Class Saml2ResponseValidator

java.lang.Object
com.codename1.backend.security.saml2.Saml2ResponseValidator

public final class Saml2ResponseValidator extends Object

Decides whether a SAML 2.0 Response an identity provider posted signs a user in, following the Web Browser SSO profile (SAML 2.0 profiles, section 4.1.4) and Spring Security's defaults.

A response is accepted only when all of this holds:

  • It is a samlp:Response of version 2.0 with a Success status, addressed (Destination, when present) to this server's ACS address and issued (when it names an issuer) by the registration's identity provider.
  • It answers the AuthnRequest this browser sent (InResponseTo), or it is unsolicited and answers nothing. One that names a request when none was sent from this browser is refused.
  • It holds exactly one Assertion. An EncryptedAssertion is refused as unsupported: there is no RSA decryption in this runtime.
  • The response, the assertion, or both, carry a signature that verifies under XmlSignature's rules with one of the registration's certificates. A signature that is present and does not verify refuses the response even when the other one does.
  • The assertion is issued by the identity provider, its Conditions hold now (within the clock skew), and every AudienceRestriction names this server's entity ID.
  • Its subject has a bearer SubjectConfirmation whose data is for this ACS address, unexpired, and for this request when it names one.
  • It has an AuthnStatement.
  • Its ID has not been accepted before (a replay), for as long as it is valid.

The replay cache is per process. Behind a load balancer the same assertion could be accepted once by each server: keep the assertion lifetime short at the identity provider, or route a browser to one server.

  • Constructor Details

    • Saml2ResponseValidator

      public Saml2ResponseValidator()
  • Method Details

    • validate

      public Saml2AuthenticatedPrincipal validate(byte[] response, RelyingPartyRegistration registration, String acsLocation, String entityId, String inResponseTo, long now)
      Checks response, the decoded XML of a SAMLResponse parameter.
      Parameters:
      acsLocation - this server's ACS address for the registration, resolved
      entityId - this server's entity ID for the registration, resolved
      inResponseTo - the ID of the AuthnRequest this browser sent; null when it sent none
      now - the time to judge validity at, in milliseconds
      Returns:
      who signed in
      Throws:
      Saml2AuthenticationException - when the response is refused