|
|
|
@ -10,12 +10,19 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
|
|
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
|
|
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
|
|
|
|
|
import ${basePackage}.frame.auth.LocalData;
|
|
|
|
|
import ${basePackage}.frame.base.Token;
|
|
|
|
|
import ${basePackage}.frame.utils.CookieUtil;
|
|
|
|
|
import ${basePackage}.frame.auth.LocalData;
|
|
|
|
|
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.*;
|
|
|
|
|
import ${basePackage}.module.system.mgr.TokensManager;
|
|
|
|
|
import ${basePackage}.module.system.req.TokensBuildRequest;
|
|
|
|
|
import ${basePackage}.module.system.rsp.TokensBuildResponse;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.Filter;
|
|
|
|
|
import javax.servlet.FilterChain;
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.ServletRequest;
|
|
|
|
|
import javax.servlet.ServletResponse;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
@ -31,6 +38,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
private String[] excluded;
|
|
|
|
|
@Value("${r"${spring.mvc.static-path-pattern}"}")
|
|
|
|
|
private String[] staticPath;
|
|
|
|
|
@Value("${r'${web.login.page}'}")
|
|
|
|
|
private String loginPage;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configure(WebSecurity web) throws Exception {
|
|
|
|
@ -42,7 +51,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
|
|
|
|
.and()
|
|
|
|
|
.addFilterBefore(new TokenFilter(), FilterSecurityInterceptor.class)// 过滤器用于处理Token
|
|
|
|
|
.authorizeRequests()
|
|
|
|
|
.formLogin().loginPage(loginPage)
|
|
|
|
|
.and().authorizeRequests()
|
|
|
|
|
.antMatchers(excluded).permitAll()// 放行排除的URL
|
|
|
|
|
.antMatchers(included).access("@Authorization.hasPermission(request,authentication)")// 需要权限的URL
|
|
|
|
|
.and().cors()
|
|
|
|
@ -77,15 +87,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
LocalData.setToken(LocalData.getTempToken());
|
|
|
|
|
} else {
|
|
|
|
|
// 组装Token ~ 这边根据实际的业务组装Token
|
|
|
|
|
Token token1 = new Token();
|
|
|
|
|
token1.setId(1L);
|
|
|
|
|
token1.setUserId(1L);
|
|
|
|
|
token1.setUserName("admin");
|
|
|
|
|
//继承临时Token
|
|
|
|
|
token1.addResourceSet(LocalData.getTempToken());
|
|
|
|
|
//管理员特有资源(这边请用正则表达式)
|
|
|
|
|
token1.putResource(".*");
|
|
|
|
|
LocalData.setToken(token1);
|
|
|
|
|
TokensManager tokensManager = LocalData.getBean(TokensManager.class);
|
|
|
|
|
TokensBuildRequest tokensBuildRequest = new TokensBuildRequest();
|
|
|
|
|
tokensBuildRequest.setToken(token);
|
|
|
|
|
TokensBuildResponse tokensBuildResponse = tokensManager.build(tokensBuildRequest, LocalData.getSysToken());
|
|
|
|
|
if (tokensBuildResponse.hasError()) {
|
|
|
|
|
LocalData.setToken(LocalData.getTempToken());
|
|
|
|
|
} else {
|
|
|
|
|
Token token_ = tokensBuildResponse.getToken();
|
|
|
|
|
LocalData.setToken(token_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Action
|
|
|
|
|