Skip to content

Add handler reference by name to HandleAuthorizationDenied #16622

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

Open
gbaso opened this issue Feb 19, 2025 · 0 comments · May be fixed by #16970
Open

Add handler reference by name to HandleAuthorizationDenied #16622

gbaso opened this issue Feb 19, 2025 · 0 comments · May be fixed by #16970
Labels
status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement

Comments

@gbaso
Copy link
Contributor

gbaso commented Feb 19, 2025

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.

@gbaso gbaso added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Feb 19, 2025
evgeniycheban added a commit to evgeniycheban/spring-security that referenced this issue Apr 20, 2025
evgeniycheban added a commit to evgeniycheban/spring-security that referenced this issue Apr 20, 2025
Issue spring-projectsgh-16622

Signed-off-by: Evgeniy Cheban <[email protected]>
evgeniycheban added a commit to evgeniycheban/spring-security that referenced this issue Apr 20, 2025
Issue spring-projectsgh-16622

Signed-off-by: Evgeniy Cheban <[email protected]>
evgeniycheban added a commit to evgeniycheban/spring-security that referenced this issue Apr 20, 2025
Issue spring-projectsgh-16622

Signed-off-by: Evgeniy Cheban <[email protected]>
evgeniycheban added a commit to evgeniycheban/spring-security that referenced this issue Apr 20, 2025
Issue spring-projectsgh-16622

Signed-off-by: Evgeniy Cheban <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant