Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3724db9e
Commit
3724db9e
authored
Jan 20, 2016
by
mkwaczynski
Committed by
Andy Wilkinson
Jan 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include details in AuditEvent data in AuthenticationAuditListener
Closes gh-4976
parent
1dd16669
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
AuthenticationAuditListener.java
...rk/boot/actuate/security/AuthenticationAuditListener.java
+3
-0
AuthenticationAuditListenerTests.java
...ot/actuate/security/AuthenticationAuditListenerTests.java
+34
-0
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java
View file @
3724db9e
...
...
@@ -61,6 +61,9 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
data
.
put
(
"type"
,
event
.
getException
().
getClass
().
getName
());
data
.
put
(
"message"
,
event
.
getException
().
getMessage
());
if
(
event
.
getAuthentication
().
getDetails
()
!=
null
)
{
data
.
put
(
"details"
,
event
.
getAuthentication
().
getDetails
());
}
publish
(
new
AuditEvent
(
event
.
getAuthentication
().
getName
(),
"AUTHENTICATION_FAILURE"
,
data
));
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java
View file @
3724db9e
...
...
@@ -16,9 +16,13 @@
package
org
.
springframework
.
boot
.
actuate
.
security
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.boot.actuate.audit.listener.AuditApplicationEvent
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.security.authentication.BadCredentialsException
;
...
...
@@ -30,6 +34,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent
;
import
static
org
.
hamcrest
.
Matchers
.
hasEntry
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
...
@@ -82,4 +88,32 @@ public class AuthenticationAuditListenerTests {
verify
(
this
.
publisher
).
publishEvent
((
ApplicationEvent
)
anyObject
());
}
@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"
);
authentication
.
setDetails
(
details
);
final
BadCredentialsException
exception
=
new
BadCredentialsException
(
"Bad user"
);
return
new
AuthenticationFailureExpiredEvent
(
authentication
,
exception
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment