protected void signMessage(SAMLMessageContext messageContext) throws MessageEncodingException {
SAMLObject outboundSAML = messageContext.getOutboundSAMLMessage();
Credential signingCredential = messageContext.getOuboundSAMLMessageSigningCredential();
if (outboundSAML instanceof SignableSAMLObject && signingCredential != null) {
SignableSAMLObject signableMessage = (SignableSAMLObject) outboundSAML;
XMLObjectBuilder<Signature> signatureBuilder = Configuration.getBuilderFactory().getBuilder(
Signature.DEFAULT_ELEMENT_NAME);
Signature signature = signatureBuilder.buildObject(Signature.DEFAULT_ELEMENT_NAME);
signature.setSigningCredential(signingCredential);
try {
//TODO pull SecurityConfiguration from SAMLMessageContext? needs to be added
//TODO pull binding-specific keyInfoGenName from encoder setting, etc?
SecurityHelper.prepareSignatureParams(signature, signingCredential, null, null);
} catch (SecurityException e) {
throw new MessageEncodingException("Error preparing signature for signing", e);
}
signableMessage.setSignature(signature);
try {
Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(signableMessage);
if (marshaller == null) {
throw new MessageEncodingException("No marshaller registered for "
+ signableMessage.getElementQName() + ", unable to marshall in preperation for signing");
}
marshaller.marshall(signableMessage);
Signer.signObject(signature);
} catch (MarshallingException e) {