use of org.opensaml.saml.metadata.resolver.MetadataResolver in project verify-hub by alphagov.
the class SamlEngineModule method getVerifyMetadataResolver.
@Provides
@Singleton
@Named("VerifyMetadataResolver")
private MetadataResolver getVerifyMetadataResolver(Environment environment, SamlEngineConfiguration configuration) {
final MetadataResolver metadataResolver = new DropwizardMetadataResolverFactory().createMetadataResolver(environment, configuration.getMetadataConfiguration());
registerMetadataRefreshTask(environment, metadataResolver, configuration.getMetadataConfiguration(), "metadata");
return metadataResolver;
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class SamlRegisteredServiceDefaultCachingMetadataResolver method resolve.
@Override
public MetadataResolver resolve(final SamlRegisteredService service) {
MetadataResolver resolver = null;
try {
LOGGER.debug("Resolving metadata for [{}] at [{}].", service.getName(), service.getMetadataLocation());
resolver = this.cache.get(service);
return resolver;
} finally {
if (resolver != null) {
LOGGER.debug("Loaded and cached SAML metadata [{}] from [{}]", resolver.getId(), service.getMetadataLocation());
}
}
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project cas by apereo.
the class GroovyResourceMetadataResolver method resolve.
@Override
public Collection<MetadataResolver> resolve(final SamlRegisteredService service) {
try {
final String metadataLocation = service.getMetadataLocation();
LOGGER.info("Loading SAML metadata via [{}]", metadataLocation);
final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);
final Object[] args = { service, this.configBean, this.samlIdPProperties, LOGGER };
final MetadataResolver metadataResolver = ScriptingUtils.executeGroovyScript(metadataResource, args, MetadataResolver.class);
if (metadataResolver != null) {
return CollectionUtils.wrap(metadataResolver);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new ArrayList<>(0);
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project pac4j by pac4j.
the class SAML2Client method initChainingMetadataResolver.
protected ChainingMetadataResolver initChainingMetadataResolver(final MetadataResolver idpMetadataProvider, final MetadataResolver spMetadataProvider) {
final ChainingMetadataResolver metadataManager = new ChainingMetadataResolver();
metadataManager.setId(ChainingMetadataResolver.class.getCanonicalName());
try {
final List<MetadataResolver> list = new ArrayList<>();
list.add(idpMetadataProvider);
list.add(spMetadataProvider);
metadataManager.setResolvers(list);
metadataManager.initialize();
} catch (final ResolverException e) {
throw new TechnicalException("Error adding idp or sp metadatas to manager", e);
} catch (final ComponentInitializationException e) {
throw new TechnicalException("Error initializing manager", e);
}
return metadataManager;
}
use of org.opensaml.saml.metadata.resolver.MetadataResolver in project pac4j by pac4j.
the class SAML2ServiceProviderMetadataResolver method resolve.
@Override
public final MetadataResolver resolve() {
final boolean credentialProviderRequired = this.authnRequestSigned || this.wantsAssertionsSigned;
if (credentialProviderRequired && this.credentialProvider == null) {
throw new TechnicalException("Credentials Provider can not be null when authnRequestSigned or" + " wantsAssertionsSigned is set to true");
}
try {
final SAML2MetadataGenerator metadataGenerator = new SAML2MetadataGenerator(binding);
metadataGenerator.setWantAssertionSigned(this.wantsAssertionsSigned);
metadataGenerator.setAuthnRequestSigned(this.authnRequestSigned);
metadataGenerator.setNameIdPolicyFormat(this.nameIdPolicyFormat);
if (credentialProviderRequired) {
metadataGenerator.setCredentialProvider(this.credentialProvider);
}
metadataGenerator.setEntityId(this.spEntityId);
metadataGenerator.setRequestInitiatorLocation(callbackUrl);
// Assertion consumer service url is the callback url
metadataGenerator.setAssertionConsumerServiceUrl(callbackUrl);
// for now same for logout url
metadataGenerator.setSingleLogoutServiceUrl(callbackUrl);
final MetadataResolver spMetadataProvider = metadataGenerator.buildMetadataResolver();
// Initialize metadata provider for our SP and get the XML as a String
this.spMetadata = metadataGenerator.getMetadata();
if (this.spMetadataResource != null) {
if (spMetadataResource.exists() && !this.forceSpMetadataGeneration) {
logger.info("Metadata file already exists at {}.", this.spMetadataResource.getFilename());
} else {
logger.info("Writing sp metadata to {}", this.spMetadataResource.getFilename());
final File parent = spMetadataResource.getFile().getParentFile();
if (parent != null) {
logger.info("Attempting to create directory structure for: {}", parent.getCanonicalPath());
if (!parent.exists() && !parent.mkdirs()) {
logger.warn("Could not construct the directory structure for SP metadata: {}", parent.getCanonicalPath());
}
}
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
final StreamResult result = new StreamResult(new StringWriter());
final StreamSource source = new StreamSource(new StringReader(this.spMetadata));
transformer.transform(source, result);
try (final OutputStream spMetadataOutputStream = this.spMetadataResource.getOutputStream()) {
spMetadataOutputStream.write(result.getWriter().toString().getBytes(StandardCharsets.UTF_8));
}
}
}
return spMetadataProvider;
} catch (final ComponentInitializationException e) {
throw new TechnicalException("Error initializing spMetadataProvider", e);
} catch (final MarshallingException e) {
logger.warn("Unable to marshal SP metadata", e);
} catch (final IOException e) {
logger.warn("Unable to print SP metadata", e);
} catch (final Exception e) {
logger.warn("Unable to transform metadata", e);
}
return null;
}
Aggregations