Example #1
0
        private static RmResource GetResource(RmReference reference)
        {
            GetRequest  getRequest  = requestFactory.CreateGetRequest(reference, null, null);
            GetResponse getResponse = transferClient.Get(getRequest);

            return(resourceFactory.CreateResource(getResponse));
        }
Example #2
0
        protected RmResource Get(RmReference objectId, CultureInfo culture, String[] attributes)
        {
            GetRequest  request  = this.requestFactory.CreateGetRequest(objectId, culture, attributes);
            GetResponse response = this.wsTransferClient.Get(request);

            return(this.resourceFactory.CreateResource(response));
        }
Example #3
0
        public RmResource FindById(string id, AttributesToFetch attributes = null)
        {
            Initialize();

            attributes = attributes ?? AttributesToFetch.All;

            var ctx = LogContext.WithConfigFormat();

            _log.Debug(ctx.Format("Finding object by id {0} with attributes {1}"), id, attributes.GetNames().ToJSON());

            RmResource resource = null;

            try
            {
                var reference = new RmReference(id);

                if (attributes != AttributesToFetch.All)
                {
                    attributes = attributes.AppendAttribute(RmResource.AttributeNames.ObjectType.Name);
                }

                resource = _defaultClient.Get(reference, attributes.GetNames());

                _log.Debug(ctx.Format("Found object with id {0}, type {1}"), id, resource.ObjectType);
            }
            catch
            {
                // catching exc - meaning that object not found

                _log.Warn(ctx.Format("Object with id {0} not found"), id);
            }
            return(resource);
        }
Example #4
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."
                }
            }
        }
Example #5
0
        public RmReference Create(RmGeneric newResource)
        {
            if (newResource == null)
            {
                throw new ArgumentNullException("newResource");
            }

            Message msgRequest  = requestFactory.CreateCreateRequest(newResource);
            Message msgResponse = wsResourceFactoryClient.Create(msgRequest);

            if (msgResponse.IsFault)
            {
                ClientHelper.HandleFault(msgResponse);
            }

            ResponseCreate createResponse = responseFactory.CreateCreateResponse(msgResponse);

            try
            {
                RmReference reference = new RmReference(createResponse.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);
                if (newResource.ContainsKey(new RmAttributeName(RmResource.AttributeNames.ObjectID.Name)))
                {
                    newResource[RmResource.AttributeNames.ObjectID.Name].Value = reference;
                }
                return(reference);
            }
            catch (NullReferenceException)
            {
                return(new RmReference());
            }
            catch (FormatException)
            {
                return(new RmReference());
            }
        }
Example #6
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 #7
0
        private static RmReference CreateResource(RmResource resource)
        {
            CreateRequest  createRequest  = requestFactory.CreateCreateRequest(resource);
            CreateResponse createResponse = transferFactoryClient.Create(createRequest);
            RmReference    reference      = new RmReference(createResponse.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);

            return(reference);
        }
Example #8
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 #9
0
        public RmResource Get(RmReference objectId, CultureInfo culture, string[] attributes)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }

            return(resourceFactory.CreateResource(prepareGetResponse(objectId, culture, attributes), false) as RmResource);
        }
Example #10
0
        public bool DeleteResource(RmReference objectId)
        {
            if (!Client.SchemaCached)
            {
                Client.RefreshSchema();
            }

            return(Client.Delete(objectId));
        }
Example #11
0
        public void RecursiveDeleteOU(RmReference topOUID)
        {
            foreach (RmOrgUnit orgUnit in Base_GetResourceByAttribute(RmOrgUnit.StaticResourceType(), RmOrgUnit.AttributeNames.ParentRef.Name, topOUID.Value,
                                                                      OperationType.Opration_Is, new string[] { RmResource.AttributeNames.ObjectID.Name }))
            {
                RecursiveDeleteOU(orgUnit.ObjectID);
            }

            DeleteResource(topOUID);
        }
Example #12
0
        public virtual DeleteRequest CreateDeleteRequest(RmReference objectId)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }
            DeleteRequest deleteRequest = new DeleteRequest();

            deleteRequest.ResourceReferenceProperty = new ResourceReferenceProperty(objectId.Value);
            return(deleteRequest);
        }
Example #13
0
        public RmResource Get(RmReference objectId)
        {
            try
            {
                return(_defaultClient.Get(objectId));
            }
            catch (Exception e)
            {
                HandleError(e);

                return(null);
            }
        }
Example #14
0
        public RmResource Get(RmReference objectId, CultureInfo culture, string[] attributes)
        {
            try
            {
                return(_defaultClient.Get(objectId, culture, attributes));
            }
            catch (Exception e)
            {
                HandleError(e);

                return(null);
            }
        }
Example #15
0
        public bool Delete(RmReference objectId)
        {
            try
            {
                return(_defaultClient.Delete(objectId));
            }
            catch (Exception e)
            {
                HandleError(e);

                return(false);
            }
        }
Example #16
0
        /// <summary>
        /// Deletes the object with the given ObjectId.
        /// </summary>
        /// <param name="objectId">The ObjectId of the object to delete.</param>
        /// <returns>True upon successful deletion.</returns>
        public bool Delete(RmReference objectId)
        {
            DeleteRequest  request  = this.requestFactory.CreateDeleteRequest(objectId);
            DeleteResponse response = this.wsTransferClient.Delete(request);

            if (response == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #17
0
        public virtual GetRequest CreateGetRequest(RmReference objectId, CultureInfo culture, String[] attributes)
        {
            GetRequest request = new GetRequest();

            request.ResourceReferenceProperty = new ResourceReferenceProperty(objectId.Value);
            if (culture != null)
            {
                request.ResourceLocaleProperty = new ResourceLocaleProperty(culture);
            }
            if (attributes != null)
            {
                request.BaseObjectSearchRequest = new BaseObjectSearchRequest(attributes);
            }
            return(request);
        }
Example #18
0
        public bool Delete(RmReference objectId)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }

            Message msgRequest  = requestFactory.CreateDeleteRequest(objectId);
            Message msgResponse = wsResourceClient.Delete(msgRequest);

            if (msgResponse.IsFault)
            {
                ClientHelper.HandleFault(msgResponse);
            }

            return(true);
        }
Example #19
0
        public Message CreateGetRequest(RmReference objectId, CultureInfo culture, string[] attributes)
        {
            if (objectId == null || string.IsNullOrEmpty(objectId.Value))
            {
                throw new ArgumentNullException("objectId");
            }

            Message msgGetRequest            = null;
            bool    isAttributeSearchRequest = false;

            RequestGet requestGet = new RequestGet()
            {
                ResourceReferenceProperty = objectId.Value
            };

            if (culture != null)
            {
                requestGet.ResourceLocaleProperty = culture.Name;
            }
            if (attributes != null && attributes.Length != 0)
            {
                isAttributeSearchRequest = true;
                List <string> attributeList = new List <string>(attributes);
                if (string.IsNullOrEmpty(attributeList.Find(a => a.ToLower() == "objecttype")))
                {
                    attributeList.Add("ObjectType");
                }
                requestGet.RequestAttributeSearch = new RequestAttributeSearch(attributeList.ToArray());
            }

            if (!isAttributeSearchRequest)
            {
                msgGetRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction);
            }
            else
            {
                msgGetRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction,
                                                      requestGet.RequestAttributeSearch, new ClientSerializer(typeof(RequestAttributeSearch)));
                ClientHelper.AddImdaHeaders(requestGet, msgGetRequest);
            }

            ClientHelper.AddRmHeaders(requestGet, msgGetRequest);

            return(msgGetRequest);
        }
Example #20
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 #21
0
        /// <summary>
        /// Creates the given resource and returns its ObjectId.
        /// This method does not set the ObjectId of newResource.
        /// </summary>
        /// <param name="newResource">The resource to create.</param>
        /// <returns>The ObjectId of the resource.</returns>
        public RmReference Create(RmResource newResource)
        {
            if (newResource == null)
            {
                throw new ArgumentNullException("newResource");
            }
            CreateRequest  request  = this.requestFactory.CreateCreateRequest(newResource);
            CreateResponse response = this.wsTransferFactoryClient.Create(request);

            try {
                RmReference reference = new RmReference(response.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);
                newResource.ObjectID = reference;
                return(reference);
            } catch (NullReferenceException) {
                return(new RmReference());
            } catch (FormatException) {
                return(new RmReference());
            }
        }
Example #22
0
        private ResponseGet prepareGetResponse(RmReference objectId, CultureInfo culture, string[] attributes)
        {
            bool haveSearchAttributes = true;

            if (attributes == null || attributes.Length == 0)
            {
                haveSearchAttributes = false;
            }

            Message msgRequest  = requestFactory.CreateGetRequest(objectId, culture, attributes);
            Message msgResponse = wsResourceClient.Get(msgRequest);

            if (msgResponse.IsFault)
            {
                ClientHelper.HandleFault(msgResponse);
            }

            return(responseFactory.CreateGetResponse(msgResponse, haveSearchAttributes));
        }
Example #23
0
        public Message CreateDeleteRequest(RmReference objectId)
        {
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }

            RequestDelete deleteRequest = new RequestDelete();

            deleteRequest.ResourceReferenceProperty = objectId.Value;

            Message msgRequest = null;

            lock (deleteRequest)
            {
                msgRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.DeleteAction, deleteRequest, new ClientSerializer(typeof(RequestDelete)));
                ClientHelper.AddRmHeaders(deleteRequest, msgRequest);
            }

            return(msgRequest);
        }
Example #24
0
 public virtual GetRequest CreateGetRequest(RmReference objectId, CultureInfo culture, String[] attributes)
 {
     GetRequest request = new GetRequest();
     request.ResourceReferenceProperty = new ResourceReferenceProperty(objectId.Value);
     if (culture != null)
     {
         request.ResourceLocaleProperty = new ResourceLocaleProperty(culture);
     }
     if (attributes != null)
     {
         request.BaseObjectSearchRequest = new BaseObjectSearchRequest(attributes);
     }
     return request;
 }
Example #25
0
 /// <summary>
 /// Creates the given resource and returns its ObjectId.
 /// This method does not set the ObjectId of newResource.
 /// </summary>
 /// <param name="newResource">The resource to create.</param>
 /// <returns>The ObjectId of the resource.</returns>
 public RmReference Create(RmResource newResource)
 {
     if (newResource == null)
         throw new ArgumentNullException("newResource");
     CreateRequest request = this.requestFactory.CreateCreateRequest(newResource);
     CreateResponse response = this.wsTransferFactoryClient.Create(request);
     try {
         RmReference reference = new RmReference(response.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);
         newResource.ObjectID = reference;
         return reference;
     } catch (NullReferenceException) {
         return new RmReference();
     } catch (FormatException) {
         return new RmReference();
     }
 }
Example #26
0
 /// <summary>
 /// Deletes the object with the given ObjectId.
 /// </summary>
 /// <param name="objectId">The ObjectId of the object to delete.</param>
 /// <returns>True upon successful deletion.</returns>
 public bool Delete(RmReference objectId)
 {
     DeleteRequest request = this.requestFactory.CreateDeleteRequest(objectId);
     DeleteResponse response = this.wsTransferClient.Delete(request);
     if (response == null)
         return false;
     else
         return true;
 }
Example #27
0
 /// <summary>
 /// Retrieves the object with the given ObjectId
 /// </summary>
 /// <param name="objectId">The ObjectId of the requested object.</param>
 /// <returns>The object or null if not found</returns>
 /// <exception cref="System.ServiceModel.FaultException">System.ServiceModel.FaultException thrown when failures occur.</exception>
 public RmResource Get(RmReference objectId)
 {
     return Get(objectId, null, null);
 }
Example #28
0
 /// <summary>
 /// Retrieves the representation of an object with the given ObjectId in the given culture.
 /// </summary>
 /// <param name="objectId">The ObjectId of the requested object.</param>
 /// <param name="culture">The requested culture representation of the object.</param>
 /// <returns>The object or null if not found.</returns>
 public RmResource Get(RmReference objectId, CultureInfo culture)
 {
     return Get(objectId, culture, null);
 }
        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 #30
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."
                }
            }
        }
Example #31
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 #32
0
 public RmResource Get(RmReference objectId, String[] attributes)
 {
     return(Get(objectId, null, attributes));
 }
Example #33
0
 public RmResource Get(RmReference objectId)
 {
     return(Get(objectId, null, null));
 }
Example #34
0
 private static RmResource GetResource(RmReference reference)
 {
     GetRequest getRequest = requestFactory.CreateGetRequest(reference, null, null);
     GetResponse getResponse = transferClient.Get(getRequest);
     return resourceFactory.CreateResource(getResponse);
 }
Example #35
0
 public RmGeneric GenericGet(RmReference objectId)
 {
     return(GenericGet(objectId, null, null));
 }
Example #36
0
 /// <summary>
 /// Retrieves the object and the specified attributes with the given ObjectId.
 /// </summary>
 /// <param name="objectId">The ObjectId of the requested object.</param>
 /// <param name="attributes">The list of attributes on the object to return.</param>
 /// <returns></returns>
 public RmResource Get(RmReference objectId, String[] attributes)
 {
     return Get(objectId, null, attributes);
 }
Example #37
0
 public RmGeneric GenericGet(RmReference objectId, CultureInfo culture)
 {
     return(GenericGet(objectId, culture, null));
 }
Example #38
0
 protected RmResource Get(RmReference objectId, CultureInfo culture, String[] attributes)
 {
     GetRequest request = this.requestFactory.CreateGetRequest(objectId, culture, attributes);
     GetResponse response = this.wsTransferClient.Get(request);
     return this.resourceFactory.CreateResource(response);
 }
Example #39
0
 public RmResource Get(RmReference objectId, CultureInfo culture)
 {
     return(Get(objectId, culture, null));
 }
Example #40
0
 private static void DeleteResource(RmReference reference)
 {
     DeleteRequest deleteRequest = requestFactory.CreateDeleteRequest(reference);
     DeleteResponse deleteResponse = transferClient.Delete(deleteRequest);
 }
Example #41
0
 public virtual DeleteRequest CreateDeleteRequest(RmReference objectId)
 {
     if (objectId == null)
     {
         throw new ArgumentNullException("objectId");
     }
     DeleteRequest deleteRequest = new DeleteRequest();
     deleteRequest.ResourceReferenceProperty = new ResourceReferenceProperty(objectId.Value);
     return deleteRequest;
 }
Example #42
0
 private static RmReference CreateResource(RmResource resource)
 {
     CreateRequest createRequest = requestFactory.CreateCreateRequest(resource);
     CreateResponse createResponse = transferFactoryClient.Create(createRequest);
     RmReference reference = new RmReference(createResponse.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);
     return reference;
 }
Example #43
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 #44
0
 private static void DeleteResource(RmReference reference)
 {
     DeleteRequest  deleteRequest  = requestFactory.CreateDeleteRequest(reference);
     DeleteResponse deleteResponse = transferClient.Delete(deleteRequest);
 }