Esempio n. 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;
 }
Esempio n. 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);
        }
Esempio n. 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;
 }
Esempio n. 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));
             }
         }
     }
 }
Esempio n. 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));
             }
         }
     }
 }
Esempio n. 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();
 }
Esempio n. 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);
        }
Esempio n. 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");
     }
 }
Esempio n. 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();
 }
Esempio n. 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);
                 }
             }
         }
     }
 }
Esempio n. 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;
 }
Esempio n. 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);
        }
Esempio n. 13
0
 public GroupMemberOperation(GrouperDocument document, GroupMember member, GroupMemberOperations operation)
     : this(document.GroupId, document.GroupName, member, operation)
 {
 }