Skip to content
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

Add handler reference by name to HandleAuthorizationDenied #16622

Open
gbaso opened this issue Feb 19, 2025 · 0 comments
Open

Add handler reference by name to HandleAuthorizationDenied #16622

gbaso opened this issue Feb 19, 2025 · 0 comments
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
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

No branches or pull requests

1 participant