Commit 0b080fcc authored by zhouqian's avatar zhouqian

Merge branch 'master' of http://gitabc.xyqb.com/head_group/xyqb-user2

# Conflicts:
#	src/main/java/cn/quantgroup/xyqb/Constants.java
parent ab2a91da
......@@ -19,27 +19,28 @@ import java.io.PrintWriter;
* Created by 11 on 2016/12/29.
*/
@WebFilter(urlPatterns = "/*")
@WebInitParam(name = "pathPattern", value = "/innerapi/**,/user/exist,/user/register,/user/login,/user/register/fast,/user/login/fast,/api/sms/**,/user/reset_password,/user/exist_check,/jr58/**,/app/login,/config/**,/api/**,/user/exists_token")
@WebInitParam(name = "pathPatterns", value = "/innerapi/**,/user/exist,/user/register,/user/login,/user/register/fast,/user/login/fast,/api/sms/**,/user/reset_password,/user/exist_check,/jr58/**,/app/login,/config/**,/api/**,/user/exists_token")
public class RequestFilter implements Filter {
private String pathPattern;
private String [] pathPatterns;
private AntPathMatcher matcher = new AntPathMatcher();
@Override
public void init(FilterConfig filterConfig) throws ServletException {
pathPattern = filterConfig.getInitParameter("pathPattern");
pathPatterns = filterConfig.getInitParameter("pathPatterns").split(",");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String requestPath = request.getRequestURI();
AntPathMatcher matcher = new AntPathMatcher();
boolean match = matcher.match(requestPath, pathPattern);
if(match){
String requestPath = getRequestPath(request);
if(isMatch(requestPath)){
//获取session信息,如果没有获取到session信息则返回错误信息
SessionStruct sessionStruct = XyqbSessionContextHolder.getXSession();
if(sessionStruct == null){
if(sessionStruct == null) {
response.setStatus(200);
response.
PrintWriter out = response.getWriter();
JsonResult result = JsonResult.buildErrorStateResult("登录失败", null);
out.print(JSONObject.toJSONString(result));
......@@ -50,6 +51,24 @@ public class RequestFilter implements Filter {
filterChain.doFilter(request, response);
}
private boolean isMatch(String path) {
for (String pattern : pathPatterns) {
if (matcher.match(path, pattern)) {
return true;
}
}
return false;
}
private String getRequestPath(HttpServletRequest request) {
String url = request.getServletPath();
if (request.getPathInfo() != null) {
url += request.getPathInfo();
}
return url;
}
@Override
public void destroy() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment