|
@@ -17,11 +17,16 @@
|
|
|
|
|
|
package com.pig4cloud.pigx.common.security.component;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
|
+import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
|
|
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
|
|
@@ -36,7 +41,11 @@ import org.springframework.web.client.RestTemplate;
|
|
|
* 1. 支持remoteTokenServices 负载均衡
|
|
|
* 2. 支持 获取用户全部信息
|
|
|
*/
|
|
|
-public abstract class BaseResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {
|
|
|
+@Slf4j
|
|
|
+@Configuration
|
|
|
+@EnableResourceServer
|
|
|
+@EnableGlobalMethodSecurity(prePostEnabled = true)
|
|
|
+public class BaseResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {
|
|
|
@Autowired
|
|
|
protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint;
|
|
|
@Autowired
|
|
@@ -45,16 +54,28 @@ public abstract class BaseResourceServerConfigurerAdapter extends ResourceServer
|
|
|
protected RemoteTokenServices remoteTokenServices;
|
|
|
@Autowired
|
|
|
protected UserDetailsService userDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private PermitAllUrlProperties permitAllUrlProperties;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 默认的配置,对外暴露
|
|
|
*
|
|
|
- * @param http
|
|
|
+ * @param httpSecurity
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
- public abstract void configure(HttpSecurity http) throws Exception;
|
|
|
+ public void configure(HttpSecurity httpSecurity) throws Exception {
|
|
|
+ //允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
|
|
|
+ httpSecurity.headers().frameOptions().disable();
|
|
|
+ ExpressionUrlAuthorizationConfigurer<HttpSecurity>
|
|
|
+ .ExpressionInterceptUrlRegistry registry = httpSecurity
|
|
|
+ .authorizeRequests();
|
|
|
+ permitAllUrlProperties.getIgnoreUrls()
|
|
|
+ .forEach(url -> registry.antMatchers(url).permitAll());
|
|
|
+ registry.anyRequest().authenticated()
|
|
|
+ .and().csrf().disable();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 提供子类重写
|