|
|
|
@ -2,10 +2,12 @@ package org.dromara.common.security.config;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.SaManager;
|
|
|
|
|
import cn.dev33.satoken.filter.SaServletFilter;
|
|
|
|
|
import cn.dev33.satoken.httpauth.basic.SaHttpBasicUtil;
|
|
|
|
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
|
|
|
|
import cn.dev33.satoken.same.SaSameUtil;
|
|
|
|
|
import cn.dev33.satoken.util.SaResult;
|
|
|
|
|
import org.dromara.common.core.constant.HttpStatus;
|
|
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
@ -35,7 +37,7 @@ public class SecurityConfiguration implements WebMvcConfigurer {
|
|
|
|
|
public SaServletFilter getSaServletFilter() {
|
|
|
|
|
return new SaServletFilter()
|
|
|
|
|
.addInclude("/**")
|
|
|
|
|
.addExclude("/actuator/**")
|
|
|
|
|
.addExclude("/actuator", "/actuator/**")
|
|
|
|
|
.setAuth(obj -> {
|
|
|
|
|
if (SaManager.getConfig().getCheckSameToken()) {
|
|
|
|
|
SaSameUtil.checkCurrentRequestToken();
|
|
|
|
@ -44,4 +46,19 @@ public class SecurityConfiguration implements WebMvcConfigurer {
|
|
|
|
|
.setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 对 actuator 健康检查接口 做账号密码鉴权
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public SaServletFilter actuatorFilter() {
|
|
|
|
|
String username = SpringUtils.getProperty("spring.cloud.nacos.discovery.metadata.username");
|
|
|
|
|
String password = SpringUtils.getProperty("spring.cloud.nacos.discovery.metadata.userpassword");
|
|
|
|
|
return new SaServletFilter()
|
|
|
|
|
.addInclude("/actuator", "/actuator/**")
|
|
|
|
|
.setAuth(obj -> {
|
|
|
|
|
SaHttpBasicUtil.check(username + ":" + password);
|
|
|
|
|
})
|
|
|
|
|
.setError(e -> SaResult.error(e.getMessage()).setCode(HttpStatus.UNAUTHORIZED));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|