use of org.opensaml.core.xml.io.MarshallingException 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;
}
use of org.opensaml.core.xml.io.MarshallingException in project spring-security by spring-projects.
the class OpenSamlAuthenticationProviderTests method serialize.
private String serialize(XMLObject object) {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
Element element = marshaller.marshall(object);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException ex) {
throw new Saml2Exception(ex);
}
}
use of org.opensaml.core.xml.io.MarshallingException in project spring-security by spring-projects.
the class TestOpenSamlObjects method signed.
static <T extends SignableSAMLObject> T signed(T signable, Saml2X509Credential credential, String entityId, String signAlgorithmUri) {
SignatureSigningParameters parameters = new SignatureSigningParameters();
Credential signingCredential = getSigningCredential(credential, entityId);
parameters.setSigningCredential(signingCredential);
parameters.setSignatureAlgorithm(signAlgorithmUri);
parameters.setSignatureReferenceDigestMethod(SignatureConstants.ALGO_ID_DIGEST_SHA256);
parameters.setSignatureCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
try {
SignatureSupport.signObject(signable, parameters);
} catch (MarshallingException | SignatureException | SecurityException ex) {
throw new Saml2Exception(ex);
}
return signable;
}
use of org.opensaml.core.xml.io.MarshallingException in project spring-security by spring-projects.
the class OpenSamlSigningUtils method serialize.
static String serialize(XMLObject object) {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
Element element = marshaller.marshall(object);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException ex) {
throw new Saml2Exception(ex);
}
}
use of org.opensaml.core.xml.io.MarshallingException in project spring-security by spring-projects.
the class OpenSaml4AuthenticationProviderTests method serialize.
private String serialize(XMLObject object) {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
Element element = marshaller.marshall(object);
return SerializeSupport.nodeToString(element);
} catch (MarshallingException ex) {
throw new Saml2Exception(ex);
}
}
Aggregations