Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Had a Error when update springboot and Springcloud from Hoxton to 2020.0.4 #254

Open
damon008 opened this issue Nov 18, 2021 · 2 comments
Open

Comments

@damon008
Copy link

Describe the bug

In my client of Resource Server

Base on

Springboot version:2.5.6
Springcloud version: 2020.0.4
Spring cloud Security version(spring-cloud-starter-oauth2): 2.2.5.RELEASE
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.6</version>
        <relativePath/>
    </parent>
<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>2020.0.4</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

<dependencies>
          <dependency>
	          <groupId>org.springframework.cloud</groupId>
	          <artifactId>spring-cloud-starter-oauth2</artifactId>
	          <version>2.2.5.RELEASE</version>
          </dependency>
</dependencies>

How can use Oauth2 for Resource Server? for some examples?

The following code is mine

SecurityConfig.java

@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.

But, I can use SSO by Oauth2 for Resource Server (Client Demo) from the version:

Springboot version: 2.3.12
Springcloud version:  Hoxton.SR12
spring-cloud-starter-oauth2:  2.2.5.RELEASE

I Just update the version of springboot and Springcloud.

Springboot version:2.5.6
Springcloud version: 2020.0.4
Spring cloud Security version(spring-cloud-starter-oauth2): 2.2.5.RELEASE

===============================================

So Excuse me, is there an example of integrating SSO with spring cloud security? Didn't understand the migration guide. Thanks

@damon008
Copy link
Author

damon008 commented Nov 18, 2021

PS: I don't use ribbon or Feign,just use the new LB (spring-cloud-loadbalancer).

@damon008
Copy link
Author

damon008 commented Nov 18, 2021

In My Customer Service,Base on 2.5.6 of spring-boot version and 2020.0.4 of spring-cloud version, what can I use for Oauth2 and SSO if not spring-cloud-starter-oauth2?

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>

Because it is ok in my projects based on 2.3.12-RELEASE of spring-boot version and Hoxton-SR12 of spring-cloud version.

By using these annotations:@EnableOAuth2Sso,@EnableResourceServer,@EnableGlobalMethodSecurity and so on.

But, In newest version, How can I do for them?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants