Search in sources :

Example 11 with SAMLSSOServiceProviderDTO

use of org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO in project product-is by wso2.

the class SAMLFederationWithFileBasedSPAndIDPTestCase method getSAMLSSOServiceProviderDTO.

protected SAMLSSOServiceProviderDTO getSAMLSSOServiceProviderDTO(String issuerName, String acsUrl) {
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO();
    samlssoServiceProviderDTO.setIssuer(issuerName);
    samlssoServiceProviderDTO.setAssertionConsumerUrls(new String[] { acsUrl });
    samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(acsUrl);
    samlssoServiceProviderDTO.setNameIDFormat(SAML_NAME_ID_FORMAT);
    samlssoServiceProviderDTO.setDoSignAssertions(true);
    samlssoServiceProviderDTO.setDoSignResponse(true);
    samlssoServiceProviderDTO.setDoSingleLogout(true);
    samlssoServiceProviderDTO.setEnableAttributeProfile(true);
    samlssoServiceProviderDTO.setEnableAttributesByDefault(true);
    return samlssoServiceProviderDTO;
}
Also used : SAMLSSOServiceProviderDTO(org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO)

Example 12 with SAMLSSOServiceProviderDTO

use of org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO in project product-is by wso2.

the class TestPassiveSTSFederation method getSAMLSSOServiceProviderDTO.

private SAMLSSOServiceProviderDTO getSAMLSSOServiceProviderDTO(String issuerName, String acsUrl) {
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO();
    samlssoServiceProviderDTO.setIssuer(issuerName);
    samlssoServiceProviderDTO.setAssertionConsumerUrls(new String[] { acsUrl });
    samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(acsUrl);
    samlssoServiceProviderDTO.setNameIDFormat(SAML_NAME_ID_FORMAT);
    samlssoServiceProviderDTO.setDoSignAssertions(true);
    samlssoServiceProviderDTO.setDoSignResponse(true);
    samlssoServiceProviderDTO.setDoSingleLogout(true);
    samlssoServiceProviderDTO.setEnableAttributesByDefault(true);
    return samlssoServiceProviderDTO;
}
Also used : SAMLSSOServiceProviderDTO(org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO)

Example 13 with SAMLSSOServiceProviderDTO

use of org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO in project product-is by wso2.

the class TenantDropDownTestCase method createSsoServiceProviderDTO.

private SAMLSSOServiceProviderDTO createSsoServiceProviderDTO() {
    SAMLSSOServiceProviderDTO samlssoServiceProviderDTO = new SAMLSSOServiceProviderDTO();
    samlssoServiceProviderDTO.setIssuer(SAML_ISSUER);
    samlssoServiceProviderDTO.setAssertionConsumerUrls(new String[] { String.format(ACS_URL, SAML_ISSUER) });
    samlssoServiceProviderDTO.setDefaultAssertionConsumerUrl(String.format(ACS_URL, SAML_ISSUER));
    samlssoServiceProviderDTO.setAttributeConsumingServiceIndex(ATTRIBUTE_CS_INDEX_VALUE);
    samlssoServiceProviderDTO.setNameIDFormat(NAMEID_FORMAT);
    samlssoServiceProviderDTO.setDoSignAssertions(false);
    samlssoServiceProviderDTO.setDoSignResponse(false);
    samlssoServiceProviderDTO.setDoSingleLogout(true);
    samlssoServiceProviderDTO.setLoginPageURL(LOGIN_URL);
    return samlssoServiceProviderDTO;
}
Also used : SAMLSSOServiceProviderDTO(org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO)

Example 14 with SAMLSSOServiceProviderDTO

use of org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO in project product-is by wso2.

the class SAML2SSOTestBase method getAssertionFromSAMLResponse.

/**
 * Extract SAML Assertion from the SAML Response.
 *
 * @param samlResponse SAML Response.
 * @param samlssoSPDTO SAMLSSO service Provider DTO.
 * @param x509Credential x509Credential instance.
 * @return SAML Response instance.
 * @throws Exception
 */
public Assertion getAssertionFromSAMLResponse(Response samlResponse, SAMLSSOServiceProviderDTO samlssoSPDTO, X509Credential x509Credential) throws Exception {
    Assertion assertion = null;
    if (samlssoSPDTO.getDoEnableEncryptedAssertion()) {
        List<EncryptedAssertion> encryptedAssertions = samlResponse.getEncryptedAssertions();
        EncryptedAssertion encryptedAssertion = null;
        if (!CollectionUtils.isEmpty(encryptedAssertions)) {
            encryptedAssertion = encryptedAssertions.get(0);
            try {
                assertion = getDecryptedAssertion(encryptedAssertion, x509Credential);
            } catch (Exception e) {
                if (log.isDebugEnabled()) {
                    log.debug("Assertion decryption failure : ", e);
                }
                throw new Exception("Unable to decrypt the SAML2 Assertion", e);
            }
        }
    } else {
        List<Assertion> assertions = samlResponse.getAssertions();
        if (assertions != null && !assertions.isEmpty()) {
            assertion = assertions.get(0);
        }
    }
    if (assertion == null && !isNoPassive(samlResponse)) {
        throw new Exception("SAML2 Assertion not found in the Response");
    }
    return assertion;
}
Also used : EncryptedAssertion(org.opensaml.saml2.core.EncryptedAssertion) Assertion(org.opensaml.saml2.core.Assertion) EncryptedAssertion(org.opensaml.saml2.core.EncryptedAssertion) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ValidationException(org.opensaml.xml.validation.ValidationException) IdentitySAMLSSOConfigServiceIdentityException(org.wso2.carbon.identity.sso.saml.stub.IdentitySAMLSSOConfigServiceIdentityException) RemoteException(java.rmi.RemoteException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.opensaml.xml.ConfigurationException)

Example 15 with SAMLSSOServiceProviderDTO

use of org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO in project product-is by wso2.

the class SAML2SSOTestBase method sendSAMLAuthenticationRequest.

/**
 * Send SAML2 Authentication request and get the SessionDataKey from IDP.
 *
 * @param client                    Closable HTTP Client.
 * @param saml2AuthRequest          SAML2 authentication request.
 * @param samlConfig                SAML configuration.
 * @param samlssoServiceProviderDTO SAMLSSO Service Provider DTO.
 * @param x509Credential            x509Credential implementation.
 * @param userAgent
 * @return HTTP Response with SessionDataKey from the IDP.
 * @throws Exception
 */
public HttpResponse sendSAMLAuthenticationRequest(CloseableHttpClient client, AuthnRequest saml2AuthRequest, SAMLConfig samlConfig, SAMLSSOServiceProviderDTO samlssoServiceProviderDTO, X509Credential x509Credential, String userAgent) throws Exception {
    HttpResponse response;
    if (SAMLConstants.SAML2_POST_BINDING_URI.equals(samlConfig.getHttpBinding())) {
        String samlPostRequest = buildSAMLPOSTRequest(saml2AuthRequest, samlConfig, x509Credential);
        response = sendSAMLPostMessage(client, samlSSOIDPUrl, SAML_REQUEST_PARAM, samlPostRequest, samlConfig, userAgent);
        EntityUtils.consume(response.getEntity());
        response = sendRedirectRequest(response, userAgent, samlssoServiceProviderDTO.getDefaultAssertionConsumerUrl(), client);
    } else if (SAMLConstants.SAML2_REDIRECT_BINDING_URI.equals(samlConfig.getHttpBinding())) {
        String redirectRequest = buildRedirectRequest(saml2AuthRequest, samlConfig, samlSSOIDPUrl, x509Credential);
        response = sendGetRequest(client, redirectRequest, null, new Header[] { new BasicHeader(HttpHeaders.USER_AGENT, userAgent) });
    } else {
        throw new Exception("Unsupported HTTP binding format " + samlConfig.getHttpBinding());
    }
    return response;
}
Also used : HttpResponse(org.apache.http.HttpResponse) BasicHeader(org.apache.http.message.BasicHeader) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ValidationException(org.opensaml.xml.validation.ValidationException) IdentitySAMLSSOConfigServiceIdentityException(org.wso2.carbon.identity.sso.saml.stub.IdentitySAMLSSOConfigServiceIdentityException) RemoteException(java.rmi.RemoteException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.opensaml.xml.ConfigurationException)

Aggregations

SAMLSSOServiceProviderDTO (org.wso2.carbon.identity.sso.saml.stub.types.SAMLSSOServiceProviderDTO)34 IOException (java.io.IOException)7 RemoteException (java.rmi.RemoteException)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 Test (org.testng.annotations.Test)5 IdentitySAMLSSOConfigServiceIdentityException (org.wso2.carbon.identity.sso.saml.stub.IdentitySAMLSSOConfigServiceIdentityException)5 SAXException (org.xml.sax.SAXException)5 SAMLSSOServiceProviderDTO (org.wso2.carbon.identity.sso.saml.dto.SAMLSSOServiceProviderDTO)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 HttpResponse (org.apache.http.HttpResponse)3 ConfigurationException (org.opensaml.xml.ConfigurationException)3 ValidationException (org.opensaml.xml.validation.ValidationException)3 IdentityException (org.wso2.carbon.identity.base.IdentityException)3 TransformerException (javax.xml.transform.TransformerException)2 Assertion (org.opensaml.saml2.core.Assertion)2 EncryptedAssertion (org.opensaml.saml2.core.EncryptedAssertion)2 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)2 Property (org.wso2.carbon.identity.application.common.model.Property)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)2