end: 注释服务端跨域配置,由前端代理处理跨域。

This commit is contained in:
wangiegie@gmail.com 2017-11-13 17:05:02 +08:00
parent 3c7d16b0ff
commit 607ada9079
2 changed files with 17 additions and 21 deletions

View File

@ -5,12 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @author lengleng
@ -26,16 +21,17 @@ public class PigGatewayApplication {
SpringApplication.run(PigGatewayApplication.class, args);
}
@Bean
@Order(Integer.MAX_VALUE)
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
// 开发时候配置跨域现在使用vue-cli 自己的代理解决生成部署是用Nginx 代理
// @Bean
// @Order(Integer.MAX_VALUE)
// public CorsFilter corsFilter() {
// final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
// final CorsConfiguration corsConfiguration = new CorsConfiguration();
// corsConfiguration.setAllowCredentials(true);
// corsConfiguration.addAllowedOrigin("*");
// corsConfiguration.addAllowedHeader("*");
// corsConfiguration.addAllowedMethod("*");
// urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
// return new CorsFilter(urlBasedCorsConfigurationSource);
// }
}

View File

@ -27,10 +27,10 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
//ele-admin options 跨域配置
if (HttpMethod.OPTIONS.name().equalsIgnoreCase(request.getMethod())) {
return true;
}
//ele-admin options 跨域配置现在处理是通过前端配置代理不使用这种方式存在风险
// if (HttpMethod.OPTIONS.name().equalsIgnoreCase(request.getMethod())) {
// return true;
// }
Object principal = authentication.getPrincipal();
List<SimpleGrantedAuthority> grantedAuthorityList = (List<SimpleGrantedAuthority>) authentication.getAuthorities();
boolean hasPermission = false;