Search in sources :

Example 1 with KeyStoreCredentialProvider

use of org.pac4j.saml.crypto.KeyStoreCredentialProvider 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 KeyStoreCredentialProvider

use of org.pac4j.saml.crypto.KeyStoreCredentialProvider 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)

Example 3 with KeyStoreCredentialProvider

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

the class SAML2ClientTests method testSaml2ConfigurationOfKeyStoreUsingResource.

@Test
public void testSaml2ConfigurationOfKeyStoreUsingResource() throws IOException {
    final Resource rs = new FileSystemResource("testKeystore.jks");
    if (rs.exists() && !rs.getFile().delete()) {
        throw new TechnicalException("File could not be deleted");
    }
    final var cfg = new SAML2Configuration(new FileSystemResource("testKeystore.jks"), "pac4j-test-passwd", "pac4j-test-passwd", new ClassPathResource("testshib-providers.xml"));
    cfg.init();
    final var p = new KeyStoreCredentialProvider(cfg);
    assertNotNull(p.getKeyInfoGenerator());
    assertNotNull(p.getCredentialResolver());
    assertNotNull(p.getKeyInfo());
    assertNotNull(p.getKeyInfoCredentialResolver());
    assertNotNull(p.getCredential());
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 4 with KeyStoreCredentialProvider

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

the class SAML2ClientTests method testSaml2ConfigurationOfKeyStore.

@Test
public void testSaml2ConfigurationOfKeyStore() throws IOException {
    final Resource rs = new FileSystemResource("testKeystore.jks");
    if (rs.exists() && !rs.getFile().delete()) {
        throw new TechnicalException("File could not be deleted");
    }
    final var cfg = new SAML2Configuration("testKeystore.jks", "pac4j-test-passwd", "pac4j-test-passwd", "resource:testshib-providers.xml");
    cfg.init();
    final var p = new KeyStoreCredentialProvider(cfg);
    assertNotNull(p.getKeyInfoGenerator());
    assertNotNull(p.getCredentialResolver());
    assertNotNull(p.getKeyInfo());
    assertNotNull(p.getKeyInfoCredentialResolver());
    assertNotNull(p.getCredential());
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Aggregations

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