Search in sources :

Example 1 with KeycloakSamlAdapter

use of org.keycloak.adapters.saml.config.KeycloakSamlAdapter in project keycloak by keycloak.

the class KeycloakSamlAdapterXMLParserTest method testXmlParserBaseFile.

@Test
public void testXmlParserBaseFile() throws Exception {
    KeycloakSamlAdapter config = parseKeycloakSamlAdapterConfig("keycloak-saml.xml", KeycloakSamlAdapter.class);
    assertThat(config, notNullValue());
    assertThat(config.getSps(), hasSize(1));
    SP sp = config.getSps().get(0);
    assertThat(sp.getEntityID(), is("sp"));
    assertThat(sp.getSslPolicy(), is("EXTERNAL"));
    assertThat(sp.getNameIDPolicyFormat(), is("format"));
    assertThat(sp.isForceAuthentication(), is(true));
    assertThat(sp.isIsPassive(), is(true));
    assertThat(sp.isAutodetectBearerOnly(), is(false));
    assertThat(sp.isKeepDOMAssertion(), is(false));
    assertThat(sp.getKeys(), hasSize(2));
    Key signing = sp.getKeys().get(0);
    assertThat(signing.isSigning(), is(true));
    Key.KeyStoreConfig keystore = signing.getKeystore();
    assertThat(keystore, notNullValue());
    assertThat(keystore.getFile(), is("file"));
    assertThat(keystore.getResource(), is("cp"));
    assertThat(keystore.getPassword(), is("pw"));
    assertThat(keystore.getPrivateKeyAlias(), is("private alias"));
    assertThat(keystore.getPrivateKeyPassword(), is("private pw"));
    assertThat(keystore.getCertificateAlias(), is("cert alias"));
    Key encryption = sp.getKeys().get(1);
    assertThat(encryption.isEncryption(), is(true));
    assertThat(encryption.getPrivateKeyPem(), is("private pem"));
    assertThat(encryption.getPublicKeyPem(), is("public pem"));
    assertThat(sp.getPrincipalNameMapping().getPolicy(), is("FROM_ATTRIBUTE"));
    assertThat(sp.getPrincipalNameMapping().getAttributeName(), is("attribute"));
    assertThat(sp.getRoleAttributes(), hasSize(1));
    assertThat(sp.getRoleAttributes(), Matchers.contains("member"));
    IDP idp = sp.getIdp();
    assertThat(idp.getEntityID(), is("idp"));
    assertThat(idp.getSignatureAlgorithm(), is("RSA_SHA256"));
    assertThat(idp.getSignatureCanonicalizationMethod(), is("canon"));
    assertThat(idp.getSingleSignOnService().isSignRequest(), is(true));
    assertThat(idp.getSingleSignOnService().isValidateResponseSignature(), is(true));
    assertThat(idp.getSingleSignOnService().getRequestBinding(), is("POST"));
    assertThat(idp.getSingleSignOnService().getBindingUrl(), is("url"));
    assertThat(idp.getSingleLogoutService().isSignRequest(), is(false));
    assertThat(idp.getSingleLogoutService().isSignResponse(), is(true));
    assertThat(idp.getSingleLogoutService().isValidateRequestSignature(), is(true));
    assertThat(idp.getSingleLogoutService().isValidateResponseSignature(), is(true));
    assertThat(idp.getSingleLogoutService().getRequestBinding(), is("REDIRECT"));
    assertThat(idp.getSingleLogoutService().getResponseBinding(), is("POST"));
    assertThat(idp.getSingleLogoutService().getPostBindingUrl(), is("posturl"));
    assertThat(idp.getSingleLogoutService().getRedirectBindingUrl(), is("redirecturl"));
    assertThat(idp.getKeys(), hasSize(1));
    assertThat(idp.getKeys().get(0).isSigning(), is(true));
    assertThat(idp.getKeys().get(0).getCertificatePem(), is("cert pem"));
}
Also used : IDP(org.keycloak.adapters.saml.config.IDP) KeycloakSamlAdapter(org.keycloak.adapters.saml.config.KeycloakSamlAdapter) SP(org.keycloak.adapters.saml.config.SP) Key(org.keycloak.adapters.saml.config.Key) Test(org.junit.Test)

Example 2 with KeycloakSamlAdapter

use of org.keycloak.adapters.saml.config.KeycloakSamlAdapter in project keycloak by keycloak.

the class KeycloakSamlAdapterXMLParserTest method testXmlParserSystemPropertiesWithPropertiesSet.

@Test
public void testXmlParserSystemPropertiesWithPropertiesSet() throws Exception {
    try {
        System.setProperty("keycloak-saml-properties.entityID", "meid");
        System.setProperty("keycloak-saml-properties.sslPolicy", "INTERNAL");
        System.setProperty("keycloak-saml-properties.signaturesRequired", "true");
        KeycloakSamlAdapter config = parseKeycloakSamlAdapterConfig("keycloak-saml-properties.xml", KeycloakSamlAdapter.class);
        assertThat(config, notNullValue());
        assertThat(config.getSps(), Matchers.contains(instanceOf(SP.class)));
        SP sp = config.getSps().get(0);
        IDP idp = sp.getIdp();
        assertThat(sp.getEntityID(), is("meid"));
        assertThat(sp.getSslPolicy(), is("INTERNAL"));
        assertThat(idp.isSignaturesRequired(), is(true));
        assertThat(idp.getSingleLogoutService().isSignRequest(), is(true));
        assertThat(idp.getSingleLogoutService().isSignResponse(), is(false));
        assertThat(idp.getSingleSignOnService().isSignRequest(), is(true));
        assertThat(idp.getSingleSignOnService().isValidateResponseSignature(), is(true));
        // These should take default from IDP.signaturesRequired
        assertThat(idp.getSingleLogoutService().isValidateRequestSignature(), is(true));
        assertThat(idp.getSingleLogoutService().isValidateResponseSignature(), is(true));
        // This is false by default
        assertThat(idp.getSingleSignOnService().isValidateAssertionSignature(), is(false));
    } finally {
        System.clearProperty("keycloak-saml-properties.entityID");
        System.clearProperty("keycloak-saml-properties.sslPolicy");
        System.clearProperty("keycloak-saml-properties.signaturesRequired");
    }
}
Also used : IDP(org.keycloak.adapters.saml.config.IDP) KeycloakSamlAdapter(org.keycloak.adapters.saml.config.KeycloakSamlAdapter) SP(org.keycloak.adapters.saml.config.SP) Test(org.junit.Test)

Example 3 with KeycloakSamlAdapter

use of org.keycloak.adapters.saml.config.KeycloakSamlAdapter in project keycloak by keycloak.

the class KeycloakSamlAdapterXMLParserTest method testMetadataUrl.

@Test
public void testMetadataUrl() throws Exception {
    KeycloakSamlAdapter config = parseKeycloakSamlAdapterConfig("keycloak-saml-with-metadata-url.xml", KeycloakSamlAdapter.class);
    assertThat(config, notNullValue());
    assertThat(config.getSps(), Matchers.contains(instanceOf(SP.class)));
    SP sp = config.getSps().get(0);
    IDP idp = sp.getIdp();
    assertThat(idp.getMetadataUrl(), is("https:///example.com/metadata.xml"));
}
Also used : IDP(org.keycloak.adapters.saml.config.IDP) KeycloakSamlAdapter(org.keycloak.adapters.saml.config.KeycloakSamlAdapter) SP(org.keycloak.adapters.saml.config.SP) Test(org.junit.Test)

Example 4 with KeycloakSamlAdapter

use of org.keycloak.adapters.saml.config.KeycloakSamlAdapter in project keycloak by keycloak.

the class KeycloakSamlAdapterXMLParserTest method testXmlParserSystemPropertiesNoPropertiesSet.

@Test
public void testXmlParserSystemPropertiesNoPropertiesSet() throws Exception {
    KeycloakSamlAdapter config = parseKeycloakSamlAdapterConfig("keycloak-saml-properties.xml", KeycloakSamlAdapter.class);
    assertThat(config, notNullValue());
    assertThat(config.getSps(), Matchers.contains(instanceOf(SP.class)));
    SP sp = config.getSps().get(0);
    IDP idp = sp.getIdp();
    assertThat(sp.getEntityID(), is("sp"));
    assertThat(sp.getSslPolicy(), is("${keycloak-saml-properties.sslPolicy}"));
    assertThat(idp.isSignaturesRequired(), is(false));
    assertThat(idp.getSingleLogoutService().isSignRequest(), is(true));
    assertThat(idp.getSingleLogoutService().isSignResponse(), is(false));
    assertThat(idp.getSingleSignOnService().isSignRequest(), is(true));
    assertThat(idp.getSingleSignOnService().isValidateResponseSignature(), is(true));
    // These should take default from IDP.signaturesRequired
    assertThat(idp.getSingleLogoutService().isValidateRequestSignature(), is(false));
    assertThat(idp.getSingleLogoutService().isValidateResponseSignature(), is(false));
    assertThat(idp.getSingleSignOnService().isValidateAssertionSignature(), is(false));
}
Also used : IDP(org.keycloak.adapters.saml.config.IDP) KeycloakSamlAdapter(org.keycloak.adapters.saml.config.KeycloakSamlAdapter) SP(org.keycloak.adapters.saml.config.SP) Test(org.junit.Test)

Example 5 with KeycloakSamlAdapter

use of org.keycloak.adapters.saml.config.KeycloakSamlAdapter in project keycloak by keycloak.

the class KeycloakSamlAdapterXMLParserTest method testValidationWithKeepDOMAssertion.

@Test
public void testValidationWithKeepDOMAssertion() throws Exception {
    testValidationValid("keycloak-saml-keepdomassertion.xml");
    // check keep dom assertion is TRUE
    KeycloakSamlAdapter config = parseKeycloakSamlAdapterConfig("keycloak-saml-keepdomassertion.xml", KeycloakSamlAdapter.class);
    assertThat(config, Matchers.notNullValue());
    assertThat(config.getSps(), hasSize(1));
    SP sp = config.getSps().get(0);
    assertThat(sp.isKeepDOMAssertion(), is(true));
}
Also used : KeycloakSamlAdapter(org.keycloak.adapters.saml.config.KeycloakSamlAdapter) SP(org.keycloak.adapters.saml.config.SP) Test(org.junit.Test)

Aggregations

KeycloakSamlAdapter (org.keycloak.adapters.saml.config.KeycloakSamlAdapter)11 SP (org.keycloak.adapters.saml.config.SP)11 Test (org.junit.Test)10 IDP (org.keycloak.adapters.saml.config.IDP)9 Key (org.keycloak.adapters.saml.config.Key)3 FileNotFoundException (java.io.FileNotFoundException)1 KeyPair (java.security.KeyPair)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 HttpClientBuilder (org.keycloak.adapters.cloned.HttpClientBuilder)1 DefaultSamlDeployment (org.keycloak.adapters.saml.DefaultSamlDeployment)1 SamlDeployment (org.keycloak.adapters.saml.SamlDeployment)1 SslRequired (org.keycloak.common.enums.SslRequired)1