Added security
This commit is contained in:
@@ -34,7 +34,10 @@
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -4,4 +4,22 @@ spring.application.name=greet-service
|
||||
|
||||
spring.boot.admin.client.url=http://localhost:8080
|
||||
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
||||
#Required for this application to connect to SBA
|
||||
spring.boot.admin.client.username=admin
|
||||
spring.boot.admin.client.password=admin
|
||||
|
||||
|
||||
#basic auth creddentials
|
||||
spring.security.user.name=client
|
||||
spring.security.user.password=client
|
||||
|
||||
|
||||
#configs to give secured server info to SBA while registering
|
||||
spring.boot.admin.client.instance.metadata.user.name= ${spring.security.user.name}
|
||||
spring.boot.admin.client.instance.metadata.user.password=${spring.security.user.password}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -15,7 +16,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -30,7 +31,10 @@
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -2,14 +2,39 @@ package com.example.springadminserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.AdminServerProperties;
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAdminServer
|
||||
public class SpringAdminServerApplication {
|
||||
|
||||
private final String adminContextPath;
|
||||
|
||||
public SpringAdminServerApplication(AdminServerProperties adminServerProperties) {
|
||||
this.adminContextPath = adminServerProperties.getContextPath();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringAdminServerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityWebFilterChain securityWebFilterChainSecure(ServerHttpSecurity http) {
|
||||
|
||||
return http.authorizeExchange()
|
||||
.pathMatchers(adminContextPath + "/assets/**").permitAll()
|
||||
.pathMatchers(adminContextPath + "/login").permitAll()
|
||||
.anyExchange().authenticated()
|
||||
.and().formLogin().loginPage(adminContextPath + "/login")
|
||||
.and().logout().logoutUrl(adminContextPath + "/logout")
|
||||
.and().httpBasic()
|
||||
.and().csrf().disable().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
spring.security.user.name=admin
|
||||
spring.security.user.password=admin
|
||||
|
||||
Reference in New Issue
Block a user