Class ResponseProcessorImpl
java.lang.Object
se.swedenconnect.opensaml.saml2.response.ResponseProcessorImpl
- All Implemented Interfaces:
Component,InitializableComponent,ResponseProcessor
public class ResponseProcessorImpl
extends Object
implements ResponseProcessor, InitializableComponent
Response processor for SAML Response messages.
Note that initialize() must be invoked before the bean can be used.
- Author:
- Martin Lindström (martin.lindstrom@litsec.se)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AssertionValidatorThe assertion validator.protected SAMLObjectDecrypterThe decrypter instance.protected MessageReplayCheckerThe replay checker.protected MetadataCredentialResolverUsed to locate certificates from the IdP metadata.protected MetadataResolverMetadata resolver for finding IdP and SP metadata.protected booleanDo we require assertions to be encrypted?protected ResponseValidationSettingsStatic response validation settings.protected ResponseValidatorThe response validator.protected SecurityConfigurationCustom security configuration.protected SignaturePrevalidatorValidator for checking that a Signature is correct with respect to the standards.protected SignatureTrustEngineThe signature trust engine to be used when validating signatures. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CriteriaSetbuildSignatureValidationCriteriaSet(IDPSSODescriptor descriptor) Builds aCriteriaSetfor use with signature validation.protected SignatureValidationParametersCriterionBuilds a signature validation criterion based on the installed security configuration.protected final voidHelper for a setter method to check the standard preconditions.protected AssertionValidatorcreateAssertionValidator(SignatureTrustEngine signatureTrustEngine, SignaturePrevalidator signatureProfileValidator) Sets up the assertion validator.protected ResponseValidatorcreateResponseValidator(SignatureTrustEngine signatureTrustEngine, SignaturePrevalidator signatureProfileValidator) Sets up the response validator.protected ResponsedecodeResponse(String samlResponse) Decodes the received SAML response message into aResponseobject.protected AbstractAssertionValidationParametersBuilder<?> protected EntityDescriptorgetMetadata(String entityID, QName role) Gets the metadata for the given entityID and role (type).protected EntityDescriptorgetSpMetadata(String entityID) Gets the SAML metadata for a given SP.voidbooleanprocessSamlResponse(String samlResponse, String relayState, ResponseProcessingInput input, ValidationContext validationContext) Processes a SAML response including signature validation and assertion decryption.voidsetDecrypter(SAMLObjectDecrypter decrypter) Assigns the decrypter instance.voidsetMessageReplayChecker(MessageReplayChecker messageReplayChecker) Assigns the message replay checker to use.voidsetMetadataResolver(MetadataResolver metadataResolver) Assigns the metadata resolver to use.voidsetRequireEncryptedAssertions(boolean requireEncryptedAssertions) Assigns whether we require assertions to be encrypted?voidsetResponseValidationSettings(ResponseValidationSettings responseValidationSettings) Assigns the response validation settings.voidsetSecurityConfiguration(SecurityConfiguration securityConfiguration) Assigns a customSecurityConfigurationfor the processor.protected voidvalidateAssertion(Assertion assertion, Response response, ResponseProcessingInput input, EntityDescriptor idpMetadata, ValidationContext validationContext) Validates the assertion.protected voidvalidateRelayState(Response response, String relayState, ResponseProcessingInput input) Validates the received relay state matches what we sent.protected voidvalidateResponse(Response response, String relayState, ResponseProcessingInput input, EntityDescriptor idpMetadata, ValidationContext validationContext) Validates the response including its signature.
-
Field Details
-
metadataResolver
Metadata resolver for finding IdP and SP metadata. -
decrypter
The decrypter instance. -
messageReplayChecker
The replay checker. -
metadataCredentialResolver
Used to locate certificates from the IdP metadata. -
signatureTrustEngine
The signature trust engine to be used when validating signatures. -
signatureProfileValidator
Validator for checking that a Signature is correct with respect to the standards. -
responseValidator
The response validator. -
assertionValidator
The assertion validator. -
responseValidationSettings
Static response validation settings. -
requireEncryptedAssertions
protected boolean requireEncryptedAssertionsDo we require assertions to be encrypted? The default istrue. -
securityConfiguration
Custom security configuration.
-
-
Constructor Details
-
ResponseProcessorImpl
public ResponseProcessorImpl()
-
-
Method Details
-
processSamlResponse
public ResponseProcessingResult processSamlResponse(String samlResponse, String relayState, ResponseProcessingInput input, ValidationContext validationContext) throws ResponseStatusErrorException, ResponseProcessingException Processes a SAML response including signature validation and assertion decryption.- Specified by:
processSamlResponsein interfaceResponseProcessor- Parameters:
samlResponse- the base64 encoded SAML responserelayState- the received relay stateinput- the processing inputvalidationContext- optional validation context for controlling the validation and assertion validation process- Returns:
- a result
- Throws:
ResponseStatusErrorException- if the response indicates a non-successfulStatusResponseProcessingException- for other processing errors
-
initialize
- Specified by:
initializein interfaceInitializableComponent- Throws:
ComponentInitializationException
-
isInitialized
public boolean isInitialized()- Specified by:
isInitializedin interfaceInitializableComponent
-
createResponseValidator
protected ResponseValidator createResponseValidator(SignatureTrustEngine signatureTrustEngine, SignaturePrevalidator signatureProfileValidator) Sets up the response validator.The default implementation creates a
ResponseValidatorinstance. For use within the Swedish eID framework subclasses should create aSwedishEidResponseValidatorinstance, see the swedish-eid-opensaml library (https://github.com/litsec/swedish-eid-opensaml).- Parameters:
signatureTrustEngine- the signature trust engine to be used when validating signaturessignatureProfileValidator- validator for checking that a Signature is correct with respect to the standards- Returns:
- the created response validator
-
createAssertionValidator
protected AssertionValidator createAssertionValidator(SignatureTrustEngine signatureTrustEngine, SignaturePrevalidator signatureProfileValidator) Sets up the assertion validator.The default implementation creates a
AssertionValidatorinstance. For use within the Swedish eID framework subclasses should create aSwedishEidAssertionValidatorinstance, see the opensaml-swedish-eid library (https://github.com/swedenconnect/opensaml-swedish-eid).- Parameters:
signatureTrustEngine- the signature trust engine to be used when validating signaturessignatureProfileValidator- validator for checking that a Signature is correct with respect to the standards- Returns:
- the created assertion validator
-
getAssertionValidationParametersBuilder
-
decodeResponse
Decodes the received SAML response message into aResponseobject.- Parameters:
samlResponse- the Base64 encoded SAML response- Returns:
- a
Responseobject - Throws:
ResponseProcessingException- for decoding errors
-
validateResponse
protected void validateResponse(Response response, String relayState, ResponseProcessingInput input, EntityDescriptor idpMetadata, ValidationContext validationContext) throws ResponseValidationException Validates the response including its signature.- Parameters:
response- the response to verifyrelayState- the relay state that was receivedinput- the processing inputidpMetadata- the IdP metadatavalidationContext- optional validation context- Throws:
ResponseValidationException- for validation errors
-
validateRelayState
protected void validateRelayState(Response response, String relayState, ResponseProcessingInput input) throws ResponseValidationException Validates the received relay state matches what we sent.- Parameters:
response- the responserelayState- the received relay stateinput- the response processing input- Throws:
ResponseValidationException- for validation errors
-
validateAssertion
protected void validateAssertion(Assertion assertion, Response response, ResponseProcessingInput input, EntityDescriptor idpMetadata, ValidationContext validationContext) throws ResponseValidationException Validates the assertion.- Parameters:
assertion- the assertion to validateresponse- the response that contained the assertioninput- the processing inputidpMetadata- the IdP metadatvalidationContext- optional validation context- Throws:
ResponseValidationException- for validation errors
-
buildSignatureValidationCriteriaSet
Builds aCriteriaSetfor use with signature validation.- Parameters:
descriptor- the IDP SSO descriptor- Returns:
- a
CriteriaSet
-
buildSignatureValidationParametersCriterion
Builds a signature validation criterion based on the installed security configuration. This is used during validation of the signature of a response or assertion.- Returns:
- a {link SignatureValidationParametersCriterion}
-
getMetadata
Gets the metadata for the given entityID and role (type).- Parameters:
entityID- the entity IDrole- the role- Returns:
- the entity descriptor or null if no metadata is found
-
getSpMetadata
Gets the SAML metadata for a given SP.- Parameters:
entityID- the SP entityID- Returns:
- the SP metadata or null if none is found
-
setMetadataResolver
Assigns the metadata resolver to use.- Parameters:
metadataResolver- the metadata resolver
-
setDecrypter
Assigns the decrypter instance.- Parameters:
decrypter- the decrypter
-
setMessageReplayChecker
Assigns the message replay checker to use.- Parameters:
messageReplayChecker- message replay checker
-
setResponseValidationSettings
Assigns the response validation settings.- Parameters:
responseValidationSettings- validation settings
-
setRequireEncryptedAssertions
public void setRequireEncryptedAssertions(boolean requireEncryptedAssertions) Assigns whether we require assertions to be encrypted? The default istrue.- Parameters:
requireEncryptedAssertions- boolean
-
setSecurityConfiguration
Assigns a customSecurityConfigurationfor the processor.- Parameters:
securityConfiguration- customSecurityConfiguration
-
checkSetterPreconditions
protected final void checkSetterPreconditions()Helper for a setter method to check the standard preconditions.
-