添加SpringBoot Admin监控中心支持
This commit is contained in:
@@ -70,6 +70,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.permitAll()
|
.permitAll()
|
||||||
.antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求
|
.antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求
|
||||||
.permitAll()
|
.permitAll()
|
||||||
|
.antMatchers("/actuator/**")// 允许SpringBoot Admin 访问监控信息
|
||||||
|
.permitAll()
|
||||||
// .antMatchers("/**")//测试时全部运行访问
|
// .antMatchers("/**")//测试时全部运行访问
|
||||||
// .permitAll()
|
// .permitAll()
|
||||||
.anyRequest()// 除上面外的所有请求全部需要鉴权认证
|
.anyRequest()// 除上面外的所有请求全部需要鉴权认证
|
||||||
|
|||||||
@@ -17,4 +17,12 @@ eureka:
|
|||||||
register-with-eureka: true
|
register-with-eureka: true
|
||||||
fetch-registry: true
|
fetch-registry: true
|
||||||
service-url:
|
service-url:
|
||||||
defaultZone: http://localhost:8001/eureka/
|
defaultZone: http://localhost:8001/eureka/
|
||||||
|
management: #开启SpringBoot Admin的监控
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: '*'
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
@@ -34,6 +34,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers("/").authenticated()//该路径需要登录认证
|
.antMatchers("/").authenticated()//该路径需要登录认证
|
||||||
// .antMatchers("/brand/list").hasAuthority("TEST")//该路径需要TEST权限
|
// .antMatchers("/brand/list").hasAuthority("TEST")//该路径需要TEST权限
|
||||||
.antMatchers("/**").permitAll()
|
.antMatchers("/**").permitAll()
|
||||||
|
.antMatchers("/actuator/**")// 允许SpringBoot Admin 访问监控信息
|
||||||
|
.permitAll()
|
||||||
.and()//启用基于http的认证
|
.and()//启用基于http的认证
|
||||||
.httpBasic()
|
.httpBasic()
|
||||||
.realmName("/")
|
.realmName("/")
|
||||||
|
|||||||
@@ -32,3 +32,11 @@ eureka:
|
|||||||
fetch-registry: true
|
fetch-registry: true
|
||||||
service-url:
|
service-url:
|
||||||
defaultZone: http://localhost:8001/eureka/
|
defaultZone: http://localhost:8001/eureka/
|
||||||
|
management: #开启SpringBoot Admin的监控
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: '*'
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
|
|||||||
31
mall-monitor/.gitignore
vendored
Normal file
31
mall-monitor/.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**
|
||||||
|
!**/src/test/**
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
41
mall-monitor/pom.xml
Normal file
41
mall-monitor/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?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"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.macro.mall</groupId>
|
||||||
|
<artifactId>mall-monitor</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>mall-monitor</name>
|
||||||
|
<description>mall-monitor project for mall</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.macro.mall</groupId>
|
||||||
|
<artifactId>mall</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<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>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.macro.mall;
|
||||||
|
|
||||||
|
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableAdminServer
|
||||||
|
@SpringBootApplication
|
||||||
|
public class MallMonitorApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MallMonitorApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.macro.mall.config;
|
||||||
|
|
||||||
|
import de.codecentric.boot.admin.server.config.AdminServerProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
|
||||||
|
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by macro on 2019/9/30.
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
private final String adminContextPath;
|
||||||
|
|
||||||
|
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
|
||||||
|
this.adminContextPath = adminServerProperties.getContextPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
|
||||||
|
successHandler.setTargetUrlParameter("redirectTo");
|
||||||
|
successHandler.setDefaultTargetUrl(adminContextPath + "/");
|
||||||
|
|
||||||
|
http.authorizeRequests()
|
||||||
|
//1.配置所有静态资源和登录页可以公开访问
|
||||||
|
.antMatchers(adminContextPath + "/assets/**").permitAll()
|
||||||
|
.antMatchers(adminContextPath + "/login").permitAll()
|
||||||
|
.anyRequest().authenticated()
|
||||||
|
.and()
|
||||||
|
//2.配置登录和登出路径
|
||||||
|
.formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and()
|
||||||
|
.logout().logoutUrl(adminContextPath + "/logout").and()
|
||||||
|
//3.开启http basic支持,admin-client注册时需要使用
|
||||||
|
.httpBasic().and()
|
||||||
|
.csrf()
|
||||||
|
//4.开启基于cookie的csrf保护
|
||||||
|
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
|
||||||
|
//5.忽略这些路径的csrf保护以便admin-client注册
|
||||||
|
.ignoringAntMatchers(
|
||||||
|
adminContextPath + "/instances",
|
||||||
|
adminContextPath + "/actuator/**"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
mall-monitor/src/main/resources/application.yml
Normal file
19
mall-monitor/src/main/resources/application.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: mall-monitor
|
||||||
|
security: # 配置登录用户名和密码
|
||||||
|
user:
|
||||||
|
name: macro
|
||||||
|
password: 123456
|
||||||
|
boot: # 不显示admin-server的监控信息
|
||||||
|
admin:
|
||||||
|
discovery:
|
||||||
|
ignored-services: ${spring.application.name}
|
||||||
|
server:
|
||||||
|
port: 8101
|
||||||
|
eureka:
|
||||||
|
client:
|
||||||
|
register-with-eureka: true
|
||||||
|
fetch-registry: true
|
||||||
|
service-url:
|
||||||
|
defaultZone: http://localhost:8001/eureka/
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.macro.mall;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class MallMonitorApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -51,6 +51,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.permitAll()
|
.permitAll()
|
||||||
.antMatchers("/member/**","/returnApply/**")// 测试时开启
|
.antMatchers("/member/**","/returnApply/**")// 测试时开启
|
||||||
.permitAll()
|
.permitAll()
|
||||||
|
.antMatchers("/actuator/**")// 允许SpringBoot Admin 访问监控信息
|
||||||
|
.permitAll()
|
||||||
.anyRequest()// 除上面外的所有请求全部需要鉴权认证
|
.anyRequest()// 除上面外的所有请求全部需要鉴权认证
|
||||||
.authenticated()
|
.authenticated()
|
||||||
.and()
|
.and()
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ spring:
|
|||||||
host: localhost # Redis服务器地址
|
host: localhost # Redis服务器地址
|
||||||
database: 0 # Redis数据库索引(默认为0)
|
database: 0 # Redis数据库索引(默认为0)
|
||||||
port: 6379 # Redis服务器连接端口
|
port: 6379 # Redis服务器连接端口
|
||||||
password: # Redis服务器连接密码(默认为空)
|
password: 123456 # Redis服务器连接密码(默认为空)
|
||||||
jedis:
|
jedis:
|
||||||
pool:
|
pool:
|
||||||
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
max-active: 8 # 连接池最大连接数(使用负值表示没有限制)
|
||||||
@@ -48,4 +48,12 @@ eureka:
|
|||||||
fetch-registry: true
|
fetch-registry: true
|
||||||
service-url:
|
service-url:
|
||||||
defaultZone: http://localhost:8001/eureka/
|
defaultZone: http://localhost:8001/eureka/
|
||||||
|
management: #开启SpringBoot Admin的监控
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: '*'
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
|
|
||||||
|
|||||||
@@ -22,4 +22,12 @@ eureka:
|
|||||||
register-with-eureka: true
|
register-with-eureka: true
|
||||||
fetch-registry: true
|
fetch-registry: true
|
||||||
service-url:
|
service-url:
|
||||||
defaultZone: http://localhost:8001/eureka/
|
defaultZone: http://localhost:8001/eureka/
|
||||||
|
management: #开启SpringBoot Admin的监控
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: '*'
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: always
|
||||||
7
pom.xml
7
pom.xml
@@ -41,6 +41,7 @@
|
|||||||
<jjwt.version>0.9.0</jjwt.version>
|
<jjwt.version>0.9.0</jjwt.version>
|
||||||
<aliyun-oss.version>2.5.0</aliyun-oss.version>
|
<aliyun-oss.version>2.5.0</aliyun-oss.version>
|
||||||
<logstash-logback.version>5.3</logstash-logback.version>
|
<logstash-logback.version>5.3</logstash-logback.version>
|
||||||
|
<admin-starter-server.version>2.1.5</admin-starter-server.version>
|
||||||
<mall-common.version>1.0-SNAPSHOT</mall-common.version>
|
<mall-common.version>1.0-SNAPSHOT</mall-common.version>
|
||||||
<mall-mbg.version>1.0-SNAPSHOT</mall-mbg.version>
|
<mall-mbg.version>1.0-SNAPSHOT</mall-mbg.version>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -164,6 +165,12 @@
|
|||||||
<artifactId>logstash-logback-encoder</artifactId>
|
<artifactId>logstash-logback-encoder</artifactId>
|
||||||
<version>${logstash-logback.version}</version>
|
<version>${logstash-logback.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--集成SpringBoot Admin监控-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.codecentric</groupId>
|
||||||
|
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||||
|
<version>${admin-starter-server.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user