Example #1
0
 public EventLogItem(GrouperDocument document, string message, LogLevels logLevel)
 {
     LogTime          = DateTime.Now;
     DocumentId       = document.Id;
     GroupId          = document.GroupId;
     GroupDisplayName = document.GroupName;
     GroupStore       = document.Store;
     Message          = message;
     LogLevel         = logLevel;
 }
Example #2
0
        public static GrouperDocument FromJson(string json)
        {
            List <ValidationError> validationErrors = new List <ValidationError>();
            GrouperDocument        document         = FromJson(json, validationErrors);

            if (document == null)
            {
                throw new InvalidGrouperDocumentException();
            }
            return(document);
        }
Example #3
0
 public OperationalLogItem(GrouperDocument document, GroupMemberOperations operation, GroupMember member)
 {
     LogTime           = DateTime.Now;
     DocumentId        = document.Id;
     GroupId           = document.GroupId;
     GroupDisplayName  = document.GroupName;
     GroupStore        = document.Store;
     Operation         = operation;
     TargetId          = member.Id;
     TargetDisplayName = member.DisplayName;
 }
Example #4
0
 public void Validate(GrouperDocument document, GrouperDocumentMember documentMember, List <ValidationError> validationErrors)
 {
     foreach (GrouperDocumentRule rule in documentMember.Rules)
     {
         if (rule.Name.IEquals("Upn"))
         {
             if (!IsUpnValid(rule.Value))
             {
                 validationErrors.Add(new ValidationError(nameof(rule.Value), ResourceString.ValidationErrorInvalidUpn, rule.Value));
             }
         }
     }
 }
Example #5
0
 public void Validate(GrouperDocument document, GrouperDocumentMember documentMember, List <ValidationError> validationErrors)
 {
     foreach (GrouperDocumentRule rule in documentMember.Rules)
     {
         if (rule.Name.IEquals("Group"))
         {
             if (rule.Value.IEquals(document.GroupId.ToString()))
             {
                 validationErrors.Add(new ValidationError(nameof(rule.Value), ResourceString.ValidationErrorSourceGroupSameAsTarget));
             }
         }
     }
 }
Example #6
0
 private GrouperDocument(GrouperDocument document, string groupName)
 {
     if (string.IsNullOrEmpty(groupName))
     {
         throw new ArgumentException("Parameter cannot be null or empty", nameof(groupName));
     }
     GroupName = groupName;
     // Copy all other properties
     Id       = document.Id;
     GroupId  = document.GroupId;
     Store    = document.Store;
     Owner    = document.Owner;
     _members = document.Members.Select(m => new GrouperDocumentMember(m)).ToList();
 }
Example #7
0
        public static GrouperDocument FromJson(string json, List <ValidationError> validationErrors)
        {
            if (validationErrors == null)
            {
                throw new ArgumentNullException(nameof(validationErrors));
            }
            GrouperDocument document = DocumentValidator.DeserializeAndValidate(json, validationErrors);

            if (validationErrors.Count > 0)
            {
                return(null);
            }
            return(document);
        }
Example #8
0
 public GroupMemberDiff(GrouperDocument document, GroupMemberCollection addMemberCollection,
                        GroupMemberCollection removeMemberCollection, GroupMemberCollection unchangedMemberCollection,
                        double changeRatio)
 {
     Document    = document ?? throw new ArgumentNullException(nameof(document));
     Add         = addMemberCollection?.AsEnumerable() ?? throw new ArgumentNullException(nameof(addMemberCollection));
     Remove      = removeMemberCollection?.AsEnumerable() ?? throw new ArgumentNullException(nameof(removeMemberCollection));
     Unchanged   = unchangedMemberCollection?.AsEnumerable() ?? throw new ArgumentNullException(nameof(unchangedMemberCollection));
     ChangeRatio = changeRatio;
     if (addMemberCollection == removeMemberCollection || addMemberCollection == unchangedMemberCollection || removeMemberCollection == unchangedMemberCollection)
     {
         throw new ArgumentException("All collections must be separate objects");
     }
 }
Example #9
0
 private GrouperDocument(GrouperDocument document, string groupName)
 {
     if (string.IsNullOrEmpty(groupName))
     {
         throw new ArgumentException("Parameter cannot be null or an empty string", nameof(groupName));
     }
     GroupName = groupName;
     // Copy all other properties
     Id      = document.Id;
     GroupId = document.GroupId;
     Store   = document.Store;
     Owner   = document.Owner;
     // Is it necessary to make a copy? GrouperDocumentMember should be immutable
     _members = document.Members.Select(m => new GrouperDocumentMember(m)).ToList();
 }
Example #10
0
 private static void InternalValidateDocument(GrouperDocument document, List <ValidationError> validationErrors)
 {
     if (document.Id == Guid.Empty)
     {
         validationErrors.Add(new ValidationError(nameof(document.Id), ResourceString.ValidationErrorDocumentIdNotValid, document.Id));
     }
     if (document.ProcessingInterval < 0)
     {
         validationErrors.Add(new ValidationError(nameof(document.ProcessingInterval), ResourceString.ValidationErrorIllegalInterval));
     }
     if (string.IsNullOrEmpty(document.GroupName))
     {
         validationErrors.Add(new ValidationError(nameof(document.GroupName), ResourceString.ValidationErrorGroupNameIsNullOrEmpty));
     }
     if (document.Id == Guid.Empty)
     {
         validationErrors.Add(new ValidationError(nameof(document.GroupId), ResourceString.ValidationErrorGroupIdNotValid, document.GroupId));
     }
     if (!storeLocations.TryGetValue(document.Store, out ResourceLocation groupLocation))
     {
         validationErrors.Add(new ValidationError(nameof(document.Store), ResourceString.ValidationErrorStoreNotRecognized, document.Store.ToString()));
         return;
     }
     InternalValidateMembers(document.Members, document.Store, groupLocation, validationErrors);
     if (validationErrors.Count > 0)
     {
         return;
     }
     foreach (GrouperDocumentMember documentMember in document.Members)
     {
         if (memberSources.TryGetValue(documentMember.Source, out DocumentMemberValidationRules memberSourceInfo))
         {
             if (memberSourceInfo.CustomValidators != null)
             {
                 foreach (ICustomValidator validator in memberSourceInfo.CustomValidators)
                 {
                     validator.Validate(document, documentMember, validationErrors);
                 }
             }
         }
     }
 }
Example #11
0
 public GroupMemberDiff(GrouperDocument document, GroupMemberCollection addMemberCollection,
                        GroupMemberCollection removeMemberCollection, GroupMemberCollection unchangedMemberCollection,
                        double changeRatio)
 {
     if (addMemberCollection is null)
     {
         throw new ArgumentNullException(nameof(addMemberCollection));
     }
     if (removeMemberCollection is null)
     {
         throw new ArgumentNullException(nameof(removeMemberCollection));
     }
     if (unchangedMemberCollection is null)
     {
         throw new ArgumentNullException(nameof(unchangedMemberCollection));
     }
     Document    = document ?? throw new ArgumentNullException(nameof(document));
     Add         = addMemberCollection.AsEnumerable();
     Remove      = removeMemberCollection.AsEnumerable();
     Unchanged   = unchangedMemberCollection.AsEnumerable();
     ChangeRatio = changeRatio;
 }
Example #12
0
        internal static GrouperDocument DeserializeAndValidate(string json, List <ValidationError> validationErrors)
        {
            GrouperDocument document = null;

            try
            {
                document = JsonConvert.DeserializeObject <GrouperDocument>(json);
            }
            catch (JsonReaderException ex)
            {
                validationErrors.Add(new ValidationError(nameof(json), ResourceString.ValidationJsonParsingError, ex.LineNumber, ex.LinePosition, ex.Message));
            }
            catch (JsonSerializationException ex)
            {
                validationErrors.Add(new ValidationError(nameof(json), ResourceString.ValidationJsonParsingError, 0, 0, ex.Message));
            }
            if (validationErrors.Count > 0)
            {
                return(null);
            }
            InternalValidateDocument(document, validationErrors);
            return(document);
        }
 public GroupMemberOperation(GrouperDocument document, GroupMember member, GroupMemberOperations operation)
     : this(document.GroupId, document.GroupName, member, operation)
 {
 }