/** * Sends SAML message using the given binding. Context is expected to contain outboundMessageTransport. In case localEntityId or localEntityRole * is set, it is used, default SP is used otherwise. * * @param samlContext context * @param sign if true sent message is signed * @param binding binding to use * @return context * @throws SAMLException in case message can't be sent * @throws MessageEncodingException in case message encoding fails * @throws MetadataProviderException in case metadata for required entities is not found */ protected SAMLMessageContext sendMessage(SAMLMessageContext samlContext, boolean sign, SAMLBinding binding) throws SAMLException, MetadataProviderException, MessageEncodingException { verifyContext(samlContext); if (sign) { Assert.notNull(samlContext.getLocalSigningCredential(), "Cannot sign outgoing message as no signing credential is set in the context"); samlContext.setOutboundSAMLMessageSigningCredential(samlContext.getLocalSigningCredential()); } MessageEncoder encoder = binding.getMessageEncoder(); encoder.encode(samlContext); return samlContext; }