Class SAMLBindingSupport
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckRelayState(String relayState) Checks that the relay state is 80 bytes or less if it is not null.static voidcheckSAML1MessageType(boolean expectRequest, SAMLObject message) Evaluate a SAML 1 messageSAMLObjectas to whether it is the expected message type (request vs response).static voidcheckSAML2MessageType(boolean expectRequest, SAMLObject message) Evaluate a SAML 2 messageSAMLObjectas to whether it is the expected message type (request vs response).static intconvertSAML2ArtifactEndpointIndex(byte[] artifactEndpointIndex) Convert a 2-byte artifact endpoint index byte[] as typically used by SAML 2 artifact types to an integer, appropriate for use withIndexedEndpointimpls.static voidevaluateMessageSizeLimit(boolean enforcementEnabled, Integer messageSizeLimit, Integer messageSize) Evaluate message size limit using the supplied parameters.static voidevaluateMessageSizeLimit(boolean enforcementEnabled, Integer messageSizeLimit, Integer messageSize, String description) Evaluate message size limit using the supplied parameters.static StringgetActualReceiverEndpointURI(MessageContext messageContext) Extract the transport endpoint URI at which this message was received.static StringgetActualReceiverEndpointURI(MessageContext messageContext, HttpServletRequest request) Extract the transport endpoint URI at which this message was received.static IntegergetBase64Size(String encoded) Efficiently get the size of Base64-encoded data if it were decoded.static IntegergetDeflatedSize(String deflatedAndEncoded, boolean estimated, Float inflationFactor) Get the size of deflated and Base64-encoded data if it were decoded then inflated.static URIgetEndpointURL(MessageContext messageContext) Get the response URL from the relying party endpoint.static URIgetEndpointURLOrNull(MessageContext messageContext) Get the response URL from the relying party endpoint.static StringgetIntendedDestinationEndpointURI(MessageContext messageContext) Extract the message information which indicates to what receiver endpoint URI the SAML message was intended to be delivered.static MessageTypegetMessageType(HttpServletRequest httpRequest) Get the type of message being processed.static StringgetRelayState(MessageContext messageContext) Get the SAML protocol relay state from a message context.static booleanisIntendedDestinationEndpointURIRequired(MessageContext messageContext) Determine whether the binding in use requires the presence within the message of information indicating the intended message destination endpoint URI.static booleanisMessageSigned(MessageContext messageContext) Determine whether the SAML message represented by the message context is digitally signed.static booleanisMessageSigned(MessageContext messageContext, boolean presenceSatisfies) Determine whether the SAML message represented by the message context is digitally signed.static booleanisSigningCapableBinding(MessageContext messageContext) Determine whether the SAML binding to be used by the message context supports signatures at the binding layer.static voidsetRelayState(MessageContext messageContext, String relayState) Set the SAML protocol relay state on a message context.static voidsetSAML1ResponseRecipient(SAMLObject outboundMessage, String endpointURL) Sets the destination attribute on the outbound message if it is aResponseAbstractTypemessage.static voidsetSAML2Destination(SAMLObject outboundMessage, String endpointURL) Sets the destination attribute on an outbound message if it is either aRequestAbstractTypeor aStatusResponseTypemessage.static voidvalidateMessageTypeValues(HttpServletRequest httpRequest, MessageType messageType) Validate that an HTTP request has a valid number of values for the specified message type.
-
Field Details
-
LOG
@Nonnull private static final org.slf4j.Logger LOGLogger.
-
-
Constructor Details
-
SAMLBindingSupport
private SAMLBindingSupport()Constructor.
-
-
Method Details
-
getRelayState
Get the SAML protocol relay state from a message context.- Parameters:
messageContext- the message context on which to operate- Returns:
- the relay state or null
-
setRelayState
public static void setRelayState(@Nonnull MessageContext messageContext, @Nullable String relayState) Set the SAML protocol relay state on a message context.- Parameters:
messageContext- the message context on which to operaterelayState- the relay state to set
-
checkRelayState
Checks that the relay state is 80 bytes or less if it is not null.- Parameters:
relayState- relay state to check- Returns:
- true if the relay state is not empty and is less than 80 bytes
-
getEndpointURLOrNull
Get the response URL from the relying party endpoint. If the SAML message is a response and the relying party endpoint contains a response location then that location is returned otherwise the normal endpoint location is returned.Instead of raising an exception, this variant returns null in the event of an inability to identify a URL to return.
- Parameters:
messageContext- current message context- Returns:
- response URL from the relying party endpoint or null
- Since:
- 5.2.0
-
getEndpointURL
@Nonnull public static URI getEndpointURL(@Nonnull MessageContext messageContext) throws BindingException Get the response URL from the relying party endpoint. If the SAML message is a response and the relying party endpoint contains a response location then that location is returned otherwise the normal endpoint location is returned.- Parameters:
messageContext- current message context- Returns:
- response URL from the relying party endpoint
- Throws:
BindingException- throw if no relying party endpoint is available
-
setSAML1ResponseRecipient
public static void setSAML1ResponseRecipient(@Nonnull SAMLObject outboundMessage, @Nonnull @NotEmpty String endpointURL) Sets the destination attribute on the outbound message if it is aResponseAbstractTypemessage.- Parameters:
outboundMessage- outbound SAML messageendpointURL- destination endpoint
-
setSAML2Destination
public static void setSAML2Destination(@Nonnull SAMLObject outboundMessage, @Nonnull @NotEmpty String endpointURL) Sets the destination attribute on an outbound message if it is either aRequestAbstractTypeor aStatusResponseTypemessage.- Parameters:
outboundMessage- outbound SAML messageendpointURL- destination endpoint
-
isMessageSigned
Determine whether the SAML message represented by the message context is digitally signed.First the SAML protocol message is examined as to whether an XML signature is present at the DOM level; if yes return true. Finally, the presence of a binding signature is evaluated by looking at
SAMLBindingContext.hasBindingSignature().- Parameters:
messageContext- current message context- Returns:
- true if the message is considered to be digitally signed, false otherwise
-
isMessageSigned
public static boolean isMessageSigned(@Nonnull MessageContext messageContext, boolean presenceSatisfies) Determine whether the SAML message represented by the message context is digitally signed.First the SAML protocol message is examined as to whether an XML signature is present at the DOM level; if yes return true. Next if
presenceSatisfiesis true, thenSignableXMLObject.getSignature()is evaluated for a non-null value; if yes return true. Finally, the presence of a binding signature is evaluated by looking atSAMLBindingContext.hasBindingSignature().- Parameters:
messageContext- current message contextpresenceSatisfies- whether the presence of a non-nullSignaturemember satisfies the evaluation- Returns:
- true if the message is considered to be digitally signed, false otherwise
-
isSigningCapableBinding
Determine whether the SAML binding to be used by the message context supports signatures at the binding layer.The capability of the binding is determined by extracting a
BindingDescriptorfrom aSAMLBindingContext.- Parameters:
messageContext- current message context- Returns:
- true if the message is considered to be digitally signed, false otherwise
-
isIntendedDestinationEndpointURIRequired
public static boolean isIntendedDestinationEndpointURIRequired(@Nonnull MessageContext messageContext) Determine whether the binding in use requires the presence within the message of information indicating the intended message destination endpoint URI.- Parameters:
messageContext- current SAML message context- Returns:
- true if the intended message destination endpoint is required, false if not
-
getIntendedDestinationEndpointURI
@Nullable public static String getIntendedDestinationEndpointURI(@Nonnull MessageContext messageContext) throws MessageException Extract the message information which indicates to what receiver endpoint URI the SAML message was intended to be delivered.- Parameters:
messageContext- the SAML message context being processed- Returns:
- the value of the intended destination endpoint URI, or null if not present or empty
- Throws:
MessageException- thrown if the message is not an instance of SAML message that could be processed by the decoder
-
getActualReceiverEndpointURI
@Nonnull public static String getActualReceiverEndpointURI(@Nonnull MessageContext messageContext, @Nonnull HttpServletRequest request) throws MessageException Extract the transport endpoint URI at which this message was received.- Parameters:
messageContext- current message contextrequest- the HttpServletRequest being evaluated- Returns:
- string representing the transport endpoint URI at which the current message was received
- Throws:
MessageException- thrown if the endpoint can not be looked up from the message context and converted to a string representation
-
getActualReceiverEndpointURI
@Nullable public static String getActualReceiverEndpointURI(@Nonnull MessageContext messageContext) throws MessageException Extract the transport endpoint URI at which this message was received.- Parameters:
messageContext- current message context- Returns:
- string representing the transport endpoint URI at which the current message was received
- Throws:
MessageException- thrown if the endpoint can not be looked up from the message context and converted to a string representation- Since:
- 5.2.0
-
convertSAML2ArtifactEndpointIndex
public static int convertSAML2ArtifactEndpointIndex(@Nonnull byte[] artifactEndpointIndex) Convert a 2-byte artifact endpoint index byte[] as typically used by SAML 2 artifact types to an integer, appropriate for use withIndexedEndpointimpls.The max input value supported is 0x7FFF (32767), which is the largest possible unsigned 16 bit value. This should be more than sufficient for typical SAML cases.
- Parameters:
artifactEndpointIndex- the endpoint index byte array, must have length == 2, and big endian byte order.- Returns:
- the convert integer value
-
checkSAML1MessageType
public static void checkSAML1MessageType(boolean expectRequest, @Nonnull SAMLObject message) throws MessageDecodingException Evaluate a SAML 1 messageSAMLObjectas to whether it is the expected message type (request vs response).- Parameters:
expectRequest- true if a SAML 1 request is expected (an instance ofRequestAbstractType, false if a SAML 1 response is expected (an instance ofResponseAbstractTypemessage- the message to evaluate- Throws:
MessageDecodingException- if the message being evaluated is not the expected type
-
checkSAML2MessageType
public static void checkSAML2MessageType(boolean expectRequest, @Nonnull SAMLObject message) throws MessageDecodingException Evaluate a SAML 2 messageSAMLObjectas to whether it is the expected message type (request vs response).- Parameters:
expectRequest- true if a SAML 2 request is expected (an instance ofRequestAbstractType, false if a SAML 2 response is expected (an instance ofResponseAbstractTypemessage- the message to evaluate- Throws:
MessageDecodingException- if the message being evaluated is not the expected type
-
getMessageType
Get the type of message being processed.- Parameters:
httpRequest- the HTTP request- Returns:
- the message type, or null if the HTTP request is malformed with respect to SAML message parameters
-
validateMessageTypeValues
public static void validateMessageTypeValues(@Nonnull HttpServletRequest httpRequest, @Nonnull MessageType messageType) throws MessageDecodingException Validate that an HTTP request has a valid number of values for the specified message type.- Parameters:
httpRequest- the HTTP requestmessageType- the message type- Throws:
MessageDecodingException- if the HTTP request has an invalid number of values for the specified message type
-
evaluateMessageSizeLimit
public static void evaluateMessageSizeLimit(boolean enforcementEnabled, @Nullable Integer messageSizeLimit, @Nullable Integer messageSize) throws MessageDecodingException Evaluate message size limit using the supplied parameters.- Parameters:
enforcementEnabled- whether enforcement of message size limit is enabledmessageSizeLimit- the message size limitmessageSize- the received message size- Throws:
MessageDecodingException- if evaluation is enabled and either 1) message size exceeds the limit or 2) the message size or limit is null
-
evaluateMessageSizeLimit
public static void evaluateMessageSizeLimit(boolean enforcementEnabled, @Nullable Integer messageSizeLimit, @Nullable Integer messageSize, @Nullable String description) throws MessageDecodingException Evaluate message size limit using the supplied parameters.- Parameters:
enforcementEnabled- whether enforcement of message size limit is enabledmessageSizeLimit- the message size limitmessageSize- the received message sizedescription- description of what is being evaluated- Throws:
MessageDecodingException- if evaluation is enabled and either 1) message size exceeds the limit or 2) the message size or limit is null
-
getBase64Size
Efficiently get the size of Base64-encoded data if it were decoded.- Parameters:
encoded- the Base64-encoded data- Returns:
- the size of the data when decoded, in bytes
-
getDeflatedSize
@Nonnull public static Integer getDeflatedSize(@Nullable String deflatedAndEncoded, boolean estimated, @Nullable Float inflationFactor) throws MessageDecodingException Get the size of deflated and Base64-encoded data if it were decoded then inflated.If
estimatedis true, then the size is estimated efficiently by simply applying the specifiedinflationFactoragainst the result ofgetBase64Size(String). This is very fast but the accuracy will depend entirely on theinflationFactorthat is used, so it must be chosen based on knowledge of the compressibility of the data.If
estimatedis false, then the encoded data is actually Base64-decoded and then inflated and the size is the length of the resultingbyte[]. This is computationally more expensive, but will give an exact size.- Parameters:
deflatedAndEncoded- the deflated and Base64-encoded dataestimated- flag indicating whether an exact or an estimated value should be determinedinflationFactor- for estimated mode the multiplier applied against the Base64-decoded size. Should be greater than 1.0- Returns:
- the size of the data when Base64-decoded and inflated, in bytes
- Throws:
MessageDecodingException- if estimated was true and inflationFactor is null, or if there was a fatal error during Base64-decoding or inflation
-