修改monitor security 配置方式 解决类过期问题

This commit is contained in:
edgar 2022-06-08 11:03:54 +08:00
parent 6cebdacdae
commit 13fbfd301a
2 changed files with 33 additions and 25 deletions

View File

@ -35,8 +35,9 @@ public class YamlPropertySourceFactory implements PropertySourceFactory {
}
catch (IllegalStateException e) {
Throwable cause = e.getCause();
if (cause instanceof FileNotFoundException)
if (cause instanceof FileNotFoundException) {
throw (FileNotFoundException) e.getCause();
}
throw e;
}
}

View File

@ -18,9 +18,13 @@ package com.pig4cloud.pig.monitor.config;
import de.codecentric.boot.admin.server.config.AdminServerProperties;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
/**
@ -29,8 +33,8 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
* @author lishangbu
* @date 2019/2/1
*/
@Configuration(proxyBeanMethods = false)
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@EnableWebSecurity
public class WebSecurityConfigurer{
private final String adminContextPath;
@ -38,14 +42,17 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
@SneakyThrows
protected void configure(HttpSecurity http) {
// @formatter:off
/**
* spring security 默认的安全策略
* @param http security注入点
* @return SecurityFilterChain
* @throws Exception
*/
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/");
http
.headers().frameOptions().disable()
.and().authorizeRequests()
@ -63,7 +70,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
.httpBasic().and()
.csrf()
.disable();
// @formatter:on
return http.build();
}
}