/** {@inheritDoc} */
protected void doEncode(MessageContext messageContext) throws MessageEncodingException {
if (!(messageContext instanceof SAMLMessageContext)) {
log.error("Invalid message context type, this encoder only support SAMLMessageContext");
throw new MessageEncodingException(
"Invalid message context type, this encoder only support SAMLMessageContext");
}
if (!(messageContext.getOutboundMessageTransport() instanceof HTTPOutTransport)) {
log.error("Invalid outbound message transport type, this encoder only support HTTPOutTransport");
throw new MessageEncodingException(
"Invalid outbound message transport type, this encoder only support HTTPOutTransport");
}
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));
}