Skip to content

Allow to redirect after login to a specific page by setting SPRING_SECURITY_SAVED_REQUEST attribute#226

Merged
f-necas merged 2 commits intomainfrom
add-redirect-attribute
Sep 29, 2025
Merged

Allow to redirect after login to a specific page by setting SPRING_SECURITY_SAVED_REQUEST attribute#226
f-necas merged 2 commits intomainfrom
add-redirect-attribute

Conversation

@f-necas
Copy link
Copy Markdown
Collaborator

@f-necas f-necas commented Sep 25, 2025

Use SPRING_SECURITY_SAVED_REQUEST key attribute to set redirect URI when using an url like /login?redirect=myurl

https://github.com/spring-projects/spring-security/blob/main/web/src/main/java/org/springframework/security/web/server/savedrequest/WebSessionServerRequestCache.java#L55

@f-necas f-necas force-pushed the add-redirect-attribute branch from 9e146fe to debf068 Compare September 26, 2025 07:31
@f-necas f-necas merged commit b388a9e into main Sep 29, 2025
3 checks passed
@f-necas f-necas deleted the add-redirect-attribute branch September 29, 2025 11:35
@github-actions
Copy link
Copy Markdown

💚 All backports created successfully

Status Branch Result
2.0.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

github-actions bot added a commit that referenced this pull request Sep 29, 2025
[2.0.x] Merge pull request #226 from georchestra/add-redirect-attribute
Copy link
Copy Markdown
Member

@pmauduit pmauduit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I don't get: is it enough to just save the parameter in GET to the session attributes using the SPRING_SECURITY_SAVED_REQUEST key ? Where would the actual redirection to the expected page take place ?

We don't need to explicitely instanciate a WebSessionServerRequestCache as pointed in the PR description ?


The Gateway allows redirection with a query parameter on login page to URLs specified in the `gateway.yaml` file.

It's a startWith match, so you can specify a whole path or just the beginning of it.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a startsWith match

@pmauduit
Copy link
Copy Markdown
Member

pmauduit commented Oct 7, 2025

We don't need to explicitely instanciate a WebSessionServerRequestCache as pointed in the PR description ?

a one is instanciated somewhere probably by spring, no need to explicitely create it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants