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
ca2b97b9
Commit
ca2b97b9
authored
Sep 09, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6851 from vpavic/authz-listener-details
* pr/6851: Include AuditEvent details in AuditListener
parents
56544c8d
d87bec11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
AuthorizationAuditListener.java
...ork/boot/actuate/security/AuthorizationAuditListener.java
+4
-1
AuthorizationAuditListenerTests.java
...oot/actuate/security/AuthorizationAuditListenerTests.java
+31
-2
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/security/AuthorizationAuditListener.java
View file @
ca2b97b9
/*
/*
* 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.
...
@@ -54,6 +54,9 @@ public class AuthorizationAuditListener extends AbstractAuthorizationAuditListen
...
@@ -54,6 +54,9 @@ public class AuthorizationAuditListener extends AbstractAuthorizationAuditListen
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
data
.
put
(
"type"
,
event
.
getAccessDeniedException
().
getClass
().
getName
());
data
.
put
(
"type"
,
event
.
getAccessDeniedException
().
getClass
().
getName
());
data
.
put
(
"message"
,
event
.
getAccessDeniedException
().
getMessage
());
data
.
put
(
"message"
,
event
.
getAccessDeniedException
().
getMessage
());
if
(
event
.
getAuthentication
().
getDetails
()
!=
null
)
{
data
.
put
(
"details"
,
event
.
getAuthentication
().
getDetails
());
}
publish
(
new
AuditEvent
(
event
.
getAuthentication
().
getName
(),
publish
(
new
AuditEvent
(
event
.
getAuthentication
().
getName
(),
"AUTHORIZATION_FAILURE"
,
data
));
"AUTHORIZATION_FAILURE"
,
data
));
}
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/security/AuthorizationAuditListenerTests.java
View file @
ca2b97b9
/*
/*
* 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.
...
@@ -20,15 +20,20 @@ import java.util.Arrays;
...
@@ -20,15 +20,20 @@ import java.util.Arrays;
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.access.AccessDeniedException
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.access.ConfigAttribute
;
import
org.springframework.security.access.ConfigAttribute
;
import
org.springframework.security.access.SecurityConfig
;
import
org.springframework.security.access.SecurityConfig
;
import
org.springframework.security.access.event.AuthenticationCredentialsNotFoundEvent
;
import
org.springframework.security.access.event.AuthorizationFailureEvent
;
import
org.springframework.security.access.event.AuthorizationFailureEvent
;
import
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
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
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
@@ -49,7 +54,15 @@ public class AuthorizationAuditListenerTests {
...
@@ -49,7 +54,15 @@ public class AuthorizationAuditListenerTests {
}
}
@Test
@Test
public
void
testAuthenticationSuccess
()
{
public
void
testAuthenticationCredentialsNotFound
()
{
this
.
listener
.
onApplicationEvent
(
new
AuthenticationCredentialsNotFoundEvent
(
this
,
Arrays
.<
ConfigAttribute
>
asList
(
new
SecurityConfig
(
"USER"
)),
new
AuthenticationCredentialsNotFoundException
(
"Bad user"
)));
verify
(
this
.
publisher
).
publishEvent
((
ApplicationEvent
)
anyObject
());
}
@Test
public
void
testAuthorizationFailure
()
{
this
.
listener
.
onApplicationEvent
(
new
AuthorizationFailureEvent
(
this
,
this
.
listener
.
onApplicationEvent
(
new
AuthorizationFailureEvent
(
this
,
Arrays
.<
ConfigAttribute
>
asList
(
new
SecurityConfig
(
"USER"
)),
Arrays
.<
ConfigAttribute
>
asList
(
new
SecurityConfig
(
"USER"
)),
new
UsernamePasswordAuthenticationToken
(
"user"
,
"password"
),
new
UsernamePasswordAuthenticationToken
(
"user"
,
"password"
),
...
@@ -57,4 +70,20 @@ public class AuthorizationAuditListenerTests {
...
@@ -57,4 +70,20 @@ public class AuthorizationAuditListenerTests {
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
AuthorizationFailureEvent
(
this
,
Arrays
.<
ConfigAttribute
>
asList
(
new
SecurityConfig
(
"USER"
)),
authentication
,
new
AccessDeniedException
(
"Bad user"
)));
ArgumentCaptor
<
AuditApplicationEvent
>
auditApplicationEvent
=
ArgumentCaptor
.
forClass
(
AuditApplicationEvent
.
class
);
verify
(
this
.
publisher
).
publishEvent
(
auditApplicationEvent
.
capture
());
assertThat
(
auditApplicationEvent
.
getValue
().
getAuditEvent
().
getData
())
.
containsEntry
(
"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