Class Saml2ResponseBuilder
java.lang.Object
se.swedenconnect.spring.saml.idp.response.Saml2ResponseBuilder
Builds a SAML
Response
message.- Author:
- Martin Lindström
-
Constructor Summary
ConstructorDescriptionSaml2ResponseBuilder
(String idpEntityId, PkiCredential signingCredential, Saml2IdpEventPublisher eventPublisher) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionorg.opensaml.saml.saml2.core.Response
buildErrorResponse
(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Status errorStatus) Given an errorStatus
object, the method builds aResponse
object indicating the error and signs it.org.opensaml.saml.saml2.core.Response
buildErrorResponse
(Saml2ResponseAttributes responseAttributes, Saml2ErrorStatusException error) Given aSaml2ErrorStatusException
exception, the method builds aResponse
object indicating the errorStatus
given by the exception and signs it.org.opensaml.saml.saml2.core.Response
buildResponse
(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Assertion assertion) Given anAssertion
, the method builds aResponse
object including the suppliedAssertion
.protected org.opensaml.saml.saml2.core.Response
createResponse
(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Status status) Creates aResponse
object with the basic attributesID
,Destination
andInResponseTo
as well as theIssuer
element and the suppliedStatus
element.protected org.opensaml.saml.saml2.core.EncryptedAssertion
encryptAssertion
(org.opensaml.saml.saml2.core.Assertion assertion, org.opensaml.saml.saml2.metadata.EntityDescriptor peerMetadata) Encrypts the suppliedAssertion
.boolean
Tells whether assertions are encrypted.void
setEncryptAssertions
(boolean encryptAssertions) Assigns whether assertions should be encrypted.void
setIdGenerator
(Saml2MessageIDGenerator idGenerator) Assigns a custom ID generator.void
setMessageSource
(MessageSource messageSource) Assigns a message source for resolving error messages.void
setResponseCustomizer
(org.springframework.security.config.Customizer<org.opensaml.saml.saml2.core.Response> responseCustomizer) By assigning aCustomizer
theResponse
object that is built can be modified.protected void
signResponse
(org.opensaml.saml.saml2.core.Response samlResponse, org.opensaml.saml.saml2.metadata.EntityDescriptor peerMetadata) Signs theResponse
message.
-
Constructor Details
-
Saml2ResponseBuilder
public Saml2ResponseBuilder(String idpEntityId, PkiCredential signingCredential, Saml2IdpEventPublisher eventPublisher) Constructor.- Parameters:
idpEntityId
- the entityID for the IdPsigningCredential
- the IdP signing credential (for signing ofResponse
objects)eventPublisher
- the event publisher
-
-
Method Details
-
buildErrorResponse
public org.opensaml.saml.saml2.core.Response buildErrorResponse(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Status errorStatus) Given an errorStatus
object, the method builds aResponse
object indicating the error and signs it.- Parameters:
responseAttributes
- the response attributes needed for building theResponse
objecterrorStatus
- the SAML status object- Returns:
- a
Response
object - Throws:
UnrecoverableSaml2IdpException
- for errors
-
buildErrorResponse
public org.opensaml.saml.saml2.core.Response buildErrorResponse(Saml2ResponseAttributes responseAttributes, Saml2ErrorStatusException error) throws UnrecoverableSaml2IdpException Given aSaml2ErrorStatusException
exception, the method builds aResponse
object indicating the errorStatus
given by the exception and signs it.- Parameters:
responseAttributes
- the response attributes needed for building theResponse
objecterror
- the SAML error- Returns:
- a
Response
object - Throws:
UnrecoverableSaml2IdpException
- for errors
-
buildResponse
public org.opensaml.saml.saml2.core.Response buildResponse(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Assertion assertion) throws UnrecoverableSaml2IdpException Given anAssertion
, the method builds aResponse
object including the suppliedAssertion
. If the Identity Provider is configured to encrypt assertions, the method encrypts the suppliedAssertion
for the recipient given bySaml2ResponseAttributes.getPeerMetadata()
.- Parameters:
responseAttributes
- the response attributes needed for building theResponse
objectassertion
- the SAMLAssertion
- Returns:
- a
Response
object - Throws:
UnrecoverableSaml2IdpException
- for errors
-
createResponse
protected org.opensaml.saml.saml2.core.Response createResponse(Saml2ResponseAttributes responseAttributes, org.opensaml.saml.saml2.core.Status status) throws UnrecoverableSaml2IdpException Creates aResponse
object with the basic attributesID
,Destination
andInResponseTo
as well as theIssuer
element and the suppliedStatus
element.- Parameters:
responseAttributes
- the response attributes needed for building theResponse
objectstatus
- the SAMLStatus
object- Returns:
- a
Response
object - Throws:
UnrecoverableSaml2IdpException
- for errors
-
signResponse
protected void signResponse(org.opensaml.saml.saml2.core.Response samlResponse, org.opensaml.saml.saml2.metadata.EntityDescriptor peerMetadata) throws UnrecoverableSaml2IdpException Signs theResponse
message.- Parameters:
samlResponse
- the object to signpeerMetadata
- the peer metadata (may be used to select signing algorithm)- Throws:
UnrecoverableSaml2IdpException
- for signing errors
-
encryptAssertion
protected org.opensaml.saml.saml2.core.EncryptedAssertion encryptAssertion(org.opensaml.saml.saml2.core.Assertion assertion, org.opensaml.saml.saml2.metadata.EntityDescriptor peerMetadata) throws UnrecoverableSaml2IdpException Encrypts the suppliedAssertion
.- Parameters:
assertion
- the assertion to encryptpeerMetadata
- the metadata for the peer to whom we encrypt for- Returns:
- an
EncryptedAssertion
- Throws:
UnrecoverableSaml2IdpException
- for unrecoverable errors
-
isEncryptAssertions
public boolean isEncryptAssertions()Tells whether assertions are encrypted.- Returns:
true
if assertions are encrypted, andfalse
otherwise
-
setEncryptAssertions
public void setEncryptAssertions(boolean encryptAssertions) Assigns whether assertions should be encrypted.- Parameters:
encryptAssertions
- whether assertions should be encrypted
-
setIdGenerator
Assigns a custom ID generator. The default isDefaultSaml2MessageIDGenerator
.- Parameters:
idGenerator
- the ID generator
-
setResponseCustomizer
public void setResponseCustomizer(org.springframework.security.config.Customizer<org.opensaml.saml.saml2.core.Response> responseCustomizer) By assigning aCustomizer
theResponse
object that is built can be modified. The customizer is invoked when theResponse
object has been completely built, but before it is signed.- Parameters:
responseCustomizer
- aCustomizer
-
setMessageSource
Assigns a message source for resolving error messages.- Parameters:
messageSource
- theMessageSource
-