From 7fb0bd77cd7962dbe69cc896b63494d55dca73d6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 12 Dec 2017 08:45:20 +0100 Subject: [PATCH] Polish "Handle null Principal in AuditEvent" Closes gh-11320 --- .../boot/actuate/audit/AuditEvent.java | 4 ++-- .../boot/actuate/audit/AuditEventTests.java | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java index f8cda87f7ee..a7b6ee21a0a 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java @@ -41,7 +41,6 @@ import org.springframework.util.Assert; * (wrappers for AuditEvent). * * @author Dave Syer - * @author Nakul Mishra * @see AuditEventRepository */ @JsonInclude(Include.NON_EMPTY) @@ -117,7 +116,8 @@ public class AuditEvent implements Serializable { } /** - * Returns the user principal responsible for the event. + * Returns the user principal responsible for the event or an empty String if the + * principal is not available. * @return the principal */ public String getPrincipal() { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java index 3d46a901065..b13e0bb4707 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java @@ -32,7 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer * @author Vedran Pavic - * @author Nakul Mishra */ public class AuditEventTests { @@ -56,6 +55,13 @@ public class AuditEventTests { assertThat(event.getData().get("c")).isEqualTo("d"); } + @Test + public void nullPrincipalIsMappedToEmptyString() { + AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", + Collections.singletonMap("a", (Object) "b")); + assertThat(auditEvent.getPrincipal()).isEmpty(); + } + @Test public void nullTimestamp() throws Exception { this.thrown.expect(IllegalArgumentException.class); @@ -64,12 +70,6 @@ public class AuditEventTests { Collections.singletonMap("a", (Object) "b")); } - @Test - public void nullPrincipal() { - AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", (Object) "b")); - assertThat(auditEvent.getPrincipal()).isEmpty(); - } - @Test public void nullType() throws Exception { this.thrown.expect(IllegalArgumentException.class);