|
|
@ -3,6 +3,7 @@ package ${basePackage}.config;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
import org.springframework.security.access.AccessDeniedException;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
@ -24,6 +25,7 @@ import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.ServletRequest;
|
|
|
|
import javax.servlet.ServletRequest;
|
|
|
|
import javax.servlet.ServletResponse;
|
|
|
|
import javax.servlet.ServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
@ -77,6 +79,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
|
|
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
|
|
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
|
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
|
|
|
|
|
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
|
|
String token = request.getParameter("token");
|
|
|
|
String token = request.getParameter("token");
|
|
|
|
if (token == null || token.isEmpty()) {
|
|
|
|
if (token == null || token.isEmpty()) {
|
|
|
|
token = CookieUtil.getCookieValue(request.getCookies(), "token");
|
|
|
|
token = CookieUtil.getCookieValue(request.getCookies(), "token");
|
|
|
@ -88,9 +91,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
TokensBuildRequest tokensBuildRequest = new TokensBuildRequest();
|
|
|
|
TokensBuildRequest tokensBuildRequest = new TokensBuildRequest();
|
|
|
|
tokensBuildRequest.setToken(token);
|
|
|
|
tokensBuildRequest.setToken(token);
|
|
|
|
TokensBuildResponse tokensBuildResponse = tokensManager.build(tokensBuildRequest, LocalData.getSysToken());
|
|
|
|
TokensBuildResponse tokensBuildResponse = tokensManager.build(tokensBuildRequest, LocalData.getSysToken());
|
|
|
|
if (!tokensBuildResponse.hasError()) {
|
|
|
|
|
|
|
|
LocalData.setToken(tokensBuildResponse.getToken());
|
|
|
|
LocalData.setToken(tokensBuildResponse.getToken());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
LocalData.setToken(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Action
|
|
|
|
// Action
|
|
|
@ -101,7 +104,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
LocalData.setAction(matcher.group(1));
|
|
|
|
LocalData.setAction(matcher.group(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
|
|
|
|
} catch (AccessDeniedException e) {
|
|
|
|
|
|
|
|
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|