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
d7fbe9ef
Commit
d7fbe9ef
authored
Jan 20, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-4976'
parents
1dd16669
2f24c186
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
AuthenticationAuditListener.java
...rk/boot/actuate/security/AuthenticationAuditListener.java
+4
-1
AuthenticationAuditListenerTests.java
...ot/actuate/security/AuthenticationAuditListenerTests.java
+19
-1
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthenticationAuditListener.java
View file @
d7fbe9ef
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -61,6 +61,9 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
...
@@ -61,6 +61,9 @@ public class AuthenticationAuditListener extends AbstractAuthenticationAuditList
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
data
.
put
(
"type"
,
event
.
getException
().
getClass
().
getName
());
data
.
put
(
"type"
,
event
.
getException
().
getClass
().
getName
());
data
.
put
(
"message"
,
event
.
getException
().
getMessage
());
data
.
put
(
"message"
,
event
.
getException
().
getMessage
());
if
(
event
.
getAuthentication
().
getDetails
()
!=
null
)
{
data
.
put
(
"details"
,
event
.
getAuthentication
().
getDetails
());
}
publish
(
new
AuditEvent
(
event
.
getAuthentication
().
getName
(),
publish
(
new
AuditEvent
(
event
.
getAuthentication
().
getName
(),
"AUTHENTICATION_FAILURE"
,
data
));
"AUTHENTICATION_FAILURE"
,
data
));
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthenticationAuditListenerTests.java
View file @
d7fbe9ef
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -18,7 +18,9 @@ package org.springframework.boot.actuate.security;
...
@@ -18,7 +18,9 @@ package org.springframework.boot.actuate.security;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
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.ApplicationEvent
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.security.authentication.BadCredentialsException
;
import
org.springframework.security.authentication.BadCredentialsException
;
...
@@ -30,6 +32,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
...
@@ -30,6 +32,8 @@ import org.springframework.security.core.authority.AuthorityUtils;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.core.userdetails.User
;
import
org.springframework.security.web.authentication.switchuser.AuthenticationSwitchUserEvent
;
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
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
@@ -82,4 +86,18 @@ public class AuthenticationAuditListenerTests {
...
@@ -82,4 +86,18 @@ public class AuthenticationAuditListenerTests {
verify
(
this
.
publisher
).
publishEvent
((
ApplicationEvent
)
anyObject
());
verify
(
this
.
publisher
).
publishEvent
((
ApplicationEvent
)
anyObject
());
}
}
@Test
public
void
testDetailsAreIncludedInAuditEvent
()
throws
Exception
{
Object
details
=
new
Object
();
UsernamePasswordAuthenticationToken
authentication
=
new
UsernamePasswordAuthenticationToken
(
"user"
,
"password"
);
authentication
.
setDetails
(
details
);
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
));
}
}
}
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