如果是OPTIONS则结束请求

This commit is contained in:
APLS 2020-04-13 22:20:54 +08:00
parent de9c974bbf
commit 9f49dbf8ec
2 changed files with 13 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationT
super(null); super(null);
this.code = code; this.code = code;
super.setAuthenticated(false); super.setAuthenticated(false);
logger.info("MobileLoginAuthenticationToken setAuthenticated ->false loading ..."); logger.info("创建未认证的用户名密码认证对象1 setAuthenticated ->false loading ...");
} }
// 创建未认证的用户名密码认证对象 // 创建未认证的用户名密码认证对象
@ -50,7 +50,7 @@ public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationT
this.code = code; this.code = code;
this.state = state; this.state = state;
super.setAuthenticated(false); super.setAuthenticated(false);
logger.info("MobileLoginAuthenticationToken setAuthenticated ->false loading ..."); logger.info("创建未认证的用户名密码认证对象2 setAuthenticated ->false loading ...");
} }

View File

@ -7,6 +7,8 @@ import com.google.gson.JsonParser;
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
import io.qyi.e5.util.SpringUtil; import io.qyi.e5.util.SpringUtil;
import io.qyi.e5.util.redis.RedisUtil; import io.qyi.e5.util.redis.RedisUtil;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
@ -50,10 +52,16 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter {
HttpServletResponse response = httpServletResponse; HttpServletResponse response = httpServletResponse;
response.setHeader("Access-Control-Allow-Origin","*"); response.setHeader("Access-Control-Allow-Origin","*");
response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT"); response.setHeader("Access-Control-Allow-Methods", "\"GET, HEAD, POST");
response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token");
filterChain.doFilter(httpServletRequest, httpServletResponse); /*如果是OPTIONS则结束请求*/
if (HttpMethod.OPTIONS.toString().equals(httpServletRequest.getMethod())) {
response.setStatus(HttpStatus.NO_CONTENT.value());
} else {
filterChain.doFilter(httpServletRequest, response);
}
} }
public void sendJson(HttpServletResponse httpServletResponse, Object o) throws IOException { public void sendJson(HttpServletResponse httpServletResponse, Object o) throws IOException {