springbootcookieshiro前端权限
springboot 前后端分离使用shiro进行权限控制并使用cors进行跨域
本来框架已经搭好了并且持续运行了一段时间前端已经能够拿到后台传过去的数据,cors配置
@Configuration
//@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://192.168.1.141:8080","http://127.0.0.1:8080")
.allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
.allowCredentials(true).maxAge(3600);
}
/*private CorsConfiguration buildConfig(){
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("http://192.168.1.141:8080");
config.addAllowedOrigin("http://127.0.0.1:8080");
config.addAllowedHeader("*");
config.addAllowedMethod(HttpMethod.GET);
config.addAllowedMethod(HttpMethod.POST);
config.addAllowedMethod(HttpMethod.PUT);
config.addAllowedMethod(HttpMethod.DELETE);
config.addAllowedMethod(HttpMethod.OPTIONS);
return config;
}
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", buildConfig());
return new CorsFilter(configSource);
}*/
}
但是今天前端请求菜单接口的时候报302问题(注:今天之前请求菜单接口是可以跨域返回数据的),不明觉厉,弄了很久还是没有弄好。
前端也加了
xhrFields: {
withCredentials: true
},
crossDomain: true,