use of org.pac4j.saml.util.DefaultConfigurationManager 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.util.DefaultConfigurationManager in project pac4j by pac4j.
the class SAML2HttpUrlMetadataGeneratorTests method initialConfiguration.
private static SAML2Configuration initialConfiguration() throws MalformedURLException {
final ConfigurationManager mgr = new DefaultConfigurationManager();
mgr.configure();
final var configuration = new SAML2Configuration();
configuration.setForceKeystoreGeneration(true);
configuration.setKeystorePath("target/keystore.jks");
configuration.setKeystorePassword("pac4j");
configuration.setPrivateKeyPassword("pac4j");
configuration.setSignMetadata(true);
configuration.setServiceProviderEntityId("urn:mace:saml:pac4j.org");
configuration.setServiceProviderMetadataResource(new UrlResource("http://localhost:8088/saml"));
configuration.setIdentityProviderMetadataResource(new ClassPathResource("idp-metadata.xml"));
configuration.init();
return configuration;
}
use of org.pac4j.saml.util.DefaultConfigurationManager 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.util.DefaultConfigurationManager in project pac4j by pac4j.
the class SAML2FileSystemKeystoreGeneratorTests method verifyKeystoreGenForNewDirectory.
@Test
public void verifyKeystoreGenForNewDirectory() throws Exception {
final ConfigurationManager mgr = new DefaultConfigurationManager();
mgr.configure();
final var configuration = new SAML2Configuration();
configuration.setCertificateSignatureAlg("SHA256withRSA");
configuration.setForceKeystoreGeneration(true);
final var path = RandomStringUtils.randomAlphabetic(4);
configuration.setKeystorePath(String.format("%s/%s/keystore.jks", FileUtils.getTempDirectoryPath(), path));
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());
}
use of org.pac4j.saml.util.DefaultConfigurationManager in project pac4j by pac4j.
the class SAML2FileSystemMetadataGeneratorTests method verifyGeneration.
@Test
public void verifyGeneration() throws Exception {
final ConfigurationManager mgr = new DefaultConfigurationManager();
mgr.configure();
final var configuration = new SAML2Configuration();
configuration.setForceKeystoreGeneration(true);
configuration.setKeystorePath("target/keystore.jks");
configuration.setKeystorePassword("pac4j");
configuration.setPrivateKeyPassword("pac4j");
configuration.setSignMetadata(true);
configuration.setServiceProviderMetadataResource(new FileSystemResource("target/out.xml"));
configuration.setIdentityProviderMetadataResource(new ClassPathResource("idp-metadata.xml"));
configuration.init();
final SAML2MetadataGenerator metadataGenerator = new SAML2FileSystemMetadataGenerator();
final var entity = metadataGenerator.buildEntityDescriptor();
assertNotNull(entity);
final var metadata = metadataGenerator.getMetadata(entity);
assertNotNull(metadata);
metadataGenerator.storeMetadata(metadata, configuration.getServiceProviderMetadataResource(), true);
assertNotNull(metadataGenerator.buildMetadataResolver(configuration.getServiceProviderMetadataResource()));
}
Aggregations