Exemple #1
0
        public UserGroup AddUserGroup(string applicationUrl, string name, string description)
        {
            var application = this.applicationTask.GetApplicationByUrl(applicationUrl);

            if (application == null)
            {
                return(null);
            }

            var userGroup = new UserGroup
            {
                ApplicationId = application.ApplicationId,
                Description   = description,
                Name          = name
            };

            using (var operation = BeginOperation())
            {
                this.userGroupRepository.Save(userGroup);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(UserGroupAction.Created, AuditInformation.Create().WithUserGroup(userGroup));
            return(userGroup);
        }
        public CredentialValue AddLafCredentialValue(string lafApplicationUrl, string sourceApplicationUrl,
                                                     string credentialUrnName, string credentialValueValue,
                                                     string credentialValueDescription)
        {
            var newCredentialValue = this.GetCredentialValue(lafApplicationUrl, credentialUrnName, credentialValueValue,
                                                             credentialValueDescription);

            if (newCredentialValue == null)
            {
                throw new ApplicationException("An attempt was made to create a CredentialValue that already exists.");
            }

            var application = this.applicationTask.GetApplicationByUrl(sourceApplicationUrl);

            newCredentialValue.SourceApplicationId = application.ApplicationId;

            using (var operation = BeginOperation())
            {
                this.credentialRepository.Save(newCredentialValue);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create().WithCredentialValues(newCredentialValue));

            return(newCredentialValue);
        }
        public void AddCredentialValueAndAssociatedUserGroup(string applicationUrl, string credentialElementNid,
                                                             string value, string description = null)
        {
            var credentialValue = this.GetCredentialValue(applicationUrl, credentialElementNid, value, description);

            if (credentialValue == null)
            {
                return;
            }

            using (var operation = BeginOperation())
            {
                UserGroup createdUserGroup;
                this.credentialRepository.AddCredentialValueAndAssociatedUserGroup(credentialValue, out createdUserGroup);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create()
                                       .WithCredentialValues(credentialValue));

            this.auditTasks.WriteEntry(UserGroupAction.Created,
                                       AuditInformation.Create()
                                       .WithUserGroup(credentialValue.AssociatedUserGroup));

            this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                       AuditInformation.Create()
                                       .WithUserGroupCredentialValues(
                                           credentialValue.AssociatedUserGroupCredentialValue));
        }
        public void AddCredentialValueAndAssociatedUserGroupToExistingDaUserGroup(string applicationUrl,
                                                                                  string credentialUrnName,
                                                                                  string credentialValueValue,
                                                                                  string credentialValueDescription,
                                                                                  int daUserGroupId,
                                                                                  out CredentialValue
                                                                                  createdCredentialValue,
                                                                                  out UserGroup createdUserGroup)
        {
            createdCredentialValue = this.GetCredentialValue(applicationUrl, credentialUrnName, credentialValueValue,
                                                             credentialValueDescription);
            if (createdCredentialValue == null)
            {
                throw new ApplicationException("An attempt was made to create a CredentialValue that already exists.");
            }

            CredentialValue createdLafUserGroupCredentialValueForExistingDaUserGroup;

            using (var operation = BeginOperation())
            {
                this.credentialRepository.AddCredentialValueAndAssociatedUserGroupToExistingDaUserGroup(
                    createdCredentialValue,
                    applicationUrl,
                    daUserGroupId,
                    out createdUserGroup,
                    out createdLafUserGroupCredentialValueForExistingDaUserGroup);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create().WithCredentialValues(createdCredentialValue));

            this.auditTasks.WriteEntry(UserGroupAction.Created,
                                       AuditInformation.Create()
                                       .WithUserGroup(createdCredentialValue.AssociatedUserGroup));

            this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                       AuditInformation.Create()
                                       .WithUserGroupCredentialValues(
                                           createdCredentialValue.AssociatedUserGroupCredentialValue));

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create()
                                       .WithCredentialValues(
                                           createdLafUserGroupCredentialValueForExistingDaUserGroup));

            var daUserGroupCredentialValues =
                this.credentialRepository.GetUserGroupCredentialValuesByUserGroupId(daUserGroupId);

            var createdUgcv =
                daUserGroupCredentialValues.FindAll(
                    x =>
                    x.CredentialValueId == createdLafUserGroupCredentialValueForExistingDaUserGroup.CredentialValueId)
                .ToArray();

            this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                       AuditInformation.Create()
                                       .WithUserGroupCredentialValues(createdUgcv));
        }
Exemple #5
0
        public void AddUserGroup(UserGroup userGroup)
        {
            using (var operation = BeginOperation())
            {
                this.userGroupRepository.Save(userGroup);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(UserGroupAction.Created, AuditInformation.Create().WithUserGroup(userGroup));
        }
        public void AddCredentialValue(CredentialValue credentialValue)
        {
            using (var operation = BeginOperation())
            {
                this.credentialRepository.Save(credentialValue);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create().WithCredentialValues(credentialValue));
        }
Exemple #7
0
        public void AddUserGroupCredentialValue(UserGroupCredentialValue userGroupCredentialValue)
        {
            using (var operation = BeginOperation())
            {
                this.userGroupRepository.Save(userGroupCredentialValue);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                       AuditInformation.Create()
                                       .WithUserGroupCredentialValues(userGroupCredentialValue));
        }
        public void WriteAudit(AuditInformation auditInformation)
        {
            Guard.ArgumentNotNull(auditInformation, "auditInformation");
            if (auditInformation.AuditMessage == null)
            {
                throw new ArgumentException("auditInformation.AuditMessage cannot be null", "auditInformation");
            }

            Logger.Current.LogVerbose("Received {0}".FormatInvariant(auditInformation));

            _auditDataAccess.WriteAudit(auditInformation);
        }
Exemple #9
0
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            try
            {
                var request = actionContext.HttpContext.Request;

                var userName = (request.IsAuthenticated)
                    ? actionContext.HttpContext.User.Identity.Name
                    : request.Params["userName"];

                if (string.IsNullOrEmpty(userName))
                {
                    userName = actionContext.ActionParameters.ContainsKey("userName")
                        ? actionContext.ActionParameters["userName"].ToString()
                        : "AnonymousUser";
                }

                var operationName = ActionName ?? actionContext.ActionDescriptor.ActionName;

                var data = string.Empty;

                if (actionContext.ActionParameters.ContainsKey("data"))
                {
                    data = actionContext.ActionParameters["data"].ToString();
                }

                var auditInformation = new AuditInformation();

                if (!string.IsNullOrEmpty(data))
                {
                    var decryptedData = EncryptionHelper.DecryptString(data);
                    auditInformation.Data = decryptedData;
                }
                else
                {
                    auditInformation.RRID         = request.Params["rrid"];
                    auditInformation.DownloadCode = request.Params["downloadCode"];
                    auditInformation.PartnerKey   = request.Params["partnerKey"];
                };

                _auditManager.WriteAudit(userName, operationName, auditInformation);
            }
            catch (Exception ex)
            {
                // Something went wrong, very unlikely case. Not appropriate to
                // throw from here.  Logging at this point is not appropriate
                // either.
                System.Diagnostics.Trace.WriteLine("Error occured while making an audit entry.");
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            try
            {
                var request = actionContext.HttpContext.Request;

                var userName = (request.IsAuthenticated)
                    ? actionContext.HttpContext.User.Identity.Name
                    : request.Params["userName"];

                if (string.IsNullOrEmpty(userName))
                {
                    userName = actionContext.ActionParameters.ContainsKey("userName") 
                        ? actionContext.ActionParameters["userName"].ToString() 
                        : "AnonymousUser";
                }

                var operationName = ActionName ?? actionContext.ActionDescriptor.ActionName;

                var data = string.Empty;

                if (actionContext.ActionParameters.ContainsKey("data"))
                {
                    data = actionContext.ActionParameters["data"].ToString();
                }

                var auditInformation = new AuditInformation();

                if (!string.IsNullOrEmpty(data))
                {
                    var decryptedData = RijndaelEncryptionHelper.DecryptString(data);
                    auditInformation.Data = decryptedData;
                }
                else
                {
                    auditInformation.Data = string.Format("RRID: {0}, DownloadCode: {1}, PartnerKey: {2}", request.Params["rrid"], request.Params["downloadCode"], request.Params["partnerKey"]);
                };

                _auditManager.WriteAudit(userName, operationName, auditInformation);
            }
            catch (Exception ex)
            {
                // Something went wrong, very unlikely case. Not appropriate to
                // throw from here.  Logging at this point is not appropriate
                // either.
                System.Diagnostics.Trace.WriteLine("Error occured while making an audit entry.");
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
        internal static AuditInformation WithUserGroup(this AuditInformation information, UserGroup userGroup)
        {
            if (userGroup == null)
            {
                return(information);
            }

            var xUserGroup = new XElement("usergroup");

            xUserGroup.SetAttributeValue("id", userGroup.UserGroupId);
            xUserGroup.SetAttributeValue("name", userGroup.Name);
            xUserGroup.SetAttributeValue("applicationid", userGroup.ApplicationId);
            information.Information.Add(xUserGroup);
            return(information);
        }
        internal static AuditInformation WithCredentialValues(this AuditInformation information,
                                                              params CredentialValue[] credentialValues)
        {
            var xCredentialValues = new XElement("credentialvalues");

            foreach (var credentialValue in credentialValues)
            {
                var xCredentialValue = new XElement("credentialvalue");
                xCredentialValue.SetAttributeValue("id", credentialValue.CredentialValueId);
                xCredentialValue.SetAttributeValue("credentialid", credentialValue.CredentialId);
                xCredentialValue.SetAttributeValue("description", credentialValue.Description);
                xCredentialValue.SetAttributeValue("value", credentialValue.Value);
                xCredentialValues.Add(xCredentialValue);
            }

            information.Information.Add(xCredentialValues);
            return(information);
        }
        public void Save(CredentialValue value)
        {
            var isNew  = value.IsNewEntity();
            var action = CredentialValueAction.Created;

            if (!isNew)
            {
                action = CredentialValueAction.Edited;
            }

            using (var operation = BeginOperation())
            {
                this.credentialRepository.Save(value);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(action, AuditInformation.Create().WithCredentialValues(value));
        }
Exemple #14
0
        public void Save(UserGroup userGroup)
        {
            var isNew  = userGroup.IsNewEntity();
            var action = UserGroupAction.Created;

            if (!isNew)
            {
                action = UserGroupAction.Edited;
            }

            using (var operation = BeginOperation())
            {
                this.userGroupRepository.Save(userGroup);
                operation.Complete();
            }

            this.auditTasks.WriteEntry(action, AuditInformation.Create().WithUserGroup(userGroup));
        }
        internal static AuditInformation WithUserGroupCredentialValues(this AuditInformation information, params UserGroupCredentialValue[] values)
        {
            var xParent = new XElement("usergroupcredentialvalues");

            foreach (var userGroupCredentialValue in values)
            {
                if (userGroupCredentialValue == null)
                {
                    continue;
                }

                var xUserGroupCredentialValue = new XElement("usergroupcredentialvalue");
                xUserGroupCredentialValue.SetAttributeValue("id", userGroupCredentialValue.UserGroupCredentialValueId);
                xUserGroupCredentialValue.SetAttributeValue("credentialvalueid", userGroupCredentialValue.CredentialValueId);
                xUserGroupCredentialValue.SetAttributeValue("usergroupid", userGroupCredentialValue.UserGroupId);
                xParent.Add(xUserGroupCredentialValue);
            }

            information.Information.Add(xParent);
            return(information);
        }
Exemple #16
0
        public UserGroup AddDevolvedAdminUserGroup(string name, string description)
        {
            UserGroup userGroup;

            using (var operation = BeginOperation())
            {
                userGroup = this.userGroupRepository.AddDevolvedAdminUserGroup(name, description);

                var userGroupCredentialValues =
                    this.userGroupRepository.GetUserGroupCredentialValuesByUserGroupId(userGroup.UserGroupId).ToArray();

                this.auditTasks.WriteEntry(UserGroupAction.Created,
                                           AuditInformation.Create().WithUserGroup(userGroup));

                this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                           AuditInformation.Create()
                                           .WithUserGroupCredentialValues(userGroupCredentialValues));

                operation.Complete();
            }

            return(userGroup);
        }
        public void AddDevolvedAdminUserGroupForGivenUserGroup(string name, string description,
                                                               int idOfUserGroupForWhichADevolvedAdminUserGroupIsToBeCreated,
                                                               out UserGroup createdDaUserGroup)
        {
            var             userGroup = this.userGroupTask.GetById(idOfUserGroupForWhichADevolvedAdminUserGroupIsToBeCreated);
            CredentialValue createdLafUserGroupCredentialValueForCreatedDaUserGroup;

            if (!this.userGroupTask.DoesUserGroupAlreadyExist(idOfUserGroupForWhichADevolvedAdminUserGroupIsToBeCreated))
            {
                throw new ApplicationException("An attempt was made to create a LAF Devolved Administrators User Group for a User Group that does not exist.");
            }

            using (var operation = BeginOperation())
            {
                this.credentialRepository.AddDevolvedAdminUserGroupForGivenUserGroup(name, description, userGroup,
                                                                                     out createdDaUserGroup,
                                                                                     out createdLafUserGroupCredentialValueForCreatedDaUserGroup);
                operation.Complete();
            }

            var daUserGroupCredentialValues =
                this.credentialRepository.GetUserGroupCredentialValuesByUserGroupId(createdDaUserGroup.UserGroupId)
                .ToArray();

            this.auditTasks.WriteEntry(UserGroupAction.Created,
                                       AuditInformation.Create().WithUserGroup(createdDaUserGroup));

            this.auditTasks.WriteEntry(CredentialValueAction.Created,
                                       AuditInformation.Create()
                                       .WithCredentialValues(
                                           createdLafUserGroupCredentialValueForCreatedDaUserGroup));

            this.auditTasks.WriteEntry(UserGroupAction.CredentialAdded,
                                       AuditInformation.Create()
                                       .WithUserGroupCredentialValues(daUserGroupCredentialValues));
        }
 public AuditInfo()
 {
     this.AuditDetails = new AuditInformation();
     this.AuditDetails.CreatedByUserId = 0;
     this.AuditDetails.CreatedDate     = DateTime.Now;
 }