예제 #1
0
        protected IDictionary <string, object> GetOrCreateSchema(User user, out bool created)
        {
            IDictionary <string, object> schema;

            if (user.CustomSchemas == null)
            {
                schema             = new Dictionary <string, object>();
                user.CustomSchemas = new Dictionary <string, IDictionary <string, object> >();
                user.CustomSchemas.Add(this.SchemaName, schema);
                created = true;
            }
            else if (!user.CustomSchemas.ContainsKey(this.SchemaName))
            {
                schema = new Dictionary <string, object>();
                user.CustomSchemas.Add(this.SchemaName, schema);
                created = true;
            }
            else
            {
                schema  = user.CustomSchemas[this.SchemaName];
                created = false;
            }

            return(schema);
        }
예제 #2
0
        public override bool UpdateField(CSEntryChange csentry, object obj)
        {
            if (this.IsReadOnly)
            {
                return(false);
            }

            if (!csentry.HasAttributeChange(this.MmsAttributeName))
            {
                return(false);
            }

            AttributeModificationType modType = csentry.AttributeChanges[this.MmsAttributeName].ModificationType;
            object value = csentry.GetValueAdd <object>(this.MmsAttributeName);

            User user = obj as User;

            if (user == null)
            {
                throw new NotSupportedException("The provided object was not of a 'user' type");
            }

            if (value == null && !this.HasSchemaField(user))
            {
                return(false);
            }

            IDictionary <string, object> schema = this.GetOrCreateSchema(user, out bool created);

            if (modType == AttributeModificationType.Delete)
            {
                if (this.HasSchemaField(user))
                {
                    schema[this.FieldName] = Utilities.GetNullRepresentation(this.NullValueRepresentation);
                    Logger.WriteLine($"Deleting {this.MmsAttributeName}");
                    return(true);
                }

                return(false);
            }

            if (value == null)
            {
                value = Utilities.GetNullRepresentation(this.NullValueRepresentation);
            }
            else
            {
                value = this.ConvertToNativeGoogleFormat(value);
            }

            schema[this.FieldName] = value;
            Logger.WriteLine($"Set {this.MmsAttributeName} -> {value ?? "<null>"}");

            return(true);
        }
        public void AddGroupWithMembers()
        {
            Group member1 = null;
            Group member2 = null;
            User  member3 = null;

            try
            {
                string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Add;
                cs.DN         = dn;
                cs.ObjectType = SchemaConstants.Group;
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", Guid.NewGuid().ToString()));

                member1 = UnitTestControl.CreateGroup();
                member2 = UnitTestControl.CreateGroup();
                member3 = UserTests.CreateUser();

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("member", new List <object>()
                {
                    member1.Email, member2.Email
                }));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("owner", new List <object>()
                {
                    member3.PrimaryEmail
                }));

                CSEntryChangeResult result = null;

                result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                Thread.Sleep(5000);

                CollectionAssert.AreEquivalent(new string[] { member1.Email, member2.Email }, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Members.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(member1, member2, member3);
            }
        }
예제 #4
0
        public override IEnumerable <AttributeChange> CreateAttributeChanges(string dn, ObjectModificationType modType, object obj)
        {
            User user = obj as User;

            if (user == null)
            {
                throw new InvalidOperationException();
            }

            if (!this.HasSchemaField(user))
            {
                yield break;
            }

            IDictionary <string, object> schema = this.GetOrCreateSchema(user, out bool created);

            object value = null;

            if (schema.ContainsKey(this.FieldName))
            {
                value = schema[this.FieldName];
            }

            if (value == null)
            {
                if (modType == ObjectModificationType.Update)
                {
                    yield return(AttributeChange.CreateAttributeDelete(this.MmsAttributeName));
                }

                yield break;
            }

            IList <object> values = this.GetValuesFromArray(value, "value");

            values = this.ConvertToNativeFimFormat(values);

            if (modType == ObjectModificationType.Add || modType == ObjectModificationType.Replace)
            {
                yield return(AttributeChange.CreateAttributeAdd(this.MmsAttributeName, values));
            }
            else if (modType == ObjectModificationType.Update)
            {
                yield return(AttributeChange.CreateAttributeReplace(this.MmsAttributeName, values));
            }
        }
예제 #5
0
        public override bool UpdateField(CSEntryChange csentry, object obj)
        {
            if (this.IsReadOnly)
            {
                return(false);
            }

            if (!csentry.HasAttributeChange(this.MmsAttributeName))
            {
                return(false);
            }

            AttributeModificationType modType      = csentry.AttributeChanges[this.MmsAttributeName].ModificationType;
            IList <object>            valueAdds    = csentry.GetValueAdds <object>(this.MmsAttributeName);
            IList <object>            valueDeletes = csentry.GetValueDeletes <object>(this.MmsAttributeName);

            valueAdds    = this.ConvertToNativeGoogleFormat(valueAdds);
            valueDeletes = this.ConvertToNativeGoogleFormat(valueDeletes);

            User user = obj as User;

            if (user == null)
            {
                throw new NotSupportedException("The provided object was not of a 'user' type");
            }

            if (valueAdds.Count == 0 && !this.HasSchemaField(user))
            {
                return(false);
            }

            IDictionary <string, object> schema = this.GetOrCreateSchema(user, out bool created);

            if (modType == AttributeModificationType.Delete)
            {
                if (this.HasSchemaField(user))
                {
                    schema[this.FieldName] = Utilities.GetNullRepresentation(this.NullValueRepresentation);
                    Logger.WriteLine($"Deleting {this.MmsAttributeName}");
                    return(true);
                }

                return(false);
            }

            IList <object> list = null;

            if (!this.HasSchemaField(user) || modType == AttributeModificationType.Replace || modType == AttributeModificationType.Add)
            {
                list = new List <object>();
            }
            else
            {
                list = this.GetValuesFromArray(schema[this.FieldName], "value");
                list = this.ConvertToNativeGoogleFormat(list);
            }

            if (modType == AttributeModificationType.Update)
            {
                foreach (object value in valueDeletes)
                {
                    list.Remove(value);
                    Logger.WriteLine($"Removing value {this.MmsAttributeName} -> {value}");
                }
            }

            foreach (object value in valueAdds)
            {
                list.Add(value);
                Logger.WriteLine($"Adding value {this.MmsAttributeName} -> {value}");
            }

            if (list.Count > 0)
            {
                List <Dictionary <string, object> > items = new List <Dictionary <string, object> >();

                foreach (object value in list)
                {
                    Dictionary <string, object> item = new Dictionary <string, object>();
                    item.Add("value", value);
                    items.Add(item);
                }

                schema[this.FieldName] = items;
            }
            else
            {
                object value = null;

                value = Utilities.GetNullRepresentation(this.NullValueRepresentation);
                Logger.WriteLine($"Set {this.MmsAttributeName} -> {value ?? "<null>"}");

                schema[this.FieldName] = value;
            }

            return(true);
        }
예제 #6
0
 protected bool HasSchema(User user)
 {
     return(user.CustomSchemas != null && user.CustomSchemas.ContainsKey(this.SchemaName));
 }
        public void TriggerBackOff()
        {
            return;

            List <Group> groups = new List <Group>();

            try
            {
                List <CSEntryChange> changes = new List <CSEntryChange>();

                for (int i = 0; i < 50; i++)
                {
                    Group e = UnitTestControl.CreateGroup();
                    groups.Add(e);
                    CSEntryChange cs = GroupMemberTests.CreateCSEntryUpdate(e);

                    List <object> addresses = new List <object>();

                    for (int j = 0; j < 100; j++)
                    {
                        string address = $"user-{Guid.NewGuid()}@lithnet.io";
                        addresses.Add(address);
                    }

                    cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("externalMember", addresses));
                    changes.Add(cs);
                }

                int directoryServicePoolSize = 30;
                int threadCount = 0;

                Task q = new Task(() =>
                {
                    Parallel.For(0, 1000, u =>
                    {
                        User x = UserTests.CreateUser();
                        Trace.WriteLine($"Created user {x.PrimaryEmail}");
                        UnitTestControl.TestParameters.UsersService.Delete(x.Id);
                    });
                });

                q.Start();

                ParallelOptions op = new ParallelOptions();
                op.MaxDegreeOfParallelism = directoryServicePoolSize;

                Parallel.ForEach(changes, op, t =>
                {
                    int threadID = Interlocked.Increment(ref threadCount);

                    Trace.WriteLine($"Thread count {threadID}");

                    try
                    {
                        CSEntryChangeResult result =
                            ExportProcessor.PutCSEntryChange(t, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                        if (result.ErrorCode != MAExportError.Success)
                        {
                            Assert.Fail(result.ErrorName);
                        }
                    }
                    finally
                    {
                        Interlocked.Decrement(ref threadCount);
                    }
                });
            }
            finally
            {
                UnitTestControl.Cleanup(groups.ToArray <object>());
            }
        }