Search in sources :

Example 1 with SOAPException

use of org.opensaml.soap.common.SOAPException in project pac4j by pac4j.

the class Pac4jHTTPArtifactDecoder method dereferenceArtifact.

/**
 * De-reference the supplied artifact into the corresponding SAML protocol message.
 *
 * @param artifact           the artifact to de-reference
 * @param peerRoleDescriptor the peer RoleDescriptor
 * @param ars                the peer's artifact resolution service endpoint
 * @return the de-referenced artifact
 * @throws MessageDecodingException if there is fatal error, or if the artifact was not successfully resolved
 */
@Nonnull
private SAMLObject dereferenceArtifact(@Nonnull final SAML2Artifact artifact, @Nonnull final RoleDescriptor peerRoleDescriptor, @Nonnull final ArtifactResolutionService ars) throws MessageDecodingException {
    try {
        final var selfEntityID = resolveSelfEntityID(peerRoleDescriptor);
        // TODO can assume/enforce response as ArtifactResponse here?
        final var opContext = new SAMLSOAPClientContextBuilder().setOutboundMessage(buildArtifactResolveRequestMessage(artifact, ars.getLocation(), selfEntityID)).setProtocol(SAMLConstants.SAML20P_NS).setPipelineName(getSOAPPipelineName()).setSecurityConfigurationProfileId(getSOAPClientSecurityConfigurationProfileId()).setPeerRoleDescriptor(peerRoleDescriptor).setSelfEntityID(selfEntityID).build();
        log.trace("Executing ArtifactResolve over SOAP 1.1 binding to endpoint: {}", ars.getLocation());
        soapClient.send(ars.getLocation(), opContext);
        final var response = (SAMLObject) opContext.getInboundMessageContext().getMessage();
        if (response instanceof ArtifactResponse) {
            return validateAndExtractResponseMessage((ArtifactResponse) response);
        } else {
            throw new MessageDecodingException("SOAP message payload was not an instance of ArtifactResponse: " + response.getClass().getName());
        }
    } catch (final MessageException | SOAPException | SecurityException e) {
        throw new MessageDecodingException("Error dereferencing artifact", e);
    }
}
Also used : MessageDecodingException(org.opensaml.messaging.decoder.MessageDecodingException) SAMLObject(org.opensaml.saml.common.SAMLObject) MessageException(org.opensaml.messaging.MessageException) ArtifactResponse(org.opensaml.saml.saml2.core.ArtifactResponse) SOAPException(org.opensaml.soap.common.SOAPException) SecurityException(org.opensaml.security.SecurityException) SAMLSOAPClientContextBuilder(org.opensaml.saml.common.messaging.soap.SAMLSOAPClientContextBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with SOAPException

use of org.opensaml.soap.common.SOAPException in project pac4j by pac4j.

the class SAML2ArtifactBindingDecoder method doDecode.

@Override
protected void doDecode() throws MessageDecodingException {
    try {
        final var endpointResolver = new DefaultEndpointResolver<ArtifactResolutionService>();
        endpointResolver.initialize();
        final var roleResolver = new PredicateRoleDescriptorResolver(idpMetadataResolver.resolve());
        roleResolver.initialize();
        final var messageContext = new SAML2MessageContext();
        final var soapClient = new PipelineFactoryHttpSOAPClient() {

            @SuppressWarnings("rawtypes")
            @Override
            public void send(final String endpoint, final InOutOperationContext operationContext) throws SOAPException, SecurityException {
                super.send(endpoint, operationContext);
                transferContext(operationContext, messageContext);
            }
        };
        soapClient.setPipelineFactory(soapPipelineProvider.getPipelineFactory());
        soapClient.setHttpClient(soapPipelineProvider.getHttpClientBuilder().buildClient());
        final var artifactDecoder = new Pac4jHTTPArtifactDecoder();
        artifactDecoder.setWebContext(context);
        artifactDecoder.setSelfEntityIDResolver(new FixedEntityIdResolver(spMetadataResolver));
        artifactDecoder.setRoleDescriptorResolver(roleResolver);
        artifactDecoder.setArtifactEndpointResolver(endpointResolver);
        artifactDecoder.setPeerEntityRole(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
        artifactDecoder.setSOAPClient(soapClient);
        artifactDecoder.setParserPool(getParserPool());
        artifactDecoder.initialize();
        artifactDecoder.decode();
        messageContext.getMessageContext().setMessage(artifactDecoder.getMessageContext().getMessage());
        this.populateBindingContext(messageContext);
        this.setMessageContext(messageContext.getMessageContext());
    } catch (final Exception e) {
        throw new MessageDecodingException(e);
    }
}
Also used : SAML2MessageContext(org.pac4j.saml.context.SAML2MessageContext) PipelineFactoryHttpSOAPClient(org.opensaml.soap.client.http.PipelineFactoryHttpSOAPClient) MessageDecodingException(org.opensaml.messaging.decoder.MessageDecodingException) DefaultEndpointResolver(org.opensaml.saml.common.binding.impl.DefaultEndpointResolver) InOutOperationContext(org.opensaml.messaging.context.InOutOperationContext) PredicateRoleDescriptorResolver(org.opensaml.saml.metadata.resolver.impl.PredicateRoleDescriptorResolver) Pac4jHTTPArtifactDecoder(org.pac4j.saml.transport.Pac4jHTTPArtifactDecoder) SecurityException(org.opensaml.security.SecurityException) MessageDecodingException(org.opensaml.messaging.decoder.MessageDecodingException) SOAPException(org.opensaml.soap.common.SOAPException)

Aggregations

MessageDecodingException (org.opensaml.messaging.decoder.MessageDecodingException)2 SecurityException (org.opensaml.security.SecurityException)2 SOAPException (org.opensaml.soap.common.SOAPException)2 Nonnull (javax.annotation.Nonnull)1 MessageException (org.opensaml.messaging.MessageException)1 InOutOperationContext (org.opensaml.messaging.context.InOutOperationContext)1 SAMLObject (org.opensaml.saml.common.SAMLObject)1 DefaultEndpointResolver (org.opensaml.saml.common.binding.impl.DefaultEndpointResolver)1 SAMLSOAPClientContextBuilder (org.opensaml.saml.common.messaging.soap.SAMLSOAPClientContextBuilder)1 PredicateRoleDescriptorResolver (org.opensaml.saml.metadata.resolver.impl.PredicateRoleDescriptorResolver)1 ArtifactResponse (org.opensaml.saml.saml2.core.ArtifactResponse)1 PipelineFactoryHttpSOAPClient (org.opensaml.soap.client.http.PipelineFactoryHttpSOAPClient)1 SAML2MessageContext (org.pac4j.saml.context.SAML2MessageContext)1 Pac4jHTTPArtifactDecoder (org.pac4j.saml.transport.Pac4jHTTPArtifactDecoder)1