Esempio n. 1
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 static void UpdateUser(string manager, PersonModel _fp)
        {
            using (DefaultClient _client = new DefaultClient())
            {
                _client.ClientCredential = CredentialCache.DefaultNetworkCredentials;
                _client.RefreshSchema();
                List <RmResource> _res = _client.Enumerate("/Person[ObjectID='" + _fp.ObjectID + "']").ToList();
                foreach (RmPerson _r in _res)
                {
                    RmResourceChanges changes = new RmResourceChanges(_r);
                    try
                    {
                        changes.BeginChanges();
                        if (string.IsNullOrWhiteSpace(manager))
                        {
                            RmAttributeName _attr = new RmAttributeName("Manager");
                            _r.Attributes.Remove(_attr);
                        }
                        else
                        {
                            _r.Manager = new RmReference(manager);
                        }

                        _client.Put(changes);
                        changes.AcceptChanges();
                    }
                    catch
                    {
                        changes.DiscardChanges();
                    }
                }
            }
        }
        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);
        }
            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);
                }
            }
Esempio n. 5
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();
                }
            }
        }
Esempio n. 6
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);
        }
        public void does_not_throw_when_no_changes_to_send()
        {
            var person = _client.EnumerateAll <RmResource>("/Person")
                         .First();

            var changes = new RmResourceChanges(person);

            changes.BeginChanges();

            _client.Update(changes);
        }
Esempio n. 8
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
        }
Esempio n. 9
0
 public void AddAlias01()
 {
     #if _
     RmPerson person = new RmPerson();
     person.MailAliases.Add("one");
     person.MailAliases.Add("two");
     RmResourceChanges changes = new RmResourceChanges(person);
     changes.BeginChanges();
     person.MailAliases.Add("three");
     var changesList = changes.GetChanges();
     Assert.AreEqual(1, changesList.Count);
     Assert.AreEqual(RmAttributeChangeOperation.Add, changesList[0].Operation);
     Assert.AreEqual("three", changesList[0].Value);
     #endif
 }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
            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);
            }
Esempio n. 14
0
            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);
            }
Esempio n. 15
0
            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);
            }
Esempio n. 16
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);
        }
Esempio n. 17
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();
                    }
                }
            }
        }