Skip to content

Commit 849baa4

Browse files
committed
Do not require after in audit events endpoint
Closes gh-11605
1 parent c233125 commit 849baa4

File tree

9 files changed

+21
-236
lines changed

9 files changed

+21
-236
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/asciidoc/endpoints/auditevents.adoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ include::{snippets}auditevents/filtered/http-response.adoc[]
2525
=== Query Parameters
2626

2727
The endpoint uses query parameters to limit the events that it returns. The following
28-
table shows the supported query parameters:
28+
table shows the supported query parameters:
2929

3030
[cols="2,4"]
3131
include::{snippets}auditevents/filtered/request-parameters.adoc[]
3232

33-
The `after` parameter is required. You can also use one or both of the `principal` and
34-
`type` parameters to further limit the results.
35-
3633

3734

3835
[[audit-events-retrieving-response-structure]]
@@ -42,4 +39,4 @@ The response contains details of all of the audit events that matched the query.
4239
following table describes the structure of the response:
4340

4441
[cols="2,1,3"]
45-
include::{snippets}auditevents/after/response-fields.adoc[]
42+
include::{snippets}auditevents/all/response-fields.adoc[]

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfiguration.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
1818

1919
import org.springframework.boot.actuate.audit.AuditEventRepository;
2020
import org.springframework.boot.actuate.audit.AuditEventsEndpoint;
21-
import org.springframework.boot.actuate.audit.AuditEventsEndpointWebExtension;
22-
import org.springframework.boot.actuate.audit.AuditEventsJmxEndpointExtension;
2321
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
2422
import org.springframework.boot.actuate.logging.LoggersEndpoint;
2523
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -50,22 +48,4 @@ public AuditEventsEndpoint auditEventsEndpoint(
5048
return new AuditEventsEndpoint(auditEventRepository);
5149
}
5250

53-
@Bean
54-
@ConditionalOnMissingBean
55-
@ConditionalOnEnabledEndpoint
56-
@ConditionalOnBean(AuditEventsEndpoint.class)
57-
public AuditEventsJmxEndpointExtension auditEventsJmxEndpointExtension(
58-
AuditEventsEndpoint auditEventsEndpoint) {
59-
return new AuditEventsJmxEndpointExtension(auditEventsEndpoint);
60-
}
61-
62-
@Bean
63-
@ConditionalOnMissingBean
64-
@ConditionalOnEnabledEndpoint
65-
@ConditionalOnBean(AuditEventsEndpoint.class)
66-
public AuditEventsEndpointWebExtension auditEventsWebEndpointExtension(
67-
AuditEventsEndpoint auditEventsEndpoint) {
68-
return new AuditEventsEndpointWebExtension(auditEventsEndpoint);
69-
}
70-
7151
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfigurationTests.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,6 @@
1919
import org.junit.Test;
2020

2121
import org.springframework.boot.actuate.audit.AuditEventsEndpoint;
22-
import org.springframework.boot.actuate.audit.AuditEventsEndpointWebExtension;
23-
import org.springframework.boot.actuate.audit.AuditEventsJmxEndpointExtension;
2422
import org.springframework.boot.autoconfigure.AutoConfigurations;
2523
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2624

@@ -46,25 +44,11 @@ public void runShouldHaveEndpointBean() {
4644
}
4745

4846
@Test
49-
public void runShouldHaveJmxExtensionBean() {
50-
this.contextRunner.run((context) -> assertThat(context)
51-
.hasSingleBean(AuditEventsJmxEndpointExtension.class));
52-
}
53-
54-
@Test
55-
public void runShouldHaveWebExtensionBean() {
56-
this.contextRunner.run((context) -> assertThat(context)
57-
.hasSingleBean(AuditEventsEndpointWebExtension.class));
58-
}
59-
60-
@Test
61-
public void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointOrExtensionBean() {
47+
public void runWhenEnabledPropertyIsFalseShouldNotHaveEndpoint() {
6248
this.contextRunner
6349
.withPropertyValues("management.endpoint.auditevents.enabled:false")
6450
.run((context) -> assertThat(context)
65-
.doesNotHaveBean(AuditEventsEndpoint.class)
66-
.doesNotHaveBean(AuditEventsJmxEndpointExtension.class)
67-
.doesNotHaveBean(AuditEventsEndpointWebExtension.class));
51+
.doesNotHaveBean(AuditEventsEndpoint.class));
6852
}
6953

7054
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.boot.actuate.audit.AuditEvent;
2727
import org.springframework.boot.actuate.audit.AuditEventRepository;
2828
import org.springframework.boot.actuate.audit.AuditEventsEndpoint;
29-
import org.springframework.boot.actuate.audit.AuditEventsEndpointWebExtension;
3029
import org.springframework.boot.test.mock.mockito.MockBean;
3130
import org.springframework.context.annotation.Bean;
3231
import org.springframework.context.annotation.Configuration;
@@ -55,13 +54,13 @@ public class AuditEventsEndpointDocumentationTests
5554
private AuditEventRepository repository;
5655

5756
@Test
58-
public void allAuditEventsAfter() throws Exception {
57+
public void allAuditEvents() throws Exception {
5958
String queryTimestamp = "2017-11-07T09:37Z";
6059
given(this.repository.find(any(), any(), any())).willReturn(
6160
Arrays.asList(new AuditEvent("alice", "logout", Collections.emptyMap())));
6261
this.mockMvc.perform(get("/actuator/auditevents").param("after", queryTimestamp))
6362
.andExpect(status().isOk())
64-
.andDo(document("auditevents/after", responseFields(
63+
.andDo(document("auditevents/all", responseFields(
6564
fieldWithPath("events").description("An array of audit events."),
6665
fieldWithPath("events.[].timestamp")
6766
.description("The timestamp of when the event occurred."),
@@ -85,7 +84,7 @@ public void filteredAuditEvents() throws Exception {
8584
requestParameters(
8685
parameterWithName("after").description(
8786
"Restricts the events to those that occurred "
88-
+ "after the given time. Required."),
87+
+ "after the given time. Optional."),
8988
parameterWithName("principal").description(
9089
"Restricts the events to those with the given "
9190
+ "principal. Optional."),
@@ -104,12 +103,6 @@ public AuditEventsEndpoint auditEventsEndpoint(AuditEventRepository repository)
104103
return new AuditEventsEndpoint(repository);
105104
}
106105

107-
@Bean
108-
public AuditEventsEndpointWebExtension adAuditEventsWebEndpointExtension(
109-
AuditEventsEndpoint delegate) {
110-
return new AuditEventsEndpointWebExtension(delegate);
111-
}
112-
113106
}
114107

115108
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
2323
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
24+
import org.springframework.lang.Nullable;
2425
import org.springframework.util.Assert;
2526

2627
/**
@@ -40,8 +41,8 @@ public AuditEventsEndpoint(AuditEventRepository auditEventRepository) {
4041
}
4142

4243
@ReadOperation
43-
public AuditEventsDescriptor events(String principal, OffsetDateTime after,
44-
String type) {
44+
public AuditEventsDescriptor events(@Nullable String principal,
45+
@Nullable OffsetDateTime after, @Nullable String type) {
4546
return new AuditEventsDescriptor(this.auditEventRepository.find(principal,
4647
after == null ? null : after.toInstant(), type));
4748
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebExtension.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtension.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebIntegrationTests.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ public class AuditEventsEndpointWebIntegrationTests {
4141
private static WebTestClient client;
4242

4343
@Test
44-
public void eventsWithoutParams() {
44+
public void allEvents() {
4545
client.get().uri((builder) -> builder.path("/actuator/auditevents").build())
46-
.exchange().expectStatus().isBadRequest();
46+
.exchange().expectStatus().isOk().expectBody()
47+
.jsonPath("events.[*].principal")
48+
.isEqualTo(new JSONArray().appendElement("admin").appendElement("admin")
49+
.appendElement("user"));
4750
}
4851

4952
@Test
50-
public void eventsWithDateAfter() {
53+
public void eventsAfter() {
5154
client.get()
5255
.uri((builder) -> builder.path("/actuator/auditevents")
5356
.queryParam("after", "2016-11-01T13:00:00%2B00:00").build())
@@ -56,23 +59,20 @@ public void eventsWithDateAfter() {
5659
}
5760

5861
@Test
59-
public void eventsWithPrincipalAndDateAfter() {
62+
public void eventsWithPrincipal() {
6063
client.get()
6164
.uri((builder) -> builder.path("/actuator/auditevents")
62-
.queryParam("after", "2016-11-01T10:00:00%2B00:00")
6365
.queryParam("principal", "user").build())
6466
.exchange().expectStatus().isOk().expectBody()
6567
.jsonPath("events.[*].principal")
6668
.isEqualTo(new JSONArray().appendElement("user"));
6769
}
6870

6971
@Test
70-
public void eventsWithPrincipalDateAfterAndType() {
72+
public void eventsWithType() {
7173
client.get()
7274
.uri((builder) -> builder.path("/actuator/auditevents")
73-
.queryParam("after", "2016-11-01T10:00:00%2B00:00")
74-
.queryParam("principal", "admin").queryParam("type", "logout")
75-
.build())
75+
.queryParam("type", "logout").build())
7676
.exchange().expectStatus().isOk().expectBody()
7777
.jsonPath("events.[*].principal")
7878
.isEqualTo(new JSONArray().appendElement("admin"))
@@ -97,12 +97,6 @@ public AuditEventsEndpoint auditEventsEndpoint() {
9797
return new AuditEventsEndpoint(auditEventsRepository());
9898
}
9999

100-
@Bean
101-
public AuditEventsEndpointWebExtension auditEventsEndpointWebExtension(
102-
AuditEventsEndpoint auditEventsEndpoint) {
103-
return new AuditEventsEndpointWebExtension(auditEventsEndpoint);
104-
}
105-
106100
private AuditEvent createEvent(String instant, String principal, String type) {
107101
return new AuditEvent(Instant.parse(instant), principal, type,
108102
Collections.emptyMap());

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtensionTests.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)