示例#1
0
        public void GetSecurityToken_AllOkay_SecurityTokenReturned()
        {
            // Act
            SecurityToken actAsToken = AdfsHelper.GetSecurityToken("https://devtest-idp.vfltest.dk/adfs/services/trust/13/usernamemixed",
                                                                   "https://dev.dcf.ws.dlbr.dk/DCFServices/", "DCFIntegrationstest", "dcftest");

            // Assert
            actAsToken.Should().NotBeNull();
        }
示例#2
0
        public void GetActAsToken_AllOkay_SecurityTokenReturned()
        {
            // Arrange
            SecurityToken bootstrap = AdfsHelper.GetSecurityToken("https://devtest-idp.vfltest.dk/adfs/services/trust/13/usernamemixed",
                                                                  "https://dev.dcf.ws.dlbr.dk/DCFServices/", "DCFIntegrationstest", "dcftest");
            ClaimsIdentity identity = new ClaimsIdentity();

            identity.BootstrapContext = bootstrap;
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            Thread.CurrentPrincipal = principal;

            // Act
            SecurityToken actAsToken =
                AdfsHelper.GetActAsToken("https://devtest-idp.vfltest.dk/adfs/services/trust/13/usernamemixed",
                                         "https://dev.dcf.ws.dlbr.dk/DCFServices/", "DCFKVKService", "dcfkvk898");

            // Assert
            actAsToken.Should().NotBeNull();
        }
示例#3
0
        /// <summary>
        /// This method tries to login the provided user on the specified ADFS IDP. If successful the current principal will be attached to the Thread and it will return the security token.
        ///
        /// If login is not successful it will throw an AdfsSecurityException specifying the reason.
        ///
        /// </summary>
        /// <param name="adfs">Options indicating which IDP to use and a few other options.</param>
        /// <param name="userName">The username to login</param>
        /// <param name="password">The users password</param>
        /// <returns>The obtained security token</returns>
        ///
        /// <throws>If login is not successful it will throw AdfsSecurityException with one of the reason codes (UserNameOrPasswordIncorrect, PasswordHasExpired, AccountDisabled, AccountLockedOut, PasswordMustChange)</throws>
        public static SecurityToken Login(AdfsOptions adfs, string userName, string password)
        {
            if (string.IsNullOrEmpty(adfs.Realm))
            {
                adfs.Realm = GetAudienceUri();
            }
            Thread.CurrentPrincipal = null;
            if (!string.IsNullOrEmpty(adfs.UserValidationServiceUri))
            {
                ValidateUser(adfs.UserValidationServiceUri, userName, password);
            }

            GenericXmlSecurityToken securityToken = (GenericXmlSecurityToken)AdfsHelper.GetSecurityToken(adfs.IdpEndpoint, adfs.Realm, userName, password);

            SamlSecurityToken token    = (SamlSecurityToken)FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers.ReadToken(new XmlTextReader(new StringReader(securityToken.TokenXml.OuterXml)));
            ClaimsIdentity    identity = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers.ValidateToken(token).First();

            // Get the IClaimsPrincipal and attach it to the current thread
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(identity);

            Thread.CurrentPrincipal = claimsPrincipal;

            return(securityToken);
        }