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
14d71885
Commit
14d71885
authored
May 03, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5830 from vpavic/audit-listener
* pr/5830: Allow customization of AuditListener
parents
6c21ba11
0b70710b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
10 deletions
+80
-10
AbstractAuditListener.java
...rk/boot/actuate/audit/listener/AbstractAuditListener.java
+38
-0
AuditListener.java
...gframework/boot/actuate/audit/listener/AuditListener.java
+9
-8
AuditAutoConfiguration.java
...rk/boot/actuate/autoconfigure/AuditAutoConfiguration.java
+2
-0
AuditAutoConfigurationTests.java
...ot/actuate/autoconfigure/AuditAutoConfigurationTests.java
+31
-2
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AbstractAuditListener.java
0 → 100644
View file @
14d71885
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
audit
.
listener
;
import
org.springframework.boot.actuate.audit.AuditEvent
;
import
org.springframework.context.ApplicationListener
;
/**
* Abstract {@link ApplicationListener} to handle {@link AuditApplicationEvent}s.
*
* @author Vedran Pavic
* @since 1.4.0
*/
public
abstract
class
AbstractAuditListener
implements
ApplicationListener
<
AuditApplicationEvent
>
{
@Override
public
void
onApplicationEvent
(
AuditApplicationEvent
event
)
{
onAuditEvent
(
event
.
getAuditEvent
());
}
protected
abstract
void
onAuditEvent
(
AuditEvent
event
);
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AuditListener.java
View file @
14d71885
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -19,17 +19,18 @@ package org.springframework.boot.actuate.audit.listener;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.actuate.audit.AuditEvent
;
import
org.springframework.boot.actuate.audit.AuditEventRepository
;
import
org.springframework.context.ApplicationListener
;
/**
*
{@link ApplicationListener} that listens for {@link AuditApplicationEvent}s and stores
* them in a {@link AuditEventRepository}.
*
The default {@link AbstractAuditListener} implementation. Listens for
*
{@link AuditApplicationEvent}s and stores
them in a {@link AuditEventRepository}.
*
* @author Dave Syer
* @author Stephane Nicoll
* @author Vedran Pavic
*/
public
class
AuditListener
implements
ApplicationListener
<
AuditApplicationEvent
>
{
public
class
AuditListener
extends
AbstractAuditListener
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
AuditListener
.
class
);
...
...
@@ -40,11 +41,11 @@ public class AuditListener implements ApplicationListener<AuditApplicationEvent>
}
@Override
p
ublic
void
onApplicationEvent
(
AuditApplication
Event
event
)
{
p
rotected
void
onAuditEvent
(
Audit
Event
event
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
event
.
getAuditEvent
()
);
logger
.
debug
(
event
);
}
this
.
auditEventRepository
.
add
(
event
.
getAuditEvent
()
);
this
.
auditEventRepository
.
add
(
event
);
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfiguration.java
View file @
14d71885
...
...
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.ObjectProvider;
import
org.springframework.boot.actuate.audit.AuditEvent
;
import
org.springframework.boot.actuate.audit.AuditEventRepository
;
import
org.springframework.boot.actuate.audit.InMemoryAuditEventRepository
;
import
org.springframework.boot.actuate.audit.listener.AbstractAuditListener
;
import
org.springframework.boot.actuate.audit.listener.AuditListener
;
import
org.springframework.boot.actuate.security.AbstractAuthenticationAuditListener
;
import
org.springframework.boot.actuate.security.AbstractAuthorizationAuditListener
;
...
...
@@ -48,6 +49,7 @@ public class AuditAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
(
AbstractAuditListener
.
class
)
public
AuditListener
auditListener
()
throws
Exception
{
return
new
AuditListener
(
this
.
auditEventRepository
);
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/AuditAutoConfigurationTests.java
View file @
14d71885
...
...
@@ -18,8 +18,10 @@ package org.springframework.boot.actuate.autoconfigure;
import
org.junit.Test
;
import
org.springframework.boot.actuate.audit.AuditEvent
;
import
org.springframework.boot.actuate.audit.AuditEventRepository
;
import
org.springframework.boot.actuate.audit.InMemoryAuditEventRepository
;
import
org.springframework.boot.actuate.audit.listener.AbstractAuditListener
;
import
org.springframework.boot.actuate.security.AbstractAuthenticationAuditListener
;
import
org.springframework.boot.actuate.security.AbstractAuthorizationAuditListener
;
import
org.springframework.boot.actuate.security.AuthenticationAuditListener
;
...
...
@@ -44,7 +46,7 @@ public class AuditAutoConfigurationTests {
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@Test
public
void
testTrace
Configuration
()
throws
Exception
{
public
void
default
Configuration
()
throws
Exception
{
registerAndRefresh
(
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
)).
isNotNull
();
assertThat
(
this
.
context
.
getBean
(
AuthenticationAuditListener
.
class
)).
isNotNull
();
...
...
@@ -52,7 +54,7 @@ public class AuditAutoConfigurationTests {
}
@Test
public
void
ownAu
to
Repository
()
throws
Exception
{
public
void
ownAu
ditEvent
Repository
()
throws
Exception
{
registerAndRefresh
(
CustomAuditEventRepositoryConfiguration
.
class
,
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AuditEventRepository
.
class
))
...
...
@@ -75,6 +77,14 @@ public class AuditAutoConfigurationTests {
.
isInstanceOf
(
TestAuthorizationAuditListener
.
class
);
}
@Test
public
void
ownAuditListener
()
throws
Exception
{
registerAndRefresh
(
CustomAuditListenerConfiguration
.
class
,
AuditAutoConfiguration
.
class
);
assertThat
(
this
.
context
.
getBean
(
AbstractAuditListener
.
class
))
.
isInstanceOf
(
TestAuditListener
.
class
);
}
private
void
registerAndRefresh
(
Class
<?>...
annotatedClasses
)
{
this
.
context
.
register
(
annotatedClasses
);
this
.
context
.
refresh
();
...
...
@@ -139,4 +149,23 @@ public class AuditAutoConfigurationTests {
}
@Configuration
protected
static
class
CustomAuditListenerConfiguration
{
@Bean
public
TestAuditListener
testAuditListener
()
{
return
new
TestAuditListener
();
}
}
protected
static
class
TestAuditListener
extends
AbstractAuditListener
{
@Override
protected
void
onAuditEvent
(
AuditEvent
event
)
{
}
}
}
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