diff --git a/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/springbootadminclient/SpringBootAdminClientApplicationIntegrationTest.java b/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/springbootadminclient/SpringBootAdminClientApplicationIntegrationTest.java
index 0201deabca..f9e969c06a 100644
--- a/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/springbootadminclient/SpringBootAdminClientApplicationIntegrationTest.java
+++ b/spring-boot-admin/spring-boot-admin-client/src/test/java/com/baeldung/springbootadminclient/SpringBootAdminClientApplicationIntegrationTest.java
@@ -15,7 +15,7 @@ import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = RANDOM_PORT)
@@ -36,20 +36,20 @@ public class SpringBootAdminClientApplicationIntegrationTest {
@Test
public void whenEnvironmentAvailable_ThenAdminServerPropertiesExist() {
- assertEquals(environment.getProperty("spring.boot.admin.url"), "http://localhost:8080");
- assertEquals(environment.getProperty("spring.boot.admin.username"), "admin");
- assertEquals(environment.getProperty("spring.boot.admin.password"), "admin");
+ assertEquals(environment.getProperty("spring.boot.admin.client.url"), "http://localhost:8080");
+ assertEquals(environment.getProperty("spring.boot.admin.client.username"), "admin");
+ assertEquals(environment.getProperty("spring.boot.admin.client.password"), "admin");
}
@Test
public void whenHttpBasicAttempted_ThenSuccess() throws Exception {
- mockMvc.perform(get("/env").with(httpBasic("client", "client")));
+ mockMvc.perform(get("/actuator/env").with(httpBasic("client", "client")));
}
@Test
public void whenInvalidHttpBasicAttempted_ThenUnauthorized() throws Exception {
mockMvc
- .perform(get("/env").with(httpBasic("client", "invalid")))
- .andExpect(status().isUnauthorized());
+ .perform(get("/actuator/env").with(httpBasic("client", "invalid")))
+ .andExpect(unauthenticated());
}
}
diff --git a/spring-boot-admin/spring-boot-admin-server/pom.xml b/spring-boot-admin/spring-boot-admin-server/pom.xml
index 142cf420f4..5ef99976c8 100644
--- a/spring-boot-admin/spring-boot-admin-server/pom.xml
+++ b/spring-boot-admin/spring-boot-admin-server/pom.xml
@@ -51,10 +51,12 @@
${spring-boot-admin-starter-client.version}
-
-
-
-
+
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
+
org.springframework.boot
spring-boot-starter-test
diff --git a/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/NotifierConfiguration.java b/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/NotifierConfiguration.java
index d43f4b430a..f9abee11b7 100644
--- a/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/NotifierConfiguration.java
+++ b/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/NotifierConfiguration.java
@@ -1,32 +1,40 @@
package com.baeldung.springbootadminserver.configs;
import java.time.Duration;
+import java.util.Collections;
+import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
+import de.codecentric.boot.admin.server.notify.CompositeNotifier;
import de.codecentric.boot.admin.server.notify.LoggingNotifier;
+import de.codecentric.boot.admin.server.notify.Notifier;
import de.codecentric.boot.admin.server.notify.RemindingNotifier;
import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier;
@Configuration
public class NotifierConfiguration {
- @Autowired
- private InstanceRepository repository;
+ private final InstanceRepository repository;
+ private final ObjectProvider> otherNotifiers;
- // @Autowired private Notifier notifier;
-
- @Bean
- public LoggingNotifier notifier() {
- return new LoggingNotifier(repository);
+ public NotifierConfiguration(InstanceRepository repository, ObjectProvider> otherNotifiers) {
+ this.repository = repository;
+ this.otherNotifiers = otherNotifiers;
}
@Bean
public FilteringNotifier filteringNotifier() {
- return new FilteringNotifier(notifier(), repository);
+ CompositeNotifier delegate = new CompositeNotifier(this.otherNotifiers.getIfAvailable(Collections::emptyList));
+ return new FilteringNotifier(delegate, this.repository);
+ }
+
+ @Bean
+ public LoggingNotifier notifier() {
+ return new LoggingNotifier(repository);
}
@Primary
diff --git a/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java b/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java
index ee37d2f0b3..1943c61ff4 100644
--- a/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java
+++ b/spring-boot-admin/spring-boot-admin-server/src/main/java/com/baeldung/springbootadminserver/configs/WebSecurityConfig.java
@@ -5,6 +5,7 @@ import java.util.UUID;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
@@ -13,6 +14,7 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
@Configuration
+@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private final AdminServerProperties adminServer;
diff --git a/spring-boot-admin/spring-boot-admin-server/src/main/resources/application.properties b/spring-boot-admin/spring-boot-admin-server/src/main/resources/application.properties
index ba7a7de2a0..273c11468c 100644
--- a/spring-boot-admin/spring-boot-admin-server/src/main/resources/application.properties
+++ b/spring-boot-admin/spring-boot-admin-server/src/main/resources/application.properties
@@ -16,14 +16,14 @@ management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
#mail notifications
-#spring.mail.host=smtp.gmail.com
-#spring.mail.username=test@gmail.com
-#spring.mail.password=password
-#spring.mail.port=587
-#spring.mail.properties.mail.smtp.auth=true
-#spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.host=
+spring.mail.username=
+spring.mail.password=
+spring.mail.port=
+spring.mail.properties.mail.smtp.auth=
+spring.mail.properties.mail.smtp.starttls.enable=
-#spring.boot.admin.notify.mail.to=test@gmail.com
+spring.boot.admin.notify.mail.to=
#hipchat notifications
#spring.boot.admin.notify.hipchat.auth-token=
diff --git a/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/NotifierConfigurationIntegrationTest.java b/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/NotifierConfigurationIntegrationTest.java
index fc8acc4e4d..eca83b6f6c 100644
--- a/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/NotifierConfigurationIntegrationTest.java
+++ b/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/NotifierConfigurationIntegrationTest.java
@@ -1,10 +1,7 @@
package com.baeldung.springbootadminserver;
-import com.baeldung.springbootadminserver.configs.NotifierConfiguration;
-
-import de.codecentric.boot.admin.server.notify.Notifier;
-import de.codecentric.boot.admin.server.notify.RemindingNotifier;
-import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier;
+import static org.junit.Assert.assertNotEquals;
+import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -13,11 +10,14 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
-import static org.junit.Assert.assertNotEquals;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
+import com.baeldung.springbootadminserver.configs.NotifierConfiguration;
+
+import de.codecentric.boot.admin.server.notify.Notifier;
+import de.codecentric.boot.admin.server.notify.RemindingNotifier;
+import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier;
@RunWith(SpringRunner.class)
-@SpringBootTest(classes = { NotifierConfiguration.class }, webEnvironment = NONE)
+@SpringBootTest(classes = { NotifierConfiguration.class, SpringBootAdminServerApplication.class }, webEnvironment = NONE)
public class NotifierConfigurationIntegrationTest {
@Autowired private ApplicationContext applicationContext;
diff --git a/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/WebSecurityConfigIntegrationTest.java b/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/WebSecurityConfigIntegrationTest.java
index 0c0695e6c2..e5018f5f5f 100644
--- a/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/WebSecurityConfigIntegrationTest.java
+++ b/spring-boot-admin/spring-boot-admin-server/src/test/java/com/baeldung/springbootadminserver/WebSecurityConfigIntegrationTest.java
@@ -14,6 +14,7 @@ import static org.springframework.security.test.web.servlet.request.SecurityMock
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@@ -51,21 +52,21 @@ public class WebSecurityConfigIntegrationTest {
.password("admin"));
mockMvc
- .perform(get("/api/applications/"))
+ .perform(get("/applications/"))
.andExpect(status().is2xxSuccessful());
}
@Test
public void whenHttpBasicAttempted_ThenSuccess() throws Exception {
- mockMvc.perform(get("/env").with(httpBasic("admin", "admin")));
+ mockMvc.perform(get("/actuator/env").with(httpBasic("admin", "admin")));
}
@Test
public void whenInvalidHttpBasicAttempted_ThenUnauthorized() throws Exception {
mockMvc
- .perform(get("/env").with(httpBasic("admin", "invalid")))
- .andExpect(status().isUnauthorized());
+ .perform(get("/actuator/env").with(httpBasic("admin", "invalid")))
+ .andExpect(unauthenticated());
}
}