spring-projects / spring-projects/spring-security

Add handler reference by name to HandleAuthorizationDenied

Open
#16,622 0 comments 0 reactions 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

MethodAuthorizationDeniedHandler is an interface with a single non-default method, therefore it can be implemented by a lambda. However, HandleAuthorizationDenied can only reference a handler by class, excluding lambdas.

I would like HandleAuthorizationDenied to have an additional parameter String handler() default "" so that this is possible:

@Configuration
@EnableMethodSecurity
class MyConfiguration {

  @Bean
  MethodAuthorizationDeniedHandler emptyListHandler() {
    return (invocation, result) -> List.of();
  }

}

class Account {
  String name;
  @PreAuthorize("hasRole('DETAILS')")
  @HandleAuthorizationDenied(handler = "emptyListHandler")
  List<String> details;
}

Even better if the handler name could be interpolated from a property or a spel expression.

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 with the HandleAuthorizationDenied annotation and the MethodAuthorizationDeniedHandler interface described in the issue. Trace how HandleAuthorizationDenied resolves handlers by class, then determine the supported configuration path for a bean name and whether property or SpEL interpolation is in scope. Done means a lambda handler can be selected by the handler name shown in the example, with the requested behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.