A transaction object monitors the changes made to an RmResource object. Use this class to check for changes when updating the Resource Management Service.
Inheritance: IDisposable
        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);
                }
            }
示例#3
0
 /// <summary>
 /// Returns a list of changes made to this object since the transaction began or the last call to AcceptChanges.
 /// </summary>
 /// <returns></returns>
 public IList <RmAttributeChange> GetChanges()
 {
     EnsureNotDisposed();
     lock (rmObject.Attributes) {
         // there was no original, so we just return an empty list
         if (originalAttributes == null)
         {
             return(new List <RmAttributeChange>());
         }
         else
         {
             return(RmResourceChanges.GetDifference(rmObject.Attributes, this.originalAttributes));
         }
     }
 }
            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);
            }
            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 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);
            }
示例#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."
                }
            }
        }
示例#8
0
        public bool Put(RmResourceChanges transaction, bool useAlternateEndpoint, out PutResponse response, SecurityToken token, ContextMessageProperty context)
        {
            response = null;
            if (transaction == null) {
                throw new ArgumentNullException("transaction");
            }

            if (!useAlternateEndpoint) {
                PutRequest resourceEPrequest = this.requestFactory.CreatePutRequest(transaction);
                try {

                    this.wsTransferClient.Put(resourceEPrequest, out response);

                }
                    //catch AuthN Fault here so we have the original transaction so we can re-submit later
                catch (System.ServiceModel.FaultException<Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpoinAddresst = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;
                    //TODO: Add AuthNLogicHere. For now, only support QA gates on the Authernate Endpoint
                }

                if (response == null)
                    return false;
                else
                    return true;
            } else {
                //TODO:Verify that the ObjectID is in the form Domain\User.
                PutRequest alternateEPrequest = this.requestFactory.CreatePutRequest(transaction);
                response = null;

                try {
                    this.alternateClient.Put(alternateEPrequest, out response, token, context);
                } catch (System.ServiceModel.FaultException<Microsoft.ResourceManagement.Client.Faults.AuthenticationRequiredFault> authNFault) {
                    String STSEndpointAddress = authNFault.Detail.SecurityTokenServiceAddress;
                    ContextMessageProperty responseContext;

                    if (ContextMessageProperty.TryGet(response.Message, out responseContext)) {
                        ContextualSecurityToken userToken = HandleAuthNFault(STSEndpointAddress, responseContext);
                        Put(transaction, true, out response, userToken, responseContext);
                    } else {
                        throw new Exception("Could not get security context from Put.");
                    }
                }

                if (response == null)
                    return false;
                else
                    return true;
            }
        }
示例#9
0
 public bool Put(RmResourceChanges transaction, bool useAlternateEndpoint)
 {
     PutResponse response;
     return Put(transaction, useAlternateEndpoint, out response, null, null);
 }
示例#10
0
 /// <summary>
 /// Saves changes made to an object recorded by the transaction to the service.
 /// </summary>
 /// <param name="transaction">The transaction object which recorded changes made to a Resource object.</param>
 /// <returns>True upon successful operation.</returns>
 public bool Put(RmResourceChanges transaction)
 {
     return Put(transaction, false);
 }
示例#11
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();
                    }
                }
            }
        }
示例#12
0
 private static void ModifyResource(RmResourceChanges changes)
 {
     PutRequest putRequest = requestFactory.CreatePutRequest(changes);
     PutResponse putResponse = transferClient.Put(putRequest);
 }
示例#13
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);
        }
示例#14
0
        /// <summary>
        /// Constructs a put request based on the changes tracked in the transaction.
        /// </summary>
        /// <param name="transaction">The transaction object which tracked the changes made to an object.</param>
        /// <returns></returns>
        public virtual PutRequest CreatePutRequest(RmResourceChanges transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            RmResource rmObject = transaction.RmObject;
            if (rmObject == null)
            {
                throw new InvalidOperationException("transaction does not have rmObject");
            }
            if (rmObject.ObjectID == null) {
                throw new InvalidOperationException("The rmObject does not have an ObjectID.");
            }
            lock (rmObject)
            {

                PutRequest putRequest = new PutRequest();

                putRequest.ResourceReferenceProperty = new ResourceReferenceProperty(rmObject.ObjectID.ToString());
                if (string.IsNullOrEmpty(rmObject.Locale) == false)
                {
                    putRequest.ResourceLocaleProperty = new ResourceLocaleProperty(new System.Globalization.CultureInfo(rmObject.Locale));
                }

                putRequest.ModifyRequest = new ModifyRequest();

                IList<RmAttributeChange> changes = transaction.GetChanges();

                foreach (RmAttributeChange attributeChange in changes)
                {
                    if (this.ProhibitedAttributes.ContainsKey(attributeChange.Name.Name))
                        continue;

                    DirectoryAccessChange putReqChange = BuildDirectoryAccessChange(attributeChange);

                    if (base.IsMultiValued(attributeChange.Name))
                    {
                        putReqChange.Operation = attributeChange.Operation.ToString();
                    }
                    else
                    {
                        if (attributeChange.Operation == RmAttributeChangeOperation.Add)
                        {
                            putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString();
                        }
                        else if (attributeChange.Operation == RmAttributeChangeOperation.Delete)
                        {
                            putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString();
                            putReqChange.AttributeValue = null;
                        } else {
                            putReqChange.Operation = attributeChange.Operation.ToString();
                        }
                    }
                    putRequest.ModifyRequest.Changes.Add(putReqChange);
                }
                return putRequest;
            }
        }
        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);
        }