Java Spring boot将云网关与Oauth2一起使用
我的问题是Oauth2的Cloudgateway安全性。但是,Oauth2的configJava Spring boot将云网关与Oauth2一起使用,java,spring-boot,oauth-2.0,spring-security-oauth2,spring-cloud-gateway,Java,Spring Boot,Oauth 2.0,Spring Security Oauth2,Spring Cloud Gateway,我的问题是Oauth2的Cloudgateway安全性。但是,Oauth2的config@enableAuth2sso将导致以下错误: 说明: org.springframework.cloud.gateway.config.GatewayAutoConfiguration中方法modifyRequestBodyGatewayFilterFactory的参数0需要找不到类型为“org.springframework.http.codec.ServerCodeConfigurer”的bean 行动
@enableAuth2sso
将导致以下错误:
说明:
org.springframework.cloud.gateway.config.GatewayAutoConfiguration中方法modifyRequestBodyGatewayFilterFactory的参数0需要找不到类型为“org.springframework.http.codec.ServerCodeConfigurer”的bean
行动:
考虑在配置中定义“org.springframework.http.codec.servercodeconfigurer”类型的bean
当我在尤里卡上使用Zuul代理时,一切都很好。
请帮我解决这个问题
这是Cloudgateway项目,我正在尝试使其成为Oauth2客户端:
配置:
@Configuration
@EnableOAuth2Sso
public class UiSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**")
.permitAll()
.anyRequest()
.authenticated();
}
}
application.yml:
server:
port: 8080
servlet:
session:
cookie:
name: UISESSION
security:
oauth2:
client:
clientId: SampleClientId
clientSecret: secret
accessTokenUri: http://localhost:8085/auth/oauth/token
userAuthorizationUri: http://localhost:8085/auth/oauth/authorize
resource:
userInfoUri: http://localhost:8085/auth/principal
spring:
application:
name: gateway
cloud:
gateway:
discovery:
locator:
enabled: false
routes:
- id: microservice1WelcomeRoute
uri: http://localhost:8083/view/welcome
predicates:
- Path=/microservice1/welcome
我使用的是Oauth2服务器授权码模型,指的是:SpringCloudGateway依赖于SpringWebFlux(它使用NettyWeb服务器), SpringCloudOAuth2依赖于SpringBootWeb(使用TomcatWeb服务器)。。。不能同时使用两个web服务器 依赖关系图(仅重要): (一) (二) 总之,如果排除Tomcat依赖项,它可能会工作 e、 g(代表格拉德尔)
SpringCloudGateway依赖于SpringWebFlux(使用NettyWeb服务器), SpringCloudOAuth2依赖于SpringBootWeb(使用TomcatWeb服务器)。。。不能同时使用两个web服务器 依赖关系图(仅重要): (一) (二) 总之,如果排除Tomcat依赖项,它可能会工作 e、 g(代表格拉德尔) 您可能想知道和链接的问题您可能想知道和链接的问题
* org.springframework.cloud:spring-cloud-starter-gateway:2.0.1.RELEASE
|-* org.springframework.boot:spring-boot-starter-webflux:2.0.5.RELEASE
|-* org.springframework.boot:spring-boot-starter-reactor-netty:2.0.5.RELEASE
* org.springframework.cloud:spring-cloud-starter-oauth2:2.0.0.RELEASE
|-* org.springframework.cloud:spring-cloud-starter-security:2.0.0.RELEASE
|-*org.springframework.cloud:spring-cloud-security:2.0.0.RELEASE
|-*org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE
|-*org.springframework.boot:spring-boot-starter-tomcat:2.0.5.RELEASE
dependencies {
// ...
implementation('org.springframework.cloud:spring-cloud-starter-gateway')
implementation('org.springframework.cloud:spring-cloud-starter-oauth2') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
// ...
testImplementation('org.springframework.boot:spring-boot-starter-test')
}