Search in sources :

Example 16 with SAMLException

use of org.pac4j.saml.exceptions.SAMLException in project pac4j by pac4j.

the class Configuration method serializeSamlObject.

public static StringWriter serializeSamlObject(final XMLObject samlObject) {
    final StringWriter writer = new StringWriter();
    try {
        final Marshaller marshaller = getMarshallerFactory().getMarshaller(samlObject.getElementQName());
        if (marshaller != null) {
            final Element element = marshaller.marshall(samlObject);
            final DOMSource domSource = new DOMSource(element);
            final StreamResult result = new StreamResult(writer);
            final TransformerFactory tf = TransformerFactory.newInstance();
            final Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            transformer.transform(domSource, result);
        }
    } catch (final Exception e) {
        throw new SAMLException(e.getMessage(), e);
    }
    return writer;
}
Also used : Marshaller(org.opensaml.core.xml.io.Marshaller) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) SAMLException(org.pac4j.saml.exceptions.SAMLException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) InitializationException(org.opensaml.core.config.InitializationException) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 17 with SAMLException

use of org.pac4j.saml.exceptions.SAMLException in project pac4j by pac4j.

the class ExplicitSignatureTrustEngineProvider method build.

@Override
public SignatureTrustEngine build() {
    final MetadataCredentialResolver metadataCredentialResolver = new MetadataCredentialResolver();
    final BasicRoleDescriptorResolver roleResolver = new BasicRoleDescriptorResolver(metadataResolver);
    final KeyInfoCredentialResolver keyResolver = DefaultSecurityConfigurationBootstrap.buildBasicInlineKeyInfoCredentialResolver();
    metadataCredentialResolver.setKeyInfoCredentialResolver(keyResolver);
    metadataCredentialResolver.setRoleDescriptorResolver(roleResolver);
    try {
        metadataCredentialResolver.initialize();
        roleResolver.initialize();
    } catch (final ComponentInitializationException e) {
        throw new SAMLException(e);
    }
    return new ExplicitKeySignatureTrustEngine(metadataCredentialResolver, keyResolver);
}
Also used : ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) ExplicitKeySignatureTrustEngine(org.opensaml.xmlsec.signature.support.impl.ExplicitKeySignatureTrustEngine) BasicRoleDescriptorResolver(org.opensaml.saml.metadata.resolver.impl.BasicRoleDescriptorResolver) MetadataCredentialResolver(org.opensaml.saml.security.impl.MetadataCredentialResolver) KeyInfoCredentialResolver(org.opensaml.xmlsec.keyinfo.KeyInfoCredentialResolver) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 18 with SAMLException

use of org.pac4j.saml.exceptions.SAMLException in project pac4j by pac4j.

the class KeyStoreCredentialProvider method loadKeyStore.

private KeyStore loadKeyStore(final InputStream inputStream, final String storePasswd, final String keyStoreType) {
    try {
        final KeyStore ks = KeyStore.getInstance(keyStoreType);
        ks.load(inputStream, storePasswd == null ? null : storePasswd.toCharArray());
        return ks;
    } catch (final Exception e) {
        throw new SAMLException("Error loading keystore", e);
    }
}
Also used : KeyStore(java.security.KeyStore) SAMLException(org.pac4j.saml.exceptions.SAMLException) KeyStoreException(java.security.KeyStoreException) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) IOException(java.io.IOException) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Example 19 with SAMLException

use of org.pac4j.saml.exceptions.SAMLException in project pac4j by pac4j.

the class SAML2IdentityProviderMetadataResolver method resolve.

@Override
public final MetadataResolver resolve() {
    // Usage of locks will adversly impact performance.
    if (idpMetadataProvider != null) {
        return idpMetadataProvider;
    }
    try {
        if (this.idpMetadataResource == null) {
            throw new XMLParserException("idp metadata cannot be resolved from " + this.idpMetadataResource);
        }
        try (final InputStream in = this.idpMetadataResource.getInputStream()) {
            final Document inCommonMDDoc = Configuration.getParserPool().parse(in);
            final Element metadataRoot = inCommonMDDoc.getDocumentElement();
            idpMetadataProvider = new DOMMetadataResolver(metadataRoot);
            idpMetadataProvider.setParserPool(Configuration.getParserPool());
            idpMetadataProvider.setFailFastInitialization(true);
            idpMetadataProvider.setRequireValidMetadata(true);
            idpMetadataProvider.setId(idpMetadataProvider.getClass().getCanonicalName());
            idpMetadataProvider.initialize();
        } catch (final FileNotFoundException e) {
            throw new TechnicalException("Error loading idp Metadata");
        }
        // If no idpEntityId declared, select first EntityDescriptor entityId as our IDP entityId
        if (this.idpEntityId == null) {
            final Iterator<EntityDescriptor> it = idpMetadataProvider.iterator();
            while (it.hasNext()) {
                final EntityDescriptor entityDescriptor = it.next();
                if (this.idpEntityId == null) {
                    this.idpEntityId = entityDescriptor.getEntityID();
                }
            }
        }
        if (this.idpEntityId == null) {
            throw new SAMLException("No idp entityId found");
        }
    } catch (final ComponentInitializationException e) {
        throw new SAMLException("Error initializing idpMetadataProvider", e);
    } catch (final XMLParserException e) {
        throw new TechnicalException("Error parsing idp Metadata", e);
    } catch (final IOException e) {
        throw new TechnicalException("Error getting idp Metadata resource", e);
    }
    return idpMetadataProvider;
}
Also used : DOMMetadataResolver(org.opensaml.saml.metadata.resolver.impl.DOMMetadataResolver) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) TechnicalException(org.pac4j.core.exception.TechnicalException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) XMLParserException(net.shibboleth.utilities.java.support.xml.XMLParserException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Aggregations

SAMLException (org.pac4j.saml.exceptions.SAMLException)19 ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)7 MessageEncodingException (org.opensaml.messaging.encoder.MessageEncodingException)4 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)4 SAMLMessageStorage (org.pac4j.saml.storage.SAMLMessageStorage)4 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)3 ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)3 EntityDescriptor (org.opensaml.saml.saml2.metadata.EntityDescriptor)3 SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)3 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 EntityIdCriterion (org.opensaml.core.criterion.EntityIdCriterion)2 XMLObject (org.opensaml.core.xml.XMLObject)2 MessageEncoder (org.opensaml.messaging.encoder.MessageEncoder)2 SAMLObject (org.opensaml.saml.common.SAMLObject)2 SAMLOutboundDestinationHandler (org.opensaml.saml.common.binding.impl.SAMLOutboundDestinationHandler)2 EndpointURLSchemeSecurityHandler (org.opensaml.saml.common.binding.security.impl.EndpointURLSchemeSecurityHandler)2 SAMLOutboundProtocolMessageSigningHandler (org.opensaml.saml.common.binding.security.impl.SAMLOutboundProtocolMessageSigningHandler)2 Response (org.opensaml.saml.saml2.core.Response)2 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)2