Closed damon008 closed 2 years ago
Spring cloud security has migrated to spring cloud gateway (for its part)
Spring cloud security 已经迁移到spring cloud gateway(就其本身而言)
What? How about Oauth2?
spring-security-oauth2 has never been part of Spring cloud
The access token relay filter is now part of Spring cloud gateway https://github.com/spring-cloud/spring-cloud-gateway/blob/main/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/TokenRelayGatewayFilterFactory.java
The access token relay filter is now part of Spring cloud gateway https://github.com/spring-cloud/spring-cloud-gateway/blob/main/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/TokenRelayGatewayFilterFactory.java
@spencergibb What about clients of oauth2? For example, Resource Server. How to authenticate?
@spencergibb Base on
Springboot version:2.5.6
Springcloud version: 2020.0.4
Spring cloud Security version: 2.2.5.RELEASE
How can use Oauth2 for Resource Server? for some examples?
Mine:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/v2/api-docs", "/swagger-resources/configuration/ui",
"/swagger-resources","/swagger-resources/configuration/security",
"/swagger-ui.html","/css/**", "/js/**","/images/**", "/webjars/**", "**/favicon.ico", "/index",
"/public/", "/static/", "/css/**", "/js/**", "/plugins/**", "/favicon.ico", "/images/**");
}
}
but it throw a exception:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.commons.security.ResourceServerTokenRelayAutoConfiguration$ResourceServerTokenRelayRegistrationAutoConfiguration': Unsatisfied dependency expressed through field 'accessTokenContextRelay'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.commons.security.AccessTokenContextRelay' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Description:
Field accessTokenContextRelay in org.springframework.cloud.commons.security.ResourceServerTokenRelayAutoConfiguration$ResourceServerTokenRelayRegistrationAutoConfiguration required a bean of type 'org.springframework.cloud.commons.security.AccessTokenContextRelay' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.cloud.commons.security.AccessTokenContextRelay' in your configuration.
@damon008 I met exactly the same problem and resolved it. Problem in fact is simple, just because some security code had moved to Spring-cloud-common,so , you have 2 sets currently, you just need exclude old set. Then you will be fine.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-security</artifactId>
</exclusion>
</exclusions>
</dependency>
Describe the bug Base on
I use these, but I found a bug:
but I also found the bug on 2.4.x of Springboot and 2020.0.x of spring cloud version.
Sample pom.xml: