Example #1
0
        public void CreatePerson()
        {
            RmPerson person = new RmPerson()
            {
                FirstName    = "John",
                LastName     = "Doe",
                DisplayName  = "John Doe",
                Domain       = "QF",
                AccountName  = "jdoe",
                MailNickname = "john.doe",
            };

            RmReference reference = CreateResource(person);
            RmPerson    queried   = GetResource(reference) as RmPerson;

            DeleteResource(reference);

            Assert.IsNotNull(queried);
            Assert.AreEqual(person.FirstName, queried.FirstName);
            Assert.AreEqual(person.LastName, queried.LastName);
            Assert.AreEqual(person.DisplayName, queried.DisplayName);
            Assert.AreEqual(person.Domain, queried.Domain);
            Assert.AreEqual(person.AccountName, queried.AccountName);
            Assert.AreEqual(person.MailNickname, queried.MailNickname);

            Assert.IsFalse(person["Manager"].IsMultiValue);
            Assert.IsFalse(queried["Manager"].IsMultiValue);
        }
Example #2
0
        public List <string> GetPermissionGroupBackLink(RmGroup group)
        {
            List <string> retVal = new List <string>();

            foreach (RmRole role in Base_GetResourceByAttribute(RmRole.StaticResourceType(), RmRole.AttributeNames.PremissionRefs.Name, group.ObjectID.Value,
                                                                OperationType.Opration_Is, new string[] { RmResource.AttributeNames.ObjectID.Name }))
            {
                if (role != null)
                {
                    foreach (RmPerson person in Base_GetResourceByAttribute(RmPerson.StaticResourceType(), RmPerson.AttributeNames.RoleRefList.Name,
                                                                            role.ObjectID.Value, OperationType.Opration_Is, new string[] { RmResource.AttributeNames.ObjectID.Name }))
                    {
                        if (person != null)
                        {
                            if (!retVal.Contains(person.ObjectID.Value))
                            {
                                retVal.Add(person.ObjectID.Value);
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
            public void modifying_single_value_generates_Replace_operation()
            {
                RmPerson person = new RmPerson
                {
                    DisplayName = "original-name"
                };

                var resourceChanges = new RmResourceChanges(person);

                resourceChanges.BeginChanges();

                person.DisplayName = "new-name";
                person.LastName    = "last name";

                var changes = resourceChanges.GetChanges();

                Assert.Equal(2, changes.Count);
                Assert.NotEmpty(changes.Where(x =>
                                              x.Name.Name == RmPerson.AttributeNames.LastName.Name &&
                                              x.Value.ToString() == "last name")
                                );
                Assert.NotEmpty(changes.Where(x =>
                                              x.Name.Name == RmResource.AttributeNames.DisplayName.Name &&
                                              x.Value.ToString() == "new-name")
                                );
                foreach (var change in changes)
                {
                    Assert.Equal(RmAttributeChangeOperation.Replace, change.Operation);
                }
            }
Example #4
0
        public void RemovePersonFromGroup(RmPerson person, RmGroup group)
        {
            if (!Client.SchemaCached)
            {
                Client.RefreshSchema();
            }

            if (person.ObjectID == null)
            {
                ClientControl.ErrorControl.AddError(new ErrorData(@"Cannot find person object ID"));
                return;
            }

            if (group.ExplicitMember == null)
            {
                ClientControl.ErrorControl.AddError(new ErrorData(@"Cannot load ExplicitMember property of the group"));
                return;
            }

            using (RmResourceChanges transaction = new RmResourceChanges(group))
            {
                if (group.ExplicitMember.Contains(person.ObjectID))
                {
                    transaction.BeginChanges();

                    group.ExplicitMember.Remove(person.ObjectID);
                    Client.Put(transaction);

                    transaction.AcceptChanges();
                }
            }
        }
        public void can_clear_reference_on_update()
        {
            var person = _client.EnumerateAll <RmPerson>("/Person").First();

            var newPerson = new RmPerson()
            {
                DisplayName = "___",
            };

            _client.Create(newPerson);

            var changes = new RmResourceChanges(newPerson);

            changes.BeginChanges();
            newPerson.Manager = person.ObjectID;

            _client.Update(changes);

            changes = new RmResourceChanges(newPerson);
            changes.BeginChanges();
            newPerson.Manager = null;

            Assert.DoesNotThrow(() =>
            {
                _client.Update(changes);
            });

            _client.Delete(newPerson);
        }
Example #6
0
        public bool HasSharePointGroup(RmPerson person, IList <RmReference> exclusiveGroupId)
        {
            foreach (RmGroup group in Base_GetResourceByAttribute(RmGroup.StaticResourceType(), RmGroup.AttributeNames.ExplicitMember.Name, person.ObjectID.Value,
                                                                  OperationType.Opration_Is, new string[] { RmResource.AttributeNames.ObjectID.Name, RmGroup.AttributeNames.FromSharePoint.Name }))
            {
                if (!group.FromSharePoint)
                {
                    continue;
                }

                if (exclusiveGroupId != null)
                {
                    bool containId = false;
                    foreach (RmReference reference in exclusiveGroupId)
                    {
                        if (reference.Value == group.ObjectID.Value)
                        {
                            containId = true;
                        }
                    }
                    if (!containId)
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            return(false);
        }
Example #7
0
        public void ResetPassword(String domainAndUserName)
        {
            // Create Anonymouse RmPerson and set ObjectID to Domain\User
            // The ObjectID attribute will become ResourceReferenceProperty in the message header
            RmPerson    user = new RmPerson();
            RmReference domainAndUsernameReference = new RmReference();

            domainAndUsernameReference.DomainAndUserNameValue = domainAndUserName;
            user.ObjectID = domainAndUsernameReference;
            PutResponse putResponse;

            putResponse = new PutResponse();
            string STSEndpoint = String.Empty;

            // Set ResetPassword to true
            // Need a transaction to watch changes to the user
            using (RmResourceChanges transaction = new RmResourceChanges(user)) {
                transaction.BeginChanges();
                user.ResetPassword = "******";
                try {
                    // We commit the change to the server
                    Put(transaction, true, out putResponse, null, null);
                } catch (FaultException <AnonymousInteractionRequiredFault> exc) {
                    // Now we must set the new password in the endpoint contained
                    // in the exception
                    string endpoint = exc.Detail.AnonymousInteractionEndpointAddress;
#warning "MUST ADD A CREATE MESSAGE WITH THE NEW PASSWORD."
                }
            }
        }
        public void delete_does_not_throw_for_nonexisting_objects()
        {
            var person = new RmPerson();

            person.ObjectID = new RmReference("3F7D3306-26FD-4DDB-9DCC-09289A3CE45D");

            Assert.DoesNotThrow(() => _client.Delete(person));
        }
Example #9
0
        public void ModifyPerson()
        {
            RmPerson manager1 = new RmPerson()
            {
                FirstName    = "John",
                LastName     = "Doe",
                DisplayName  = "John Doe",
                Domain       = "QF",
                AccountName  = "jdoe1",
                MailNickname = "john.doe"
            };
            RmPerson manager2 = new RmPerson()
            {
                FirstName    = "Jack",
                LastName     = "Doe",
                DisplayName  = "Jack Doe",
                Domain       = "QF",
                AccountName  = "jdoe2",
                MailNickname = "jack.doe"
            };

            RmReference refMgr1 = CreateResource(manager1);
            RmReference refMgr2 = CreateResource(manager2);

            RmPerson employee = new RmPerson()
            {
                FirstName    = "Jack",
                LastName     = "Frost",
                DisplayName  = "Jack Frost",
                Domain       = "QF",
                AccountName  = "jfrost",
                MailNickname = "jack.frost",
                Manager      = refMgr1
            };

            RmReference refEmp = CreateResource(employee);

            employee.ObjectID = refEmp;
            RmPerson getEmp1 = GetResource(refEmp) as RmPerson;

            RmResourceChanges changes = new RmResourceChanges(employee);

            changes.BeginChanges();
            employee.Manager = refMgr2;
            ModifyResource(changes);
            changes.AcceptChanges();

            RmPerson getEmp2 = GetResource(refEmp) as RmPerson;

            DeleteResource(refMgr1);
            DeleteResource(refMgr2);
            DeleteResource(refEmp);

            Assert.IsNotNull(getEmp1);
            Assert.IsNotNull(getEmp2);
            Assert.AreEqual(refMgr1, getEmp1.Manager);
            Assert.AreEqual(refMgr2, getEmp2.Manager);
        }
Example #10
0
        public RmResource GetGroupDisplayedOwner(RmGroup group, string[] attributes)
        {
            RmPerson person = Base_GetResourceById(RmPerson.StaticResourceType(), group.DisplayedOwner.Value, attributes) as RmPerson;

            if (person != null)
            {
                return(person);
            }

            return(Base_GetResourceById(RmGroup.StaticResourceType(), group.DisplayedOwner.Value, attributes));
        }
Example #11
0
        public List <string> GetConfilctRoles(RmPerson person)
        {
            List <string> retVal = new List <string>();

            if (person.RoleRefList == null)
            {
                return(retVal);
            }

            List <string> ouRoleList = new List <string>();

            foreach (RmReference role in person.RoleRefList)
            {
                ouRoleList.Add(role.Value);
            }

            foreach (RmSSoD ssod in Base_GetResourceByAttribute(RmSSoD.StaticResourceType(), RmSSoD.AttributeNames.Enabled.Name, "true", ResourceControl.OperationType.Opration_Is,
                                                                new string[] { RmResource.AttributeNames.DisplayName.Name, RmSSoD.AttributeNames.RejectionRefs.Name }))
            {
                List <string> potentialConflictList = new List <string>();
                foreach (RmReference rejectedRef in ssod.RejectionRefs)
                {
                    if (ouRoleList.Contains(rejectedRef.Value))
                    {
                        if (!potentialConflictList.Contains(rejectedRef.Value))
                        {
                            potentialConflictList.Add(rejectedRef.Value);
                        }
                    }
                }
                if (potentialConflictList.Count > 1)
                {
                    string conflict = ssod.ObjectID.Value + ":";
                    foreach (string conflictRole in potentialConflictList)
                    {
                        if (conflict == ssod.ObjectID.Value + ":")
                        {
                            conflict += conflictRole;
                        }
                        else
                        {
                            conflict = conflict + "|" + conflictRole;
                        }
                    }
                    if (!retVal.Contains(conflict))
                    {
                        retVal.Add(conflict);
                    }
                }
            }

            return(retVal);
        }
Example #12
0
        public void RemoveAlias01()
        {
#if _
            RmPerson person = new RmPerson();
            person.MailAliases.Add("one");
            person.MailAliases.Add("two");
            RmResourceChanges changes = new RmResourceChanges(person);
            changes.BeginChanges();
            person.MailAliases.Remove("two");
            var changesList = changes.GetChanges();
            Assert.AreEqual(1, changesList.Count);
            Assert.AreEqual(RmAttributeChangeOperation.Delete, changesList[0].Operation);
            Assert.AreEqual("two", changesList[0].Value);
#endif
        }
        public void creates_new_person()
        {
            var person = new RmPerson();

            person.FirstName   = "new person first name";
            person.DisplayName = "_new person display name";

            _client.Create(person);
            var newId = person.ObjectID;

            var newPerson = _client.FindById(newId.Value);

            Assert.NotNull(newPerson);
            Assert.NotNull(person.ObjectID);

            _client.Delete(person);
        }
        public void deletes_person()
        {
            var person = new RmPerson();

            _client.Create(person);

            var newPerson = _client.FindById(person.ObjectID.Value);

            Assert.NotNull(newPerson);

            var deleted = _client.Delete(person);

            newPerson = _client.FindById(person.ObjectID.Value);
            Assert.Null(newPerson);

            Assert.True(deleted);
        }
Example #15
0
        public void ManagerChange01()
        {
            RmReference manager1 = new RmReference("{54C0FFDB-548A-45df-A7A4-7386EE8120A7}");
            RmReference manager2 = new RmReference("{C4360DE1-C589-4444-B960-92930878A7AC}");
            RmPerson    person   = new RmPerson()
            {
                Manager = manager1
            };
            RmResourceChanges changes = new RmResourceChanges(person);

            changes.BeginChanges();
            person.Manager = manager2;
            var changesList = changes.GetChanges();

            Assert.AreEqual(1, changesList.Count);
            Assert.AreEqual(RmAttributeChangeOperation.Replace, changesList[0].Operation);
            Assert.AreEqual(manager2, changesList[0].Value);
        }
Example #16
0
        public void FirstNameChange01()
        {
            string   before = "Before";
            string   after  = "After";
            RmPerson person = new RmPerson()
            {
                FirstName = before
            };
            RmResourceChanges changes = new RmResourceChanges(person);

            changes.BeginChanges();
            person.FirstName = after;
            var changesList = changes.GetChanges();

            Assert.AreEqual(1, changesList.Count);
            Assert.AreEqual(RmAttributeChangeOperation.Replace, changesList[0].Operation);
            Assert.AreEqual(after, changesList[0].Value);
        }
Example #17
0
        public List <string> GetAssignedRoles(RmPerson person)
        {
            List <string> retVal = new List <string>();

            foreach (RmUserAssignment assignment in Base_GetResourceByAttribute(RmUserAssignment.StaticResourceType(), RmUserAssignment.AttributeNames.AssignedUser.Name,
                                                                                person.ObjectID.Value, OperationType.Opration_Is, new string[] { RmUserAssignment.AttributeNames.AssignedRole.Name }))
            {
                if (assignment != null)
                {
                    if (!retVal.Contains(assignment.AssignedRole.Value))
                    {
                        retVal.Add(assignment.AssignedRole.Value);
                    }
                }
            }

            return(retVal);
        }
Example #18
0
        public RmPerson GetPersonByDomainAccount(string domainAccount, string[] attributes)
        {
            string[] da = domainAccount.Split(@"\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (da.Length != 2)
            {
                return(null);
            }

            string filter = string.Format("[{0}='{1}' and {2}='{3}']", RmPerson.AttributeNames.Domain.Name, da[0], RmPerson.AttributeNames.AccountName.Name, da[1]);

            foreach (RmPerson person in Base_GetResourceByQuery(RmPerson.StaticResourceType(), filter, attributes))
            {
                return(person);
            }

            return(null);
        }
Example #19
0
        public List <RmGroup> GetAssignedGroups(RmPerson person, string[] attributes)
        {
            List <RmGroup> retVal = new List <RmGroup>();

            string query = string.Format("[{0}='{1}' or {2}='{3}']",
                                         RmGroup.AttributeNames.ExplicitMember.Name,
                                         person.ObjectID.Value,
                                         RmGroup.AttributeNames.ComputedMember.Name,
                                         person.ObjectID.Value);

            foreach (RmGroup group in Base_GetResourceByQuery(RmGroup.StaticResourceType(), query, attributes))
            {
                if (group != null)
                {
                    retVal.Add(group);
                }
            }

            return(retVal);
        }
            public void setting_single_valued_reference_generates_Replace_operation()
            {
                RmPerson person = new RmPerson();

                var resourceChanges = new RmResourceChanges(person);

                resourceChanges.BeginChanges();

                person.Manager = new RmReference("2CFAAD59-A6ED-4A96-91A2-52992361929A");

                var changes = resourceChanges.GetChanges();

                Assert.Equal(1, changes.Count);

                var change = changes.Single();

                Assert.Equal(RmAttributeChangeOperation.Replace, change.Operation);
                Assert.Equal(RmPerson.AttributeNames.Manager.Name, change.Name.Name);
                Assert.Equal(person.Manager, change.Value);
            }
Example #21
0
        public List <RmResource> GetGroupExplicitMembers(RmGroup group, string[] attributes)
        {
            List <RmResource> retVal = new List <RmResource>();

            foreach (RmReference memberRef in group.ExplicitMember)
            {
                RmPerson person = Base_GetResourceById(RmPerson.StaticResourceType(), memberRef.Value, attributes) as RmPerson;
                if (person != null)
                {
                    retVal.Add(person);
                    continue;
                }

                RmGroup gp = Base_GetResourceById(RmGroup.StaticResourceType(), memberRef.Value, attributes) as RmGroup;
                if (gp != null)
                {
                    retVal.Add(gp);
                }
            }

            return(retVal);
        }
            public void clearing_single_valued_date_generates_Delete_operation___otherwise_fim_web_service_throws()
            {
                RmPerson person = new RmPerson
                {
                    EmployeeEndDate = new DateTime(2011, 1, 1)
                };

                var resourceChanges = new RmResourceChanges(person);

                resourceChanges.BeginChanges();

                person.EmployeeEndDate = null;

                var changes = resourceChanges.GetChanges();

                Assert.Equal(1, changes.Count);

                var change = changes.Single();

                Assert.Equal(RmAttributeChangeOperation.Delete, change.Operation);
                Assert.Equal(RmPerson.AttributeNames.EmployeeEndDate.Name, change.Name.Name);
                Assert.Equal(person.EmployeeEndDate, change.Value);
            }
            public void clearing_single_valued_reference_generates_Delete_operation___otherwise_fim_web_service_throws()
            {
                RmPerson person = new RmPerson
                {
                    Manager = new RmReference("2CFAAD59-A6ED-4A96-91A2-52992361929A")
                };

                var resourceChanges = new RmResourceChanges(person);

                resourceChanges.BeginChanges();

                person.Manager = null;

                var changes = resourceChanges.GetChanges();

                Assert.Equal(1, changes.Count);

                var change = changes.Single();

                Assert.Equal(RmAttributeChangeOperation.Delete, change.Operation);
                Assert.Equal(RmPerson.AttributeNames.Manager.Name, change.Name.Name);
                Assert.Equal(person.Manager, change.Value);
            }
Example #24
0
        protected override void InitializeAuthenticationGate(IServiceProvider provider)
        {
            sentSMS = false;

            // When the activity is first loaded, we're going to try to retrieve the user info from the registration data
            if (this.AuthenticationGateActivity.RegistrationData == null ||
                string.IsNullOrEmpty(this.userCellPhone = UnicodeEncoding.Unicode.GetString(this.AuthenticationGateActivity.RegistrationData)))
            {
                //Looks like our cell phone data was not stored in registration data
                //Default to FIM store
                using (ServiceSecurityContext.Current.WindowsIdentity.Impersonate())
                {
                    using (DefaultClient client = new DefaultClient())
                    {
                        client.RefreshSchema();

                        SequentialWorkflow containingSequentialWorkflow = null;
                        SequentialWorkflow.TryGetContainingWorkflow(this.AuthenticationGateActivity, out containingSequentialWorkflow);

                        Guid targetUser;
                        if (containingSequentialWorkflow.ActorId == CellOTPGate.AnonymousID)
                        {
                            targetUser = containingSequentialWorkflow.TargetId;
                        }
                        else
                        {
                            targetUser = containingSequentialWorkflow.ActorId;
                        }

                        RmPerson person = client.Get(new Microsoft.ResourceManagement.ObjectModel.RmReference(targetUser.ToString())) as RmPerson;
                        this.userCellPhone = person.MobilePhone;
                    }
                }
            }

            base.InitializeAuthenticationGate(provider);
        }
Example #25
0
        public static void OTPReset(string domain, string username, ContextualSecurityToken authNSecurityToken, ContextMessageProperty contextMessageProperty)
        {
            // Create Anonymouse RmPerson and set ObjectID to Domain\User
            // The ObjectID attribute will become ResourceReferenceProperty in the message header
            RmPerson    user = new RmPerson();
            RmReference domainAndUsernameReference = new RmReference();

            domainAndUsernameReference.DomainAndUserNameValue = domain + '\\' + username;
            user.ObjectID = domainAndUsernameReference;
            PutResponse putResponse;

            putResponse = new PutResponse();
            string STSEndpoint = String.Empty;
            bool   putSuccess  = false; //This should always stay false with these calls unless no password reset workflow or qa authn workflow is attached.

            var          alternateClient = new AlternateClient();
            var          mexClient       = new MexClient();
            XmlSchemaSet metadata        = mexClient.Get();
            var          requestFactory  = new RmRequestFactory(metadata);

            // Set ResetPassword to true
            // Need a transaction to watch changes to the user
            using (RmResourceChanges transaction = new RmResourceChanges(user))
            {
                transaction.BeginChanges();

                user.ResetPassword = "******";

                try
                {
                    if (transaction.RmObject.ObjectID.Value.Split('\\').Length != 2)
                    {
                        throw new ArgumentException("User Identity must be specified by netbios domain in this format: Domain name\\user name.");
                    }

                    PutRequest alternateEPrequest = requestFactory.CreatePutRequest(transaction);

                    try
                    {
                        alternateClient.Put(alternateEPrequest, out putResponse, authNSecurityToken, contextMessageProperty);
                        putSuccess = true;
                    }
                    catch (System.ServiceModel.FaultException <Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault)
                    {
                        Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault msAuthNFault =
                            new Microsoft.ResourceManagement.WebServices.WSResourceManagement.AuthenticationRequiredFault(authNFault.Detail.SecurityTokenServiceAddress,
                                                                                                                          authNFault.Detail.UserRegistered.GetValueOrDefault(),
                                                                                                                          authNFault.Detail.UserLockedOut.GetValueOrDefault());

                        ContextMessageProperty responseContext;

                        if (ContextMessageProperty.TryGet(putResponse.Message, out responseContext) == false)
                        {
                            throw new InvalidOperationException("Could not retrieve security context message property even though we received an AuthN Fault. Something is fundamentally broken. Ensure assembly versions are correct and upgrades did not change protocol.");
                        }

                        throw new AuthenticationRequiredException(authNFault.Reason.ToString(),
                                                                  msAuthNFault,
                                                                  responseContext);
                    }
                }
                finally
                {
                    if (putSuccess == true)
                    {
                        transaction.AcceptChanges();
                    }
                    else
                    {
                        transaction.DiscardChanges();
                    }
                }
            }
        }
Example #26
0
        public List <RmPerson> GetAllPerson(string[] attributes)
        {
            List <RmResource> resourceList = Base_GetAllResource(RmPerson.StaticResourceType(), attributes);

            return(resourceList.ConvertAll <RmPerson>(delegate(RmResource r) { return r as RmPerson; }));
        }
Example #27
0
 public RmPerson GetPersonByDisplayName(string displayName, string[] attributes)
 {
     return(Base_GetResourceByDisplayName(RmPerson.StaticResourceType(), displayName, attributes) as RmPerson);
 }
Example #28
0
 public RmPerson GetPersonById(string objectId, string[] attributes)
 {
     return(Base_GetResourceById(RmPerson.StaticResourceType(), objectId, attributes) as RmPerson);
 }
Example #29
0
        public List <RmPerson> GetPersonByAttribute(string attributeName, string value, OperationType operation, string[] attributes)
        {
            List <RmResource> resourceList = Base_GetResourceByAttribute(RmPerson.StaticResourceType(), attributeName, value, operation, attributes);

            return(resourceList.ConvertAll <RmPerson>(delegate(RmResource r) { return r as RmPerson; }));
        }
Example #30
0
        public List <RmPerson> GetPersonByQuery(string query, string[] attributes)
        {
            List <RmResource> resourceList = Base_GetResourceByQuery(RmPerson.StaticResourceType(), query, attributes);

            return(resourceList.ConvertAll <RmPerson>(delegate(RmResource r) { return r as RmPerson; }));
        }