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