Exemplo n.º 1
0
        public void Put(PutRequest request, out PutResponse response)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.ModifyRequest == null)
            {
                throw new ArgumentNullException("ModifyRequest");
            }
            if (request.ResourceReferenceProperty == null)
            {
                throw new ArgumentNullException("ResourceReferenceProperty");
            }

            Message putRequest = null;

            lock (request)
            {
                putRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.PutAction, request.ModifyRequest, new ClientSerializer(typeof(ModifyRequest)));
                ClientHelper.AddImdaHeaders(request as ImdaRequest, putRequest);
                ClientHelper.AddRmHeaders(request as WsTransfer.TransferRequest, putRequest);
            }
            Message putResponse = Put(putRequest);

            response = new PutResponse(putResponse);
            if (putResponse.IsFault)
            {
                ClientHelper.HandleFault(putResponse);
            }

            // the response has no information if it isn't a fault
            // PutResponse putResponseTyped = putResponse.GetBody<PutResponse>(new ClientSerializer(typeof(PutResponse)));
        }
Exemplo n.º 2
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."
                }
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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();
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void Put(PutRequest request, out PutResponse response, SecurityToken token)
 {
     Put(request, out response, token, null);
 }
Exemplo n.º 6
0
 public void Put(PutRequest request, out PutResponse response)
 {
     Put(request, out response, null);
 }