spring-projects / spring-projects/spring-security

Custom authorization logic when token exchange flow is triggered in Spring authorization server

Open
#19,480 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior
I want to be able to apply additional authorization checks during Token exchange flow (OAuth2TokenExchangeAuthenticationToken)

I have different kind of users, for simplification, let's assume administrator and normal user. I need to support a case that only Administrator can impersonate normal user, and only certain Administrators can do the impersonation

For time being, we can assume that information if user is an administrator can be deduced from his token claims. And to check if administrator can impersonate, a dedicated API call needs to be made to validate

I expect that

  1. When administrator who can do the impersonation, calls token endpoint with grant type: urn:ietf:params:oauth:grant-type:token-exchange, will receive http 200 response with impersonating token
  2. When user who cannot do the impersonation, calls token endpoint with grant type urn:ietf:params:oauth:grant-type:token-exchange, will receive an error. Can be 403/401, whatever is feasible

Current Behavior
There is no easy way at the moment to customize spring authorization server implementation to support the above. The only option, is to replace whole org.springframework.security.oauth2.server.authorization.authentication.OAuth2TokenExchangeAuthenticationProvider with custom implementation which will inject additional checks

The above option is not good as this requires replacing copying the whole class and customizing it so it will increase maintenance burden for me during spring upgrades

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading OAuth2TokenExchangeAuthenticationProvider and the token endpoint flow for OAuth2TokenExchangeAuthenticationToken. Identify the supported extension point for applying claims-based administrator and impersonation checks without copying the provider. Done means authorized exchanges succeed and unauthorized users receive an error, with coverage for both outcomes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authorization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.