Skip to content

Commit

Permalink
Merge pull request #14 from swedenconnect/bugfix/IS-13-type-audit
Browse files Browse the repository at this point in the history
IS-13 Fixed bug in audit logging
  • Loading branch information
martin-lindstrom committed Aug 28, 2023
2 parents c24ebb1 + cae0c65 commit f4af471
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Spring Boot Autoconfigure module</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<packaging>pom</packaging>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>

<name>Sweden Connect :: Spring SAML Identity Provider :: Parent POM</name>
<description>Parent POM for Spring SAML Identity Provider libraries</description>
Expand Down
2 changes: 1 addition & 1 deletion saml-identity-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Core Library</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/**
* Audit event for creating event objects for the SAML IdP.
*
*
* @author Martin Lindström
*/
@JsonInclude(Include.NON_EMPTY)
Expand All @@ -48,7 +48,7 @@ public class Saml2AuditEvent extends AuditEvent {

/**
* Constructor.
*
*
* @param type the type of audit event
* @param timestamp the timestamp (in millis since epoch)
* @param spEntityId the entityID of the requesting SP
Expand All @@ -57,13 +57,13 @@ public class Saml2AuditEvent extends AuditEvent {
*/
public Saml2AuditEvent(final String type, final long timestamp, final String spEntityId, final String authnRequestId,
final Saml2AuditData... data) {
super(Instant.ofEpochMilli(timestamp), type, Optional.ofNullable(spEntityId).orElseGet(() -> UNKNOWN_SP),
super(Instant.ofEpochMilli(timestamp), Optional.ofNullable(spEntityId).orElseGet(() -> UNKNOWN_SP), type,
buildData(spEntityId, authnRequestId, data));
}

/**
* Builds a {@link Map} given the supplied audit data
*
*
* @param spEntityId the entityID of the requesting SP
* @param authnRequestId the ID of the {@code AuthnRequest}
* @param data audit data
Expand All @@ -87,7 +87,7 @@ private static Map<String, Object> buildData(
/**
* Gets a string suitable to include in log entries. It does not dump the entire audit data that can contain sensible
* data (that should not be present in proceess logs).
*
*
* @return a log string
*/
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import se.swedenconnect.spring.saml.idp.OpenSamlTestBase;
import se.swedenconnect.spring.saml.idp.attributes.UserAttribute;
import se.swedenconnect.spring.saml.idp.audit.Saml2AuditEvent;
import se.swedenconnect.spring.saml.idp.audit.Saml2AuditEvents;
import se.swedenconnect.spring.saml.idp.authentication.Saml2UserAuthentication;
import se.swedenconnect.spring.saml.idp.authentication.Saml2UserAuthenticationInputToken;
import se.swedenconnect.spring.saml.idp.authentication.Saml2UserDetails;
Expand Down Expand Up @@ -109,7 +110,7 @@ public class AuthenticationIntegrationTest extends OpenSamlTestBase {

@Autowired
private Saml2EventListener eventListener;

@Autowired
private AuditEventListener auditListener;

Expand Down Expand Up @@ -176,7 +177,11 @@ public String getPreferredBinding() {
Assertions.assertTrue(this.eventListener.getEvents().get(3) instanceof Saml2SuccessResponseEvent);

// Auditing
Assertions.assertEquals(4, this.auditListener.getEvents().size());
Assertions.assertEquals(4, this.auditListener.getEvents().size());
Assertions.assertEquals(Saml2AuditEvents.SAML2_AUDIT_REQUEST_RECEIVED, this.auditListener.getEvents().get(0).getType());
Assertions.assertEquals(Saml2AuditEvents.SAML2_AUDIT_BEFORE_USER_AUTHN, this.auditListener.getEvents().get(1).getType());
Assertions.assertEquals(Saml2AuditEvents.SAML2_AUDIT_AFTER_USER_AUTHN, this.auditListener.getEvents().get(2).getType());
Assertions.assertEquals(Saml2AuditEvents.SAML2_AUDIT_SUCCESSFUL_RESPONSE, this.auditListener.getEvents().get(3).getType());
}

@Test
Expand Down Expand Up @@ -266,9 +271,9 @@ public AuthnRequestCustomizer getAuthnRequestCustomizer() {
Assertions.assertTrue(this.eventListener.getEvents().get(1) instanceof Saml2PreUserAuthenticationEvent);
Assertions.assertTrue(this.eventListener.getEvents().get(2) instanceof Saml2PostUserAuthenticationEvent);
Assertions.assertTrue(this.eventListener.getEvents().get(3) instanceof Saml2SuccessResponseEvent);

// Auditing
Assertions.assertEquals(4, this.auditListener.getEvents().size());
Assertions.assertEquals(4, this.auditListener.getEvents().size());
}

@Test
Expand Down Expand Up @@ -354,9 +359,9 @@ public String getPreferredBinding() {
Assertions.assertTrue(Saml2PostUserAuthenticationEvent.class.cast(this.eventListener.getEvents().get(6))
.getUserAuthentication().isSsoApplied());
Assertions.assertTrue(this.eventListener.getEvents().get(7) instanceof Saml2SuccessResponseEvent);

// Auditing
Assertions.assertEquals(8, this.auditListener.getEvents().size());
Assertions.assertEquals(8, this.auditListener.getEvents().size());
}

private EntityDescriptor getIdpMetadata() throws Exception {
Expand Down Expand Up @@ -452,7 +457,7 @@ public static class ApplicationConfiguration {
Saml2EventListener saml2EventListener() {
return new Saml2EventListener();
}

@Bean
AuditEventListener auditListener() {
return new AuditEventListener();
Expand Down Expand Up @@ -521,11 +526,11 @@ public static class AuditEventListener implements ApplicationListener<AuditAppli

@Override
public void onApplicationEvent(final AuditApplicationEvent event) {
if (event.getAuditEvent() instanceof Saml2AuditEvent e) {
if (event.getAuditEvent() instanceof Saml2AuditEvent e) {
events.add(e);
}
}

public void clear() {
this.events.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-samples-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Samples :: Client Application</name>
Expand Down
2 changes: 1 addition & 1 deletion samples/demo-boot-idp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-samples-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Samples :: Spring Boot Starter Demo Application</name>
Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Samples :: Parent POM</name>
Expand Down
2 changes: 1 addition & 1 deletion starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>se.swedenconnect.spring.saml.idp</groupId>
<artifactId>spring-saml-idp-parent</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
</parent>

<name>Sweden Connect :: Spring SAML Identity Provider :: Spring Boot Starter</name>
Expand Down

0 comments on commit f4af471

Please sign in to comment.