ReadObject() public method

ReadObject is used to read and object from the reader. Deserialize will do the work.
public ReadObject ( System reader, bool verifyObjectName ) : object
reader System
verifyObjectName bool
return object
Beispiel #1
0
        private ContextualSecurityToken HandleAuthNFault(String stsEndpointAddress, ContextMessageProperty responseContext)
        {
            ContextualSecurityToken returnToken = null;

            //create new client to talk to the STS
            SecurityTokenServiceClient stsClient = new SecurityTokenServiceClient("ServiceMultipleTokenBinding_SecurityTokenService", stsEndpointAddress);

            Guid contextGuid = new Guid(responseContext.Context["instanceId"]);

            Message          RST;  //The Request for Security Token
            Message          RSTR; //The Request for Security Token Response
            ClientSerializer RSTRSerializer = new ClientSerializer(typeof(Client.WsTrust.RequestSecurityTokenResponse));

            Client.WsTrust.RequestSecurityTokenResponse serializedRSTR;
            Dictionary <int, String> answers = new Dictionary <int, string>();

            //Initial RST, RSTR


            RST = stsClient.BuildRequestSecurityTokenMessage(contextGuid);

            RSTR = stsClient.RequestSecurityToken(RST);

            //We will continue asking for RSTR untill we get a Security Token (or get a fault)
            do
            {
                serializedRSTR = (Client.WsTrust.RequestSecurityTokenResponse)RSTRSerializer.ReadObject(RSTR.GetReaderAtBodyContents());
                if (serializedRSTR != null)
                {
                    if (serializedRSTR.Authchallenge != null)
                    {
                        if (serializedRSTR.Authchallenge.challenge.workflowAuthChallenge.Name == "QAGate")
                        {
                            answers = questionHandler.Invoke(serializedRSTR.Authchallenge.challenge.workflowAuthChallenge);
                            Client.WsTrust.RequestSecurityTokenResponse RSTRrequest = new Client.WsTrust.RequestSecurityTokenResponse();
                            RSTRrequest.Context = serializedRSTR.Context;
                            RSTRrequest.AuthChallengeResponse = new AuthenticationChallengeResponse(answers);

                            RSTR = stsClient.BuildRequestSecurityTokenResponseMessage(RSTRrequest);
                            RSTR = stsClient.RequestSecurityTokenResponse(RSTR);
                        }
                    }
                    else if (serializedRSTR.RequestedSecurityToken != null)
                    {
                        returnToken = serializedRSTR.GetContextTokenFromResponse(responseContext);
                    }
                    else
                    {
                        throw new Exception("The STS returned a response that is neither an AuthChallenge nor a Security Response.");
                    }
                }
                else
                {
                    throw new Exception("Received a response from the STS that we do not understand.");
                }
            } while (returnToken == null);

            return(returnToken);
        }
Beispiel #2
0
        private ContextualSecurityToken HandleAuthNFault(String stsEndpointAddress, ContextMessageProperty responseContext)
        {
            ContextualSecurityToken returnToken = null;

            //create new client to talk to the STS
            SecurityTokenServiceClient stsClient = new SecurityTokenServiceClient("ServiceMultipleTokenBinding_SecurityTokenService", stsEndpointAddress);

            Guid contextGuid = new Guid(responseContext.Context["instanceId"]);

            Message RST;  //The Request for Security Token
            Message RSTR;  //The Request for Security Token Response
            ClientSerializer RSTRSerializer = new ClientSerializer(typeof(Client.WsTrust.RequestSecurityTokenResponse));
            Client.WsTrust.RequestSecurityTokenResponse serializedRSTR;
            Dictionary<int, String> answers = new Dictionary<int, string>();

            //Initial RST, RSTR

            RST = stsClient.BuildRequestSecurityTokenMessage(contextGuid);

            RSTR = stsClient.RequestSecurityToken(RST);

            //We will continue asking for RSTR untill we get a Security Token (or get a fault)
            do {
                serializedRSTR = (Client.WsTrust.RequestSecurityTokenResponse)RSTRSerializer.ReadObject(RSTR.GetReaderAtBodyContents());
                if (serializedRSTR != null) {
                    if (serializedRSTR.Authchallenge != null) {
                        if (serializedRSTR.Authchallenge.challenge.workflowAuthChallenge.Name == "QAGate") {
                            answers = questionHandler.Invoke(serializedRSTR.Authchallenge.challenge.workflowAuthChallenge);
                            Client.WsTrust.RequestSecurityTokenResponse RSTRrequest = new Client.WsTrust.RequestSecurityTokenResponse();
                            RSTRrequest.Context = serializedRSTR.Context;
                            RSTRrequest.AuthChallengeResponse = new AuthenticationChallengeResponse(answers);

                            RSTR = stsClient.BuildRequestSecurityTokenResponseMessage(RSTRrequest);
                            RSTR = stsClient.RequestSecurityTokenResponse(RSTR);
                        }
                    } else if (serializedRSTR.RequestedSecurityToken != null) {
                        returnToken = serializedRSTR.GetContextTokenFromResponse(responseContext);
                    } else {
                        throw new Exception("The STS returned a response that is neither an AuthChallenge nor a Security Response.");
                    }
                } else
                    throw new Exception("Received a response from the STS that we do not understand.");

            } while (returnToken == null);

            return returnToken;
        }