From 2f24c1862a040e08cb6d7887adab817db6e57dc8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 20 Jan 2016 10:13:11 +0000 Subject: [PATCH] Polish contribution --- .../security/AuthenticationAuditListener.java | 2 +- .../AuthenticationAuditListenerTests.java | 40 ++++++------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java index 4f85b86701..072c81c71b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java index 59823e51a3..216b06fbd9 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.boot.actuate.security; -import java.util.Map; - import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -89,31 +87,17 @@ public class AuthenticationAuditListenerTests { } @Test - public void shouldPassDetailsToAuditEventOnAuthenticationFailureEvent() - throws Exception { - // given - final Object details = new Object(); - final AuthenticationFailureExpiredEvent event = - createAuthenticationFailureEvent(details); - - // when - this.listener.onApplicationEvent(event); - - // then - final ArgumentCaptor applicationEventArgumentCaptor = - ArgumentCaptor.forClass(AuditApplicationEvent.class); - verify(this.publisher).publishEvent(applicationEventArgumentCaptor.capture()); - final Map eventData = - applicationEventArgumentCaptor.getValue().getAuditEvent().getData(); - assertThat(eventData, hasEntry("details", details)); - } - - private AuthenticationFailureExpiredEvent createAuthenticationFailureEvent( - final Object details) { - final UsernamePasswordAuthenticationToken authentication = - new UsernamePasswordAuthenticationToken("user", "password"); + public void testDetailsAreIncludedInAuditEvent() throws Exception { + Object details = new Object(); + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( + "user", "password"); authentication.setDetails(details); - final BadCredentialsException exception = new BadCredentialsException("Bad user"); - return new AuthenticationFailureExpiredEvent(authentication, exception); + this.listener.onApplicationEvent(new AuthenticationFailureExpiredEvent( + authentication, new BadCredentialsException("Bad user"))); + ArgumentCaptor auditApplicationEvent = ArgumentCaptor + .forClass(AuditApplicationEvent.class); + verify(this.publisher).publishEvent(auditApplicationEvent.capture()); + assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(), + hasEntry("details", details)); } }