|
|
@@ -0,0 +1,63 @@ |
|
|
|
package com.tuoheng.gateway.config; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
|
|
|
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; |
|
|
|
import org.springframework.security.config.web.server.ServerHttpSecurity; |
|
|
|
import org.springframework.security.web.server.SecurityWebFilterChain; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author chenjiandong |
|
|
|
* @description: TODO |
|
|
|
* @date 2022/9/28 13:53 |
|
|
|
*/ |
|
|
|
@Configuration |
|
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true) |
|
|
|
@EnableWebFluxSecurity |
|
|
|
public class WebSecurityConfig { |
|
|
|
|
|
|
|
/** |
|
|
|
* 需要登录后访问的接口 |
|
|
|
*/ |
|
|
|
public static String oauthUrlStr; |
|
|
|
|
|
|
|
/** |
|
|
|
* 不需要登录就可以访问的接口 |
|
|
|
*/ |
|
|
|
public static String permitUrlStr; |
|
|
|
|
|
|
|
@Value("${security.ignore.oauthUrls}") |
|
|
|
public void setOauthUrlStr(String oauthUrls) { |
|
|
|
oauthUrlStr = oauthUrls; |
|
|
|
} |
|
|
|
|
|
|
|
@Value("${security.ignore.permitUrls}") |
|
|
|
public void setPermitUrlStr(String permitUrls) { |
|
|
|
permitUrlStr = permitUrls; |
|
|
|
} |
|
|
|
|
|
|
|
@Bean |
|
|
|
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity){ |
|
|
|
String[] OAUTH_PATH = oauthUrlStr.split(","); |
|
|
|
String[] PERMIT_PATH = permitUrlStr.split(","); |
|
|
|
httpSecurity |
|
|
|
.authorizeExchange() |
|
|
|
.pathMatchers(OAUTH_PATH).authenticated() |
|
|
|
.pathMatchers(PERMIT_PATH).permitAll() |
|
|
|
.pathMatchers("/api/system/demo/test").hasAuthority("SCOPE_email") |
|
|
|
.anyExchange().permitAll() |
|
|
|
.and() |
|
|
|
.csrf() |
|
|
|
.disable() |
|
|
|
.cors(); |
|
|
|
httpSecurity.oauth2ResourceServer().jwt(); |
|
|
|
return httpSecurity.build(); |
|
|
|
} |
|
|
|
|
|
|
|
} |