更新CORS过滤器实现

pull/76/head
fengshuonan 2021-06-08 15:23:05 +08:00
parent 8323365725
commit 5da3081451
2 changed files with 2 additions and 41 deletions

View File

@ -1,36 +0,0 @@
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;
}
}

View File

@ -3,6 +3,7 @@ package cn.stylefeng.guns.config.web;
import cn.stylefeng.guns.core.error.CustomErrorAttributes;
import cn.stylefeng.guns.core.security.AuthJwtTokenSecurityInterceptor;
import cn.stylefeng.guns.core.security.PermissionSecurityInterceptor;
import cn.stylefeng.roses.kernel.security.cors.CorsFilterConfiguration;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
@ -21,7 +22,7 @@ import javax.annotation.Resource;
* @date 2020/4/11 10:23
*/
@Configuration
@Import({cn.hutool.extra.spring.SpringUtil.class})
@Import({cn.hutool.extra.spring.SpringUtil.class, CorsFilterConfiguration.class})
public class SpringMvcConfiguration implements WebMvcConfigurer {
@Resource
@ -30,9 +31,6 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
@Resource
private PermissionSecurityInterceptor permissionSecurityInterceptor;
@Resource
private OptionsSecurityInterceptor optionsSecurityInterceptor;
/**
*
*
@ -65,7 +63,6 @@ public class SpringMvcConfiguration implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authJwtTokenSecurityInterceptor);
registry.addInterceptor(permissionSecurityInterceptor);
registry.addInterceptor(optionsSecurityInterceptor);
}
/**