My problem is Cloudgateway security with Oauth2. However, Oauth2's config @EnableOAuth2Sso
will cause the following error:
Description:
Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.
When I did the same with Zuul proxy on Eureka, everything worked fine. Please help me how to solve this problem.
This is Cloudgateway project and I'm trying to make it an Oauth2 client:
Config:
@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
I am using Oauth2 server by Authorization Code model, referring to this question: