Search in sources :

Example 1 with ComponentInitializationException

use of net.shibboleth.utilities.java.support.component.ComponentInitializationException in project verify-hub by alphagov.

the class HubAsIdpMetadataHandlerTest method initializeMetadata.

private MetadataResolver initializeMetadata() {
    try {
        InitializationService.initialize();
        String content = new MetadataFactory().defaultMetadata();
        StringBackedMetadataResolver metadataResolver = new StringBackedMetadataResolver(content);
        BasicParserPool pool = new BasicParserPool();
        pool.initialize();
        metadataResolver.setParserPool(pool);
        metadataResolver.setId("testResolver");
        metadataResolver.setResolveViaPredicatesOnly(true);
        metadataResolver.setRequireValidMetadata(true);
        EntityDescriptorCriterionPredicateRegistry registry = new EntityDescriptorCriterionPredicateRegistry();
        registry.register(EntitiesDescriptorNameCriterion.class, EntitiesDescriptorNamePredicate.class);
        metadataResolver.setCriterionPredicateRegistry(registry);
        metadataResolver.initialize();
        return metadataResolver;
    } catch (ComponentInitializationException | InitializationException e) {
        throw propagate(e);
    }
}
Also used : MetadataFactory(uk.gov.ida.saml.metadata.test.factories.metadata.MetadataFactory) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) BasicParserPool(net.shibboleth.utilities.java.support.xml.BasicParserPool) StringBackedMetadataResolver(uk.gov.ida.saml.metadata.StringBackedMetadataResolver) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) InitializationException(org.opensaml.core.config.InitializationException) EntityDescriptorCriterionPredicateRegistry(org.opensaml.saml.metadata.criteria.entity.impl.EntityDescriptorCriterionPredicateRegistry)

Example 2 with ComponentInitializationException

use of net.shibboleth.utilities.java.support.component.ComponentInitializationException in project verify-hub by alphagov.

the class EidasMetadataResolver method initialiseResolver.

private void initialiseResolver() {
    try {
        BasicParserPool parserPool = new BasicParserPool();
        parserPool.initialize();
        this.setParserPool(parserPool);
        this.setId("dynamic-resolver!");
        this.initialize();
    } catch (ComponentInitializationException e) {
        throw propagate(e);
    }
}
Also used : ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) BasicParserPool(net.shibboleth.utilities.java.support.xml.BasicParserPool)

Example 3 with ComponentInitializationException

use of net.shibboleth.utilities.java.support.component.ComponentInitializationException 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;
}
Also used : ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) TechnicalException(org.pac4j.core.exception.TechnicalException) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) ArrayList(java.util.ArrayList) SAML2IdentityProviderMetadataResolver(org.pac4j.saml.metadata.SAML2IdentityProviderMetadataResolver) SAML2ServiceProviderMetadataResolver(org.pac4j.saml.metadata.SAML2ServiceProviderMetadataResolver) SAML2MetadataResolver(org.pac4j.saml.metadata.SAML2MetadataResolver) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ChainingMetadataResolver(org.opensaml.saml.metadata.resolver.ChainingMetadataResolver)

Example 4 with ComponentInitializationException

use of net.shibboleth.utilities.java.support.component.ComponentInitializationException 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;
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) StreamSource(javax.xml.transform.stream.StreamSource) OutputStream(java.io.OutputStream) IOException(java.io.IOException) MetadataResolver(org.opensaml.saml.metadata.resolver.MetadataResolver) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) TechnicalException(org.pac4j.core.exception.TechnicalException) MarshallingException(org.opensaml.core.xml.io.MarshallingException) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) IOException(java.io.IOException) SAMLException(org.pac4j.saml.exceptions.SAMLException) StringWriter(java.io.StringWriter) MarshallingException(org.opensaml.core.xml.io.MarshallingException) StringReader(java.io.StringReader) File(java.io.File)

Example 5 with ComponentInitializationException

use of net.shibboleth.utilities.java.support.component.ComponentInitializationException in project pac4j by pac4j.

the class SAML2WebSSOMessageSender method sendMessage.

@Override
public void sendMessage(final SAML2MessageContext context, final AuthnRequest authnRequest, final Object relayState) {
    final SPSSODescriptor spDescriptor = context.getSPSSODescriptor();
    final IDPSSODescriptor idpssoDescriptor = context.getIDPSSODescriptor();
    final SingleSignOnService ssoService = context.getIDPSingleSignOnService(destinationBindingType);
    final AssertionConsumerService acsService = context.getSPAssertionConsumerService();
    final MessageEncoder encoder = getMessageEncoder(context);
    final SAML2MessageContext outboundContext = new SAML2MessageContext(context);
    outboundContext.getProfileRequestContext().setProfileId(context.getProfileRequestContext().getProfileId());
    outboundContext.getProfileRequestContext().setInboundMessageContext(context.getProfileRequestContext().getInboundMessageContext());
    outboundContext.getProfileRequestContext().setOutboundMessageContext(context.getProfileRequestContext().getOutboundMessageContext());
    outboundContext.setMessage(authnRequest);
    outboundContext.getSAMLEndpointContext().setEndpoint(acsService);
    outboundContext.getSAMLPeerEndpointContext().setEndpoint(ssoService);
    outboundContext.getSAMLPeerEntityContext().setRole(context.getSAMLPeerEntityContext().getRole());
    outboundContext.getSAMLPeerEntityContext().setEntityId(context.getSAMLPeerEntityContext().getEntityId());
    outboundContext.getSAMLProtocolContext().setProtocol(context.getSAMLProtocolContext().getProtocol());
    outboundContext.getSecurityParametersContext().setSignatureSigningParameters(this.signatureSigningParametersProvider.build(spDescriptor));
    if (relayState != null) {
        outboundContext.getSAMLBindingContext().setRelayState(relayState.toString());
    }
    try {
        invokeOutboundMessageHandlers(spDescriptor, idpssoDescriptor, outboundContext);
        encoder.setMessageContext(outboundContext);
        encoder.initialize();
        encoder.prepareContext();
        encoder.encode();
        final SAMLMessageStorage messageStorage = context.getSAMLMessageStorage();
        if (messageStorage != null) {
            messageStorage.storeMessage(authnRequest.getID(), authnRequest);
        }
    } catch (final MessageEncodingException e) {
        throw new SAMLException("Error encoding saml message", e);
    } catch (final ComponentInitializationException e) {
        throw new SAMLException("Error initializing saml encoder", e);
    }
}
Also used : SPSSODescriptor(org.opensaml.saml.saml2.metadata.SPSSODescriptor) SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) ComponentInitializationException(net.shibboleth.utilities.java.support.component.ComponentInitializationException) SingleSignOnService(org.opensaml.saml.saml2.metadata.SingleSignOnService) AssertionConsumerService(org.opensaml.saml.saml2.metadata.AssertionConsumerService) MessageEncoder(org.opensaml.messaging.encoder.MessageEncoder) SAMLMessageStorage(org.pac4j.saml.storage.SAMLMessageStorage) MessageEncodingException(org.opensaml.messaging.encoder.MessageEncodingException) SAMLException(org.pac4j.saml.exceptions.SAMLException)

Aggregations

ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)9 SAMLException (org.pac4j.saml.exceptions.SAMLException)5 BasicParserPool (net.shibboleth.utilities.java.support.xml.BasicParserPool)3 TechnicalException (org.pac4j.core.exception.TechnicalException)3 IOException (java.io.IOException)2 ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)2 InitializationException (org.opensaml.core.config.InitializationException)2 MessageEncoder (org.opensaml.messaging.encoder.MessageEncoder)2 MessageEncodingException (org.opensaml.messaging.encoder.MessageEncodingException)2 MetadataResolver (org.opensaml.saml.metadata.resolver.MetadataResolver)2 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)2 IDPSSODescriptor (org.opensaml.saml.saml2.metadata.IDPSSODescriptor)2 SPSSODescriptor (org.opensaml.saml.saml2.metadata.SPSSODescriptor)2 SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)2 SAMLMessageStorage (org.pac4j.saml.storage.SAMLMessageStorage)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1