/** * Finds binding with the given name. * * @param bindingName name * @return binding * @throws SAMLException in case binding can't be found */ protected SAMLBinding getBinding(String bindingName) throws SAMLException { for (SAMLBinding binding : bindings) { if (binding.getBindingURI().equals(bindingName)) { return binding; } } throw new SAMLException("Binding " + bindingName + " is not available, please check your configuration"); }
/** * Analyzes the transport object and returns the first binding capable of sending/extracting a SAML message from to/from it. * In case no binding is found SAMLException is thrown. * * @param transport transport type to get binding for * @return decoder * @throws SAMLException in case no suitable decoder is found for given request */ protected SAMLBinding getBinding(InTransport transport) throws SAMLException { for (SAMLBinding binding : bindings) { if (binding.supports(transport)) { return binding; } } throw new SAMLException("Unsupported request"); }
log.debug("Retrieving message using binding {}", binding.getBindingURI()); samlContext.setInboundSAMLBinding(binding.getBindingURI()); MessageDecoder decoder = binding.getMessageDecoder(); decoder.decode(samlContext);
/** * Populates security policy to use for the incoming message and sets it in the samlContext as securityPolicyResolver. * SecurityPolicy is populated using getSecurityPolicy method of the used binding. * * @param samlContext saml context to set the policy to * @param binding binding used to retrieve the message */ protected void populateSecurityPolicy(SAMLMessageContext samlContext, SAMLBinding binding) { SecurityPolicy policy = new BasicSecurityPolicy(); binding.getSecurityPolicy(policy.getPolicyRules(), samlContext); StaticSecurityPolicyResolver resolver = new StaticSecurityPolicyResolver(policy); samlContext.setSecurityPolicyResolver(resolver); }
/** * 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; }