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

Method Security for Filtering non-collections #14601

Closed
Tracked by #14595
rwinch opened this issue Feb 13, 2024 · 0 comments
Closed
Tracked by #14595

Method Security for Filtering non-collections #14601

rwinch opened this issue Feb 13, 2024 · 0 comments
Assignees
Labels
in: core An issue in spring-security-core status: duplicate A duplicate of another issue type: enhancement A general enhancement
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Feb 13, 2024

We support filtering the results of collections, but it would be nice to filter non-collection types. I haven't decided on the syntax for this but here is a rough idea:

// needs work because won't work with primitives
class DefaultValueDeniedHandler implements MethodAccessDeniedHandler {
   // FIXME: should we even allow access to the deniedObject?
  // for PreAuthorize deniedObject is a reference to the method and arguments, for PostAuthorize it is the return value
   public Object handle(Object deniedObject, AccessDeniedException e) {
      return null;
  }
}
class Foo {
  @DenyAll
  @DeniedHandler(DefaultValueDeniedHandler.class)
  String bar() {
    return "bar";
  }
}
foo.bar(); // returns null

We could also customize to do non-default types. For example if we wanted to mask the value:

// needs work because won't work with primitives
class MaskDeniedHandler implements MethodAccessDeniedHandler {
   public String handle(String deniedObject, AccessDeniedException e) {
      return "***";
  }
}
class Foo {
  @DenyAll
  @DeniedHandler(MaskDeniedHandler.class)
  String bar() {
    return "bar";
  }
}
foo.bar(); // returns "***"

We can also create composed annotations to simplify.

class Foo {
  @DenyAll
  @MaskDenied
  String bar() {
    return "bar";
  }
}
foo.bar(); // returns "***"

We can also allow the handler to be specified on the class level

@MaskDenied
class Foo {
  @DenyAll
  String bar() {
    return "bar";
  }

  @DenyAll
  String zip() {
    return "zip";
  }
}
foo.bar(); // returns "***"
foo.zip(); // returns "***"
marcusdacoregio added a commit to marcusdacoregio/spring-security that referenced this issue Apr 3, 2024
@marcusdacoregio marcusdacoregio added status: duplicate A duplicate of another issue in: core An issue in spring-security-core type: enhancement A general enhancement labels Apr 3, 2024
@marcusdacoregio marcusdacoregio added this to the 6.3.0-RC1 milestone Apr 3, 2024
jzheaux added a commit that referenced this issue Apr 4, 2024
marcusdacoregio added a commit to marcusdacoregio/spring-security that referenced this issue Apr 12, 2024
marcusdacoregio added a commit to marcusdacoregio/spring-security that referenced this issue Apr 12, 2024
marcusdacoregio added a commit that referenced this issue Apr 12, 2024
- Renamed @AuthorizationDeniedHandler to @HandleAuthorizationDenied
- Merged the post processor interface into MethodAuthorizationDeniedHandler , it now has two methods handleDeniedInvocation and handleDeniedInvocationResult
- @HandleAuthorizationDenied now handles AuthorizationDeniedException thrown from the method

Issue gh-14601
jzheaux added a commit that referenced this issue Aug 30, 2024
Now instructs to use MethodAuthorizationDeniedHandler

Issue gh-14601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core An issue in spring-security-core status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
Status: No status
Development

No branches or pull requests

2 participants