Skip to content

Commit

Permalink
fix: Assertion and Response supports serialization in events
Browse files Browse the repository at this point in the history
[IS-70]
  • Loading branch information
martin-lindstrom committed Apr 24, 2024
1 parent 6efbb1d commit c7f3250
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import org.opensaml.saml.saml2.core.Response;
import org.opensaml.saml.saml2.core.Status;

import se.swedenconnect.opensaml.common.utils.SerializableOpenSamlObject;
import se.swedenconnect.spring.saml.idp.Saml2IdentityProviderVersion;

/**
* An event that signals that a SAML error response is being sent.
*
*
* @author Martin Lindström
*/
public class Saml2ErrorResponseEvent extends AbstractSaml2IdpEvent {
Expand All @@ -34,27 +35,28 @@ public class Saml2ErrorResponseEvent extends AbstractSaml2IdpEvent {

/**
* Constructor.
*
*
* @param response the SAML response
* @param spEntityId the entityID of the SP that we are sending the response to
*/
public Saml2ErrorResponseEvent(final Response response, final String spEntityId) {
super(response);
super(new SerializableOpenSamlObject<Response>(response));
this.spEntityId = spEntityId;
}

/**
* Gets the SAML response.
*
*
* @return the {@link Response}
*/
@SuppressWarnings("unchecked")
public Response getResponse() {
return Response.class.cast(this.getSource());
return ((SerializableOpenSamlObject<Response>) this.getSource()).get();
}

/**
* Gets the entityID of the SP that we are sending the response to.
*
*
* @return SP SAML entityID
*/
public String getSpEntityId() {
Expand All @@ -63,7 +65,7 @@ public String getSpEntityId() {

/**
* Gets the SAML {@link Status} that was sent.
*
*
* @return SAML {@link Status}
*/
public Status getStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,59 @@
import org.opensaml.saml.saml2.core.Assertion;
import org.opensaml.saml.saml2.core.Response;

import se.swedenconnect.opensaml.common.utils.SerializableOpenSamlObject;
import se.swedenconnect.spring.saml.idp.Saml2IdentityProviderVersion;

/**
* An event that signals that a successful SAML response is being sent.
*
*
* @author Martin Lindström
*/
public class Saml2SuccessResponseEvent extends AbstractSaml2IdpEvent {

private static final long serialVersionUID = Saml2IdentityProviderVersion.SERIAL_VERSION_UID;

/** The issued SAML assertion (un-encrypted). */
private final Assertion assertion;
private final SerializableOpenSamlObject<Assertion> assertion;

/** The entityID of the SP that we are sending the response to. */
private String spEntityId;

/**
* Constructor.
*
*
* @param response the SAML response
* @param assertion the SAML Assertion (before being encrypted)
* @param spEntityId the entityID of the SP that we are sending the response to
*/
public Saml2SuccessResponseEvent(final Response response, final Assertion assertion, final String spEntityId) {
super(response);
this.assertion = assertion;
super(new SerializableOpenSamlObject<Response>(response));
this.assertion = new SerializableOpenSamlObject<Assertion>(assertion);
this.spEntityId = spEntityId;
}

/**
* Gets the SAML response.
*
*
* @return the {@link Response}
*/
@SuppressWarnings("unchecked")
public Response getResponse() {
return Response.class.cast(this.getSource());
return ((SerializableOpenSamlObject<Response>) this.getSource()).get();
}

/**
* Gets the (un-encrypted) SAML {@link Assertion}
*
*
* @return an {@link Assertion}
*/
public Assertion getAssertion() {
return this.assertion;
return this.assertion.get();
}

/**
* Gets the entityID of the SP that we are sending the response to.
*
*
* @return SP SAML entityID
*/
public String getSpEntityId() {
Expand Down

0 comments on commit c7f3250

Please sign in to comment.