Skip to content

Commit 4599766

Browse files
BogdanStoeanmaibin
authored andcommitted
Bael 1271 (eugenp#2907)
* BAEL-1271 - initial commit * BAEL-1271 - created an admin server and a client app that registers to * BAEL-1271 - added security on admin server/on client actuator endpoints * BAEL-1271 - configured mail notifications * added unit test coverage * added unit test coverage * hipchat configuration
1 parent 6365159 commit 4599766

18 files changed

Lines changed: 601 additions & 0 deletions

File tree

‎spring-boot-admin/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Spring Boot Admin
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-boot-admin-client</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-admin-client</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.8.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-boot-admin-starter-client.version>1.5.4</spring-boot-admin-starter-client.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-security</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>de.codecentric</groupId>
39+
<artifactId>spring-boot-admin-starter-client</artifactId>
40+
<version>${spring-boot-admin-starter-client.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.security</groupId>
49+
<artifactId>spring-security-test</artifactId>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
<executions>
60+
<execution>
61+
<goals>
62+
<goal>build-info</goal>
63+
</goals>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
70+
71+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.springbootadminclient;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringBootAdminClientApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringBootAdminClientApplication.class, args);
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#basic auth creddentials
2+
security.user.name=client
3+
security.user.password=client
4+
5+
#configs to connect to a secured server
6+
spring.boot.admin.url=http://localhost:8080
7+
spring.boot.admin.username=admin
8+
spring.boot.admin.password=admin
9+
10+
#configs to give secured server info
11+
spring.boot.admin.client.metadata.user.name=${security.user.name}
12+
spring.boot.admin.client.metadata.user.password=${security.user.password}
13+
14+
#app config
15+
spring.application.name=spring-boot-admin-client
16+
server.port=8081
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<jmxConfigurator />
4+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%date [%thread] %-5level %logger{25} - %msg%n</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="CONSOLE"/>
12+
</root>
13+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.baeldung.springbootadminclient;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.core.env.Environment;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
import org.springframework.test.web.servlet.MockMvc;
11+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
12+
import org.springframework.web.context.WebApplicationContext;
13+
14+
import static org.junit.Assert.assertEquals;
15+
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
16+
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
17+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
18+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
19+
20+
@RunWith(SpringRunner.class)
21+
@SpringBootTest(webEnvironment = RANDOM_PORT)
22+
public class SpringBootAdminClientApplicationTests {
23+
24+
@Autowired Environment environment;
25+
26+
@Autowired WebApplicationContext wac;
27+
28+
private MockMvc mockMvc;
29+
30+
@Before
31+
public void setup() {
32+
mockMvc = MockMvcBuilders
33+
.webAppContextSetup(wac)
34+
.build();
35+
}
36+
37+
@Test
38+
public void whenEnvironmentAvailable_ThenAdminServerPropertiesExist() {
39+
assertEquals(environment.getProperty("spring.boot.admin.url"), "http://localhost:8080");
40+
assertEquals(environment.getProperty("spring.boot.admin.username"), "admin");
41+
assertEquals(environment.getProperty("spring.boot.admin.password"), "admin");
42+
}
43+
44+
@Test
45+
public void whenHttpBasicAttempted_ThenSuccess() throws Exception {
46+
mockMvc.perform(get("/env").with(httpBasic("client", "client")));
47+
}
48+
49+
@Test
50+
public void whenInvalidHttpBasicAttempted_ThenUnauthorized() throws Exception {
51+
mockMvc
52+
.perform(get("/env").with(httpBasic("client", "invalid")))
53+
.andExpect(status().isUnauthorized());
54+
}
55+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-boot-admin-server</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-admin-server</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.8.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-boot-admin-server.version>1.5.4</spring-boot-admin-server.version>
26+
<spring-boot-admin-starter-client.version>1.5.4</spring-boot-admin-starter-client.version>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter</artifactId>
33+
</dependency>
34+
35+
<!-- dependencies used to enable admin server and UI-->
36+
<dependency>
37+
<groupId>de.codecentric</groupId>
38+
<artifactId>spring-boot-admin-server</artifactId>
39+
<version>${spring-boot-admin-server.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>de.codecentric</groupId>
43+
<artifactId>spring-boot-admin-server-ui</artifactId>
44+
<version>${spring-boot-admin-server.version}</version>
45+
</dependency>
46+
47+
<!--Add login page and logout feature-->
48+
<dependency>
49+
<groupId>de.codecentric</groupId>
50+
<artifactId>spring-boot-admin-server-ui-login</artifactId>
51+
<version>${spring-boot-admin-server.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-security</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.hazelcast</groupId>
59+
<artifactId>hazelcast</artifactId>
60+
</dependency>
61+
<!--declare the admin server as a client, for self monitoring-->
62+
<dependency>
63+
<groupId>de.codecentric</groupId>
64+
<artifactId>spring-boot-admin-starter-client</artifactId>
65+
<version>${spring-boot-admin-starter-client.version}</version>
66+
</dependency>
67+
<!--mail notifications-->
68+
<!--<dependency>-->
69+
<!--<groupId>org.springframework.boot</groupId>-->
70+
<!--<artifactId>spring-boot-starter-mail</artifactId>-->
71+
<!--</dependency>-->
72+
<dependency>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-starter-test</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.springframework.security</groupId>
79+
<artifactId>spring-security-test</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
83+
</dependencies>
84+
85+
<build>
86+
<plugins>
87+
<plugin>
88+
<groupId>org.springframework.boot</groupId>
89+
<artifactId>spring-boot-maven-plugin</artifactId>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
94+
95+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.springbootadminserver;
2+
3+
import de.codecentric.boot.admin.config.EnableAdminServer;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@EnableAdminServer
8+
@SpringBootApplication
9+
public class SpringBootAdminServerApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringBootAdminServerApplication.class, args);
13+
}
14+
}

0 commit comments

Comments
 (0)