Skip to content

Commit

Permalink
Polish contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jan 20, 2016
1 parent 3724db9 commit 2f24c18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -89,31 +87,17 @@ public void testAuthenticationSwitch() {
}

@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<AuditApplicationEvent> applicationEventArgumentCaptor =
ArgumentCaptor.forClass(AuditApplicationEvent.class);
verify(this.publisher).publishEvent(applicationEventArgumentCaptor.capture());
final Map<String, Object> 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> auditApplicationEvent = ArgumentCaptor
.forClass(AuditApplicationEvent.class);
verify(this.publisher).publishEvent(auditApplicationEvent.capture());
assertThat(auditApplicationEvent.getValue().getAuditEvent().getData(),
hasEntry("details", details));
}
}

0 comments on commit 2f24c18

Please sign in to comment.