internal static SamlSecurityToken CreateSamlToken(ClaimsIdentity subject, string audience)
        {
            SecurityTokenDescriptor  descriptor = TokenHelper.CreateDescriptor(subject, audience, 600);
            SamlSecurityTokenHandler handler    = TokenHelper.GetSamlHandler();

            return(handler.CreateToken(descriptor) as SamlSecurityToken);
        }
Esempio n. 2
0
        private void CreateSamlTokens(SecurityTokenDescriptor tokenDescriptor)
        {
            SamlSecurityTokenHandler samlTokenHandler = new SamlSecurityTokenHandler();
            SamlSecurityToken        token            = samlTokenHandler.CreateToken(tokenDescriptor) as SamlSecurityToken;
            MemoryStream             ms     = new MemoryStream();
            XmlDictionaryWriter      writer = XmlDictionaryWriter.CreateTextWriter(ms);

            samlTokenHandler.WriteToken(writer, token);
        }
Esempio n. 3
0
        public MeasureTokenHandlers()
        {
            IdentityModelEventSource.ShowPII = true;
            var securityTokenDescriptor = new SecurityTokenDescriptor
            {
                Audience           = TestData.Audience,
                Claims             = TestData.ClaimsDictionary,
                Issuer             = TestData.Issuer,
                Subject            = TestData.Subject,
                SigningCredentials = TestData.RsaSigningCredentials_2048Sha256
            };

            _jwtToken   = _jsonWebTokenHandler.CreateToken(securityTokenDescriptor);
            _saml1Token = _saml1SecurityTokenHandler.WriteToken(_saml1SecurityTokenHandler.CreateToken(securityTokenDescriptor));
            _saml2Token = _saml2SecurityTokenHandler.WriteToken(_saml2SecurityTokenHandler.CreateToken(securityTokenDescriptor));
            _tokenValidationParameters = TestData.RsaTokenValidationParameters_2048_Public;
        }
Esempio n. 4
0
        private static SamlSecurityToken CreateSamlToken(IList <Claim> claims)
        {
            var samlTokenHandler = new SamlSecurityTokenHandler();
            var tokenDescriptor  = new SecurityTokenDescriptor
            {
                Audience           = Default.Audience,
                NotBefore          = Default.NotBefore,
                Expires            = Default.Expires,
                IssuedAt           = Default.IssueInstant,
                Issuer             = Default.Issuer,
                SigningCredentials = Default.AsymmetricSigningCredentials,
                Subject            = new ClaimsIdentity(claims)
            };

            var token = samlTokenHandler.CreateToken(tokenDescriptor) as SamlSecurityToken;

            token.SigningKey = Default.AsymmetricSigningKey;
            return(token);
        }
        public static void Run(string[] args)
        {
            IdentityModelEventSource.ShowPII = true;
            var testRuns = TestConfig.SetupTestRuns(
                new List <TestExecutor>
            {
                TokenTestExecutors.JsonWebTokenHandler_ValidateToken_InParallel,
                TokenTestExecutors.JwtSecurityTokenHandler_ValidateToken_InParallel,
                TokenTestExecutors.Saml2SecurityTokenHandler_ValidateToken_InParallel,
                TokenTestExecutors.SamlSecurityTokenHandler_ValidateToken_InParallel,
                TokenTestExecutors.JsonWebTokenHandler_CreateToken_InParallel,
                TokenTestExecutors.JwtSecurityTokenHandler_CreateToken_InParallel,
                TokenTestExecutors.Saml2SecurityTokenHandler_CreateToken_InParallel,
                TokenTestExecutors.SamlSecurityTokenHandler_CreateToken_InParallel,
            });

            var securityTokenDescriptor   = TestData.SecurityTokenDescriptor(TestData.RsaSigningCredentials_2048Sha256);
            var tokenValidationParameters = TestData.TokenValidationParameters(securityTokenDescriptor.SigningCredentials.Key);
            var jwtTokenHandler           = new JwtSecurityTokenHandler();
            var jwt = jwtTokenHandler.CreateEncodedJwt(securityTokenDescriptor);
            var samlTokenHandler  = new SamlSecurityTokenHandler();
            var samlToken         = samlTokenHandler.CreateToken(securityTokenDescriptor);
            var saml              = samlTokenHandler.WriteToken(samlToken);
            var saml2TokenHandler = new Saml2SecurityTokenHandler();
            var saml2Token        = saml2TokenHandler.CreateToken(securityTokenDescriptor);
            var saml2             = saml2TokenHandler.WriteToken(saml2Token);

            var testConfig    = TestConfig.ParseArgs(args);
            var tokenTestData = new TokenTestRunData
            {
                JwtSecurityTokenHandler = new JwtSecurityTokenHandler(),
                JsonWebTokenHandler     = new JsonWebTokenHandler(),
                JwtToken                  = jwt,
                NumIterations             = testConfig.NumIterations,
                Saml2Token                = saml2,
                SamlToken                 = saml,
                SamlSecurityTokenHandler  = samlTokenHandler,
                Saml2SecurityTokenHandler = saml2TokenHandler,
                TokenValidationParameters = tokenValidationParameters,
                SecurityTokenDescriptor   = securityTokenDescriptor
            };

            // run each test to set any static data
            foreach (var testRun in testRuns)
            {
                testRun.TestExecutor(tokenTestData);
            }

            var assemblyVersion = typeof(JwtSecurityTokenHandler).Assembly.GetName().Version.ToString();

#if DEBUG
            var prefix = "DEBUG";
#else
            var prefix = "RELEASE";
#endif
            testConfig.Version = $"{prefix}-{assemblyVersion}";
            var logName   = $"SecurityTokens-{testConfig.Version}_{DateTime.Now.ToString("yyyy.MM.dd.hh.mm.ss")}.txt";
            var directory = testConfig.LogDirectory;
            var logFile   = Path.Combine(directory, logName);
            Directory.CreateDirectory(directory);

            TestRunner.Run(testConfig, testRuns, tokenTestData);
            File.WriteAllText(logFile, testConfig.Logger.Logs);
        }