Search in sources :

Example 1 with CredentialProvider

use of org.pac4j.saml.crypto.CredentialProvider in project pac4j by pac4j.

the class SAML2HttpUrlKeystoreGeneratorTests method verifyKeystoreGeneration.

@Test
public void verifyKeystoreGeneration() throws Exception {
    final ConfigurationManager mgr = new DefaultConfigurationManager();
    mgr.configure();
    final var wireMockServer = new WireMockServer(8085);
    try {
        wireMockServer.stubFor(post(urlPathEqualTo("/keystore")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", ContentType.TEXT_PLAIN.getMimeType())));
        final var restBody = IOUtils.toString(new ClassPathResource("dummy-keystore.txt").getInputStream(), StandardCharsets.UTF_8);
        wireMockServer.stubFor(get(urlPathEqualTo("/keystore")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", ContentType.TEXT_PLAIN.getMimeType()).withBody(restBody)));
        wireMockServer.start();
        final var configuration = new SAML2Configuration();
        configuration.setCertificateSignatureAlg("SHA256withRSA");
        configuration.setForceKeystoreGeneration(true);
        configuration.setKeystoreResourceUrl("http://localhost:8085/keystore");
        configuration.setKeystorePassword("pac4j");
        configuration.setPrivateKeyPassword("pac4j");
        configuration.setServiceProviderMetadataResource(new FileSystemResource("target/out.xml"));
        configuration.setIdentityProviderMetadataResource(new ClassPathResource("idp-metadata.xml"));
        configuration.init();
        final CredentialProvider provider = new KeyStoreCredentialProvider(configuration);
        assertNotNull(provider.getCredentialResolver());
        assertNotNull(provider.getCredential());
        assertNotNull(provider.getKeyInfo());
    } finally {
        wireMockServer.stop();
    }
}
Also used : DefaultConfigurationManager(org.pac4j.saml.util.DefaultConfigurationManager) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) CredentialProvider(org.pac4j.saml.crypto.CredentialProvider) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) FileSystemResource(org.springframework.core.io.FileSystemResource) DefaultConfigurationManager(org.pac4j.saml.util.DefaultConfigurationManager) ConfigurationManager(org.pac4j.saml.util.ConfigurationManager) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with CredentialProvider

use of org.pac4j.saml.crypto.CredentialProvider in project pac4j by pac4j.

the class SAML2FileSystemKeystoreGeneratorTests method verifyKeystoreGeneration.

@Test
public void verifyKeystoreGeneration() throws Exception {
    final ConfigurationManager mgr = new DefaultConfigurationManager();
    mgr.configure();
    final var configuration = new SAML2Configuration();
    configuration.setCertificateSignatureAlg("SHA256withRSA");
    configuration.setForceKeystoreGeneration(true);
    configuration.setKeystorePath("target/keystore.jks");
    configuration.setKeystorePassword("pac4j");
    configuration.setPrivateKeyPassword("pac4j");
    configuration.setServiceProviderMetadataResource(new FileSystemResource("target/out.xml"));
    configuration.setIdentityProviderMetadataResource(new ClassPathResource("idp-metadata.xml"));
    configuration.init();
    final SAML2KeystoreGenerator generator = new SAML2FileSystemKeystoreGenerator(configuration);
    generator.generate();
    assertTrue(configuration.getKeystoreResource().getFile().exists());
    final CredentialProvider provider = new KeyStoreCredentialProvider(configuration);
    assertNotNull(provider.getCredentialResolver());
    assertNotNull(provider.getCredential());
    assertNotNull(provider.getKeyInfo());
}
Also used : DefaultConfigurationManager(org.pac4j.saml.util.DefaultConfigurationManager) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) CredentialProvider(org.pac4j.saml.crypto.CredentialProvider) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) FileSystemResource(org.springframework.core.io.FileSystemResource) ConfigurationManager(org.pac4j.saml.util.ConfigurationManager) DefaultConfigurationManager(org.pac4j.saml.util.DefaultConfigurationManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SAML2Configuration (org.pac4j.saml.config.SAML2Configuration)2 CredentialProvider (org.pac4j.saml.crypto.CredentialProvider)2 KeyStoreCredentialProvider (org.pac4j.saml.crypto.KeyStoreCredentialProvider)2 ConfigurationManager (org.pac4j.saml.util.ConfigurationManager)2 DefaultConfigurationManager (org.pac4j.saml.util.DefaultConfigurationManager)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 FileSystemResource (org.springframework.core.io.FileSystemResource)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1