Наследование: Microsoft.ResourceManagement.ObjectModel.RmResource
        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);
        }
Пример #2
0
            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);
                }
            }
Пример #3
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);
        }
        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));
        }
        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);
        }
Пример #6
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
 }
        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);
        }
Пример #8
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);
        }
Пример #9
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);
            }
Пример #10
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);
            }
Пример #11
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);
            }
Пример #12
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."
                }
            }
        }
Пример #13
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();
                    }
                }
            }
        }
Пример #14
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);
        }
Пример #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);
        }