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