Class SADParser.SADValidator
java.lang.Object
se.swedenconnect.opensaml.sweid.saml2.signservice.SADParser.SADValidator
- Enclosing class:
SADParser
A validator for verifying the SAD JWT.
- Author:
- Martin Lindström (martin@idsec.se)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionSADValidator
(X509Certificate... certificates) Constructor initializing the validator with a set of certificates that are to be used for JWT signature validation.SADValidator
(org.opensaml.saml.saml2.metadata.EntityDescriptor idpMetadata) Creates a SAD validator initialized with the IdPEntityDescriptor
(metadata) from which the IdP signing key/certificate will be read (needed for JWT signature validation).SADValidator
(MetadataProvider metadataProvider) Constructor creating a SAD validator initialized with aMetadataProvider
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setAllowedClockSkew
(Duration allowedClockSkew) Assigned the allowed clock skew.validate
(String sadJwt, String idpEntityID, String expectedRecipientEntityID, String expectedSubject, String expectedLoa, String sadRequestID, int expectedNoDocs, String signRequestID) Validates a SAD based on expected data.validate
(org.opensaml.saml.saml2.core.AuthnRequest authnRequest, org.opensaml.saml.saml2.core.Assertion assertion) A method that validates the SAD issued in anAssertion
based on theAuthnRequest
containing aSADRequest
.void
verifyJwtSignature
(String sadJwt, String idpEntityID) Verifies the signature on the supplied SAD JWT.
-
Field Details
-
DEFAULT_ALLOWED_CLOCK_SKEW
Default allowed clock skew.
-
-
Constructor Details
-
SADValidator
Constructor initializing the validator with a set of certificates that are to be used for JWT signature validation. These certificates are the IdP signing certificates obtained from the IdP metadata entry.- Parameters:
certificates
- certificate(s) to be used when verifying the JWT signature
-
SADValidator
Constructor creating a SAD validator initialized with aMetadataProvider
instance. During JWT signature validation the IdP signature certificate will be obtained from the IdP metadata entry held by the metadata provider.- Parameters:
metadataProvider
- metadata provider
-
SADValidator
public SADValidator(org.opensaml.saml.saml2.metadata.EntityDescriptor idpMetadata) Creates a SAD validator initialized with the IdPEntityDescriptor
(metadata) from which the IdP signing key/certificate will be read (needed for JWT signature validation).- Parameters:
idpMetadata
- the IdP metadata
-
-
Method Details
-
validate
public SAD validate(org.opensaml.saml.saml2.core.AuthnRequest authnRequest, org.opensaml.saml.saml2.core.Assertion assertion) throws SADValidationException, IllegalArgumentException A method that validates the SAD issued in anAssertion
based on theAuthnRequest
containing aSADRequest
.- Parameters:
authnRequest
- the AuthnRequest holding the SADRequestassertion
- the Assertion holding the sad attribute (as a encoded JWT)- Returns:
- a SAD object, or null if no SAD was requested (and issued)
- Throws:
SADValidationException
- for SAD validation errorsIllegalArgumentException
- if the supplied AuthnRequest does not contain a SADRequest extension, or is invalid by other means (e.g., missing LoA)- See Also:
-
validate
public SAD validate(String sadJwt, String idpEntityID, String expectedRecipientEntityID, String expectedSubject, String expectedLoa, String sadRequestID, int expectedNoDocs, String signRequestID) throws SADValidationException Validates a SAD based on expected data. If theAuthnRequest
and issuedAssertion
is available, the methodvalidate(AuthnRequest, Assertion)
is a better option.Note: It is assumed that the supplied
expectedSubject
parameter is a attribute value read from the assertion having the attribute name indicated in the 'attr' field of the SAD. If this attribute name is not known in advance, the SAD needs to be parsed (SADParser.parse(String)
) so that the 'attr' field can be read, and the correct attribute value be located from the assertion.- Parameters:
sadJwt
- the encoded SAD JWT (found in the sad attribute of a received assertion)idpEntityID
- the entityID of the issuing IdP (the issuer of the received assertion holding the sad attribute)expectedRecipientEntityID
- the entityID of the recipient (the signature service SP that issued the SADRequest)expectedSubject
- the expected subject name (user ID). See note aboveexpectedLoa
- the expected level of assurance to be found in the SAD (should be the LoA found in the assertion)sadRequestID
- the ID of the SADRequest extension that was sent to the IdPexpectedNoDocs
- expected number of documents (from the DocCount element of the SADRequest)signRequestID
- ID for the SignRequest that was included in the SADRequest- Returns:
- a SAD object
- Throws:
SADValidationException
- for validation errors
-
verifyJwtSignature
Verifies the signature on the supplied SAD JWT.- Parameters:
sadJwt
- the SAD JWTidpEntityID
- the entityID of the IdP that signed the JWT- Throws:
SADValidationException
- for signature validation errors
-
setAllowedClockSkew
Assigned the allowed clock skew. The default isDEFAULT_ALLOWED_CLOCK_SKEW
.- Parameters:
allowedClockSkew
- allowed clock skew
-