Skip to content

Commit 478d138

Browse files
joemahady-commduanemay
authored andcommitted
Update after review
1 parent 4c8b9e8 commit 478d138

5 files changed

Lines changed: 26 additions & 12 deletions

File tree

server/src/main/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public PasswordChangeEvent(String message, UaaUser user, Authentication principa
3131

3232
@Override
3333
public AuditEvent getAuditEvent() {
34-
return createAuditRecord(getUser().getId(), getUser().getUsername(), AuditEventType.PasswordChangeSuccess,
35-
getOrigin(getPrincipal()), getMessage());
34+
return createAuditRecord(getUser().getId(), AuditEventType.PasswordChangeSuccess,
35+
getOrigin(getPrincipal()), getMessage(), getUser().getUsername());
3636
}
3737

3838
}

server/src/main/java/org/cloudfoundry/identity/uaa/account/event/PasswordChangeFailureEvent.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public PasswordChangeFailureEvent(String message, UaaUser user, Authentication p
3333
public AuditEvent getAuditEvent() {
3434
UaaUser user = getUser();
3535
if (user == null) {
36-
return createAuditRecord(getPrincipal().getName(), getPrincipal().getName(), AuditEventType.PasswordChangeFailure,
37-
getOrigin(getPrincipal()), getMessage());
36+
return createAuditRecord(getPrincipal().getName(), AuditEventType.PasswordChangeFailure,
37+
getOrigin(getPrincipal()), getMessage(), getPrincipal().getName());
3838
} else {
39-
return createAuditRecord(user.getId(), user.getUsername(), AuditEventType.PasswordChangeFailure,
40-
getOrigin(getPrincipal()), getMessage());
39+
return createAuditRecord(user.getId(), AuditEventType.PasswordChangeFailure,
40+
getOrigin(getPrincipal()), getMessage(), user.getUsername());
4141
}
4242
}
4343

server/src/main/java/org/cloudfoundry/identity/uaa/audit/AuditEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public class AuditEvent {
2929
private final String authenticationType;
3030

3131
public AuditEvent(AuditEventType type, String principalId, String origin, String data, long time, String identityZoneId, String authenticationType, String description) {
32-
this(type, principalId, null, origin, data, time, identityZoneId, authenticationType, description);
32+
this(type, principalId, origin, data, time, identityZoneId, authenticationType, description, null);
3333
}
3434

35-
public AuditEvent(AuditEventType type, String principalId, String principalName, String origin, String data, long time, String identityZoneId, String authenticationType, String description) {
35+
public AuditEvent(AuditEventType type, String principalId, String origin, String data, long time, String identityZoneId, String authenticationType, String description, String principalName) {
3636
this.type = type;
3737
this.data = data;
3838
this.origin = origin;

server/src/main/java/org/cloudfoundry/identity/uaa/audit/event/AbstractUaaEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ protected AuditEvent createAuditRecord(String principalId, AuditEventType type,
7979
return new AuditEvent(type, principalId, origin, data, System.currentTimeMillis(), zoneId, null, null);
8080
}
8181

82-
protected AuditEvent createAuditRecord(String principalId, String principalName, AuditEventType type, String origin, String data) {
83-
return new AuditEvent(type, principalId, principalName, origin, data, System.currentTimeMillis(), zoneId, null, null);
82+
protected AuditEvent createAuditRecord(String principalId, AuditEventType type, String origin, String data, String principalName) {
83+
return new AuditEvent(type, principalId, origin, data, System.currentTimeMillis(), zoneId, null, null, principalName);
8484
}
8585

8686
protected AuditEvent createAuditRecord(String principalId, AuditEventType type, String origin, String data, String authenticationType, String message) {

server/src/test/java/org/cloudfoundry/identity/uaa/audit/LoggingAuditServiceTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void log_format_whenAuthTypeIsNull() {
5151

5252
@Test
5353
void log_format_whenPrincipalNameIsPresent() {
54-
AuditEvent auditEvent = new AuditEvent(PasswordChangeSuccess, "thePrincipalId", "thePrincipalName", "theOrigin", "theData", 42L, "theZoneId", null, null);
54+
AuditEvent auditEvent = new AuditEvent(PasswordChangeSuccess, "thePrincipalId", "theOrigin", "theData", 42L, "theZoneId", null, null, "thePrincipalName");
5555

5656
loggingAuditService.log(auditEvent, "not-used");
5757

@@ -63,7 +63,7 @@ void log_format_whenPrincipalNameIsPresent() {
6363

6464
@Test
6565
void log_format_whenPrincipalNameAndAuthTypeArePresent() {
66-
AuditEvent auditEvent = new AuditEvent(PasswordChangeFailure, "thePrincipalId", "thePrincipalName", "theOrigin", "theData", 42L, "theZoneId", "theAuthType", "theDescription");
66+
AuditEvent auditEvent = new AuditEvent(PasswordChangeFailure, "thePrincipalId", "theOrigin", "theData", 42L, "theZoneId", "theAuthType", "theDescription", "thePrincipalName");
6767

6868
loggingAuditService.log(auditEvent, "not-used");
6969

@@ -87,6 +87,20 @@ void log_sanitizesMaliciousInput() {
8787
.contains(LogSanitizerUtil.SANITIZED_FLAG);
8888
}
8989

90+
@Test
91+
void log_sanitizesMaliciousPrincipalName() {
92+
AuditEvent auditEvent = new AuditEvent(PasswordChangeSuccess, "principalId", "origin", "data", 100L, "safe-zone", null, null, "malicious\r\n\tname");
93+
94+
loggingAuditService.log(auditEvent, "not-used");
95+
96+
ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
97+
verify(mockLogger).info(stringCaptor.capture());
98+
assertThat(stringCaptor.getValue()).doesNotContain("\r")
99+
.doesNotContain("\n")
100+
.doesNotContain("\t")
101+
.contains(LogSanitizerUtil.SANITIZED_FLAG);
102+
}
103+
90104
@Test
91105
void log_doesNotModifyNonMaliciousInput() {
92106
AuditEvent auditEvent = new AuditEvent(UserAuthenticationSuccess, "principalId", "origin", "data", 100L, "safe-zone", null, null);

0 commit comments

Comments
 (0)