Esempio n. 1
0
 public void ParallelStressLoad()
 {
     var start = DateTime.Now;
     var factory = new TaskFactory();
     var tasks = new Task[20];
     for (var t = 0; t < tasks.Length; ++t)
     {
         tasks[t] = factory.StartNew(() =>
         {
             var client = new SecurityTokenServiceClient();
             var tokens = new string[20];
             for (int au = 0; au < tokens.Length; ++au)
             {
                 var token = client.Add(new[] { new KeyValuePair<string, string>("id", au.ToString()) });
                 tokens[au] = token;
                 for (int gu = 0; gu < au; ++gu)
                 {
                     var user = client.Get(tokens[gu]);
                     Assert.AreEqual(gu.ToString(), user.First(item => item.Key == "id").Value);
                 }
             }
         });
     }
     Console.WriteLine("tasks created");
     Task.WaitAll(tasks);
     var finish = DateTime.Now;
     var elapsed = finish - start;
     Console.WriteLine(elapsed);
 }
Esempio n. 2
0
 public void AddAndGet()
 {
     var client = new SecurityTokenServiceClient();
     var token = client.Add(new[] { new KeyValuePair<string, string>("id", "asdf") });
     var user = client.Get(token);
     Assert.AreEqual("asdf", user.First(item => item.Key == "id").Value);
 }
Esempio n. 3
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);
        }
 public void RemoveLogin(string token)
 {
     using (var client = new SecurityTokenServiceClient())
     {
         client.Remove(token);
         client.Close();
     }
 }
 public string Add(UserHeader user)
 {
     using (var client = new SecurityTokenServiceClient())
     {
         var token = client.Add(SerializeUser(user));
         client.Close();
         return token;
     }
 }
 public string AddLogin(UserHeader user)
 {
     using (var client = new SecurityTokenServiceClient())
     {
         var token = client.Add(
             SerializeUser(user).Concat(
                 new[] { new KeyValuePair<string, string>(IsLoginProperty, "true") }).ToArray());
         client.Close();
         return token;
     }
 }
Esempio n. 7
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;
        }
 private UserHeader GetImpl(string token, bool isLogin)
 {
     using (var client = new SecurityTokenServiceClient())
     {
         var propertyBag = client.Get(token);
         client.Close();
         if (propertyBag == null) return null;
         if (propertyBag.Any(item => item.Key == IsLoginProperty) == !isLogin) return null;
         return DeserializeUser(propertyBag);
     }
 }