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();
}
}
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());
}
Aggregations