Colm O hEigeartaigh created CXF-9269:
----------------------------------------
Summary: Support JSR-250 @PermitAll and @DenyAll in
SecureAnnotationsInterceptor
Key: CXF-9269
URL: https://issues.apache.org/jira/browse/CXF-9269
Project: CXF
Issue Type: Improvement
Reporter: Colm O hEigeartaigh
Assignee: Colm O hEigeartaigh
Fix For: 4.3.0
{{SecureAnnotationsInterceptor}} (and {{SimpleAuthorizingFilter}} for JAX-RS,
which delegates to it) only processes the role annotation configured via
{{{}annotationClassName{}}}, which is {{@RolesAllowed}} by default. The other
JSR-250 security annotations, {{@PermitAll}} and {{{}@DenyAll{}}}, are silently
ignored:
* A method annotated {{@DenyAll}} has no rule, so the default applies: any
caller is permitted, including anonymous callers when {{allowAnonymousUsers}}
is {{true}} (the default).
* A method annotated {{@PermitAll}} in a class with a class-level
{{@RolesAllowed}} still requires the class-level roles.
* The common JSR-250 pattern of a class-level {{@DenyAll}} with individual
methods opened via {{@PermitAll}} or {{@RolesAllowed}} doesn’t work as expected.
CXF has never documented support for these annotations, so this is not a
security issue, but it’s a frequent expectation from Jakarta EE and other
JAX-RS implementations.
{*}Proposed behaviour{*}, following JSR-250 and the rule resolution
{{SecureAnnotationsInterceptor}} already uses for {{{}@RolesAllowed{}}}:
* *Method-level {{{}@DenyAll{}}}:* no caller may invoke the method,
authenticated or anonymous. As with method-level {{{}@RolesAllowed{}}}, it
can’t be relaxed by an overriding method.
* *Method-level {{{}@PermitAll{}}}:* any caller may invoke the method,
including anonymous callers. It replaces class-level
{{{}@RolesAllowed{}}}/{{{}@DenyAll{}}} from its own class or a superclass, as a
method-level {{@RolesAllowed}} does today. It does not remove method-level
rules from a superclass or interface method it overrides, so an override can’t
weaken an explicitly protected method.
* *Class-level {{{}@DenyAll{}}}:* applies to the class’s own methods and to
its inherited methods that have no method-level annotation, as for a
class-level {{{}@RolesAllowed{}}}.
* *Class-level {{{}@PermitAll{}}}:* the class’s methods without a method-level
annotation have no role requirement.
* *Several annotations on the same element* (e.g. {{@RolesAllowed}} and
{{@DenyAll}} on one method) are invalid per JSR-250; the most restrictive
should apply, and a warning should be logged.
* *Namespace:* the annotations are matched by name.
{{jakarta.annotation.security.*}} on 4.x; the {{javax.annotation.security.*}}
equivalents if this is backported to 3.6.x.
* *Custom annotation class:* when {{annotationClassName}} is set to something
else (e.g. Spring’s {{{}@Secured{}}}), {{{}@PermitAll{}}}/{{{}@DenyAll{}}}
should still be honoured.
*Compatibility:*
* *Stricter:* methods annotated {{{}@DenyAll{}}}, and the unannotated methods
of a class annotated {{{}@DenyAll{}}}, are now denied. Previously the
annotation was ignored and they were open.
* *More permissive:* methods annotated {{@PermitAll}} in a class with a
class-level {{@RolesAllowed}} no longer require the class-level roles, and
admit anonymous callers. Previously the annotation was ignored and the class
roles applied.
These need to go in the release notes / migration guide.
*Tests:*
* method-level and class-level {{{}@DenyAll{}}}, for authenticated and
anonymous callers;
* method-level {{@PermitAll}} replacing class-level {{@RolesAllowed}} and
class-level {{{}@DenyAll{}}}, including when declared on a superclass;
* an override annotated {{@PermitAll}} still enforcing the overridden method’s
method-level {{{}@RolesAllowed{}}};
* the “class-level {{@DenyAll}} + method-level
{{{}@PermitAll{}}}/{{{}@RolesAllowed{}}}” pattern;
* {{{}@PermitAll{}}}/{{{}@DenyAll{}}} on interfaces and through generic
interface methods;
* a custom {{annotationClassName}} combined with
{{{}@PermitAll{}}}/{{{}@DenyAll{}}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)