}
SAMLMessageContext<SAMLObject, Response, NameIdentifier> artifactContext = (SAMLMessageContext) messageContext;
HTTPOutTransport outTransport = (HTTPOutTransport) artifactContext.getOutboundMessageTransport();
URLBuilder urlBuilder = new URLBuilder(getEndpointURL(artifactContext));
List<Pair<String, String>> params = urlBuilder.getQueryParams();
params.add(new Pair<String, String>("TARGET", HTTPTransportUtils.urlEncode(artifactContext.getRelayState())));
SAML1ArtifactBuilder artifactBuilder;
if (artifactContext.getOutboundMessageArtifactType() != null) {
artifactBuilder = Configuration.getSAML1ArtifactBuilderFactory().getArtifactBuilder(
artifactContext.getOutboundMessageArtifactType());
} else {
artifactBuilder = Configuration.getSAML1ArtifactBuilderFactory().getArtifactBuilder(defaultArtifactType);
artifactContext.setOutboundMessageArtifactType(defaultArtifactType);
}
AbstractSAML1Artifact artifact;
String artifactString;
for (Assertion assertion : artifactContext.getOutboundSAMLMessage().getAssertions()) {
artifact = artifactBuilder.buildArtifact(artifactContext, assertion);
try {
artifactMap.put(artifact.base64Encode(), messageContext.getInboundMessageIssuer(), messageContext
.getOutboundMessageIssuer(), assertion);
} catch (MarshallingException e) {
log.error("Unable to marshall assertion to be represented as an artifact", e);
throw new MessageEncodingException("Unable to marshall assertion to be represented as an artifact", e);
}
artifactString = artifact.base64Encode();
params.add(new Pair<String, String>("SAMLart", artifactString));
}
String redirectUrl = urlBuilder.buildURL();
log.debug("Sending redirect to URL {} to relying party {}", redirectUrl, artifactContext
.getInboundMessageIssuer());
outTransport.sendRedirect(urlBuilder.buildURL());
}