【7.0.3】增加跨域拦截器

pull/72/head
fengshuonan 4 years ago
parent 6d6af15c06
commit 55c658b50f

@ -0,0 +1,36 @@
package cn.stylefeng.guns.config.web;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*
* @author fengshuonan
* @date 2021/4/13 18:24
*/
@Component
@Slf4j
public class OptionsSecurityInterceptor implements HandlerInterceptor {
/**
* header
*
* @author fengshuonan
* @date 2021/4/13 18:24
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Authorization");
response.setHeader("Access-Control-Allow-Credentials", "true");
return true;
}
}

@ -32,6 +32,9 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
@Resource
private PermissionSecurityInterceptor permissionSecurityInterceptor;
@Resource
private OptionsSecurityInterceptor optionsSecurityInterceptor;
/**
*
*
@ -78,6 +81,7 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authJwtTokenSecurityInterceptor);
registry.addInterceptor(permissionSecurityInterceptor);
registry.addInterceptor(optionsSecurityInterceptor);
}
/**

Loading…
Cancel
Save