Skip to content

Commit

Permalink
调整跨域配置,更新README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dolyw committed Jan 14, 2020
1 parent 7aaa8b4 commit 0639645
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

> 前端地址:[https://github.com/wang926454/VueStudy/tree/master/VueStudy08-JWT](https://github.com/wang926454/VueStudy/tree/master/VueStudy08-JWT)
#### Issues
#### 疑问查看

1. [#14 重复请求会不会生成多个token](https://github.com/dolyw/ShiroJwt/issues/14)
2. [#19 跨域sso问题](https://github.com/dolyw/ShiroJwt/issues/19)
3. [#22 如果是微服务的话,是不是每个微服务都的写一套这样的shiro?](https://github.com/dolyw/ShiroJwt/issues/22)
3. [#29 Token刷新并发处理](https://github.com/dolyw/ShiroJwt/issues/29)

<img src="https://cdn.jsdelivr.net/gh/wliduo/CDN@master/feed/qq.png" height="180"></img>

Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/wang/config/OriginFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.wang.config;

import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* 全局跨域放开
*
* @author wliduo[[email protected]]
* @date 2019/11/26 14:29
*/
@Component
public class OriginFilter implements Filter {

@Override
public void init(FilterConfig filterConfig) throws ServletException { }

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpServletResponse.setHeader("Access-Control-Allow-Headers", httpServletRequest.getHeader("Access-Control-Request-Headers"));
filterChain.doFilter(request, response);
}

@Override
public void destroy() { }

}
21 changes: 0 additions & 21 deletions src/main/java/com/wang/config/WebMvcConfig.java

This file was deleted.

5 changes: 3 additions & 2 deletions src/main/java/com/wang/config/shiro/jwt/JwtFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ protected boolean executeLogin(ServletRequest request, ServletResponse response)
*/
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
// 跨域已经在OriginFilter处全局配置
/*HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
httpServletResponse.setHeader("Access-control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE");
Expand All @@ -142,7 +143,7 @@ protected boolean preHandle(ServletRequest request, ServletResponse response) th
if (httpServletRequest.getMethod().equals(RequestMethod.OPTIONS.name())) {
httpServletResponse.setStatus(HttpStatus.OK.value());
return false;
}
}*/
return super.preHandle(request, response);
}

Expand Down

0 comments on commit 0639645

Please sign in to comment.