Skip to content

Spring Security Reactive doesn't store scopedTarget.oauth2ClientContext into Redis #7564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zhaojunjie163 opened this issue Oct 24, 2019 · 4 comments
Assignees
Labels
for: external-project For an external project and not something we can fix

Comments

@zhaojunjie163
Copy link

zhaojunjie163 commented Oct 24, 2019

Hello Teams,
I'm using spring security oauth2 for single sign-on, and would like to use spring session to store oAuth2 information into Redis. so that we can scale horizontally. After debugging, I found spring security will not store scopedTarget.oauth2ClientContext into Redis by default, hence new instance will not able to get oAuth client information.

I found a similar issue on StackOverflow. but it's an old version. I'm currently using spring-security 5.2 and spring session 2.2. May I know can I achieve the same purpose in spring-security 5.2 in a reactive way(WebFlux)?

How to reproduce

A sample repo here: https://github.com/zhaojunjie163/sample.git
1.) Install Redis
2.) After authentication, if restart the application, then need to re-login, as scopedTarget.oauth2ClientContext not persist in Redis.

Configuration POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.0.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webflux</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
<!--Spring Session-->
		<dependency>
			<groupId>org.springframework.session</groupId>
			<artifactId>spring-session-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>

<!--Spring Security oAuth2-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-oauth2-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-oauth2-jose</artifactId>
		</dependency>

<!--Others-->
		<dependency>
			<groupId>io.projectreactor</groupId>
			<artifactId>reactor-core</artifactId>
		</dependency>

		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>io.projectreactor</groupId>
			<artifactId>reactor-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 24, 2019
@foo4u
Copy link

foo4u commented May 26, 2020

This is a major problem and no one must be using this in production with just Spring Security provided code. The problem is InMemoryReactiveOAuth2AuthorizedClientService is the only provided ReactiveOAuth2AuthorizedClientService.

I'm going to write one for Redis since this is blocking us as well.

@jgrandja
Copy link
Contributor

@zhaojunjie163

I found spring security will not store scopedTarget.oauth2ClientContext

It seems you are referring to Spring Security OAuth , as scopedTarget.oauth2ClientContext exists in that project NOT Spring Security.

I'm going to close this since it's not an issue in Spring Security's 5.x OAuth support.

FYI, please see #7889

@jgrandja jgrandja added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels May 27, 2020
@jgrandja jgrandja self-assigned this May 27, 2020
@jgrandja
Copy link
Contributor

jgrandja commented May 27, 2020

@foo4u Please see #7889

Instead of configuring InMemoryReactiveOAuth2AuthorizedClientService use WebSessionServerOAuth2AuthorizedClientRepository along with Spring Session backed by Redis. That should work for your setup.

@foo4u
Copy link

foo4u commented May 28, 2020

@jgrandja thanks for the info. That worked well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants