Skip to content

[Use Case]: Inheritance of annotations beyond Jakarta interceptor bindings #1293

@yrodiere

Description

@yrodiere

As a ...

  • Application user/user of the configuration itself
  • API user (application developer)
  • SPI user (container or runtime developer)
  • Specification implementer

I need to be able to ...

... apply annotations to my repository interfaces, and have them taken into account in repository implementations even if the annotations are not CDI interceptor bindings.

Which enables me to ...

  • secure access to Jakarta Data repositories according to roles/permissions defined by jakarta.security annotations
  • <put the effect of any method-level annotation you can think of here>

Additional information

Section 7.2 of the spec states:

A repository interface or method of a repository interface may be annotated with an interceptor binding annotation. In the Jakarta EE environment—​or in any other environment where Jakarta Interceptors [6] is available and integrated with Jakarta CDI—​if the repository implementation is instantiated by the CDI bean container then the interceptor binding annotation is inherited by the repository implementation. That is, the interceptor binding annotation must be treated as if it were placed directly on the repository implementation bean. The interceptors bound to the annotation are applied automatically by the implementation of Jakarta Interceptors.

This is a very useful feature, but unfortunately limited to interceptor binding annotations.

There are more annotations that could be applied to repositories, and that would make sense to be "inherited" -- copied, really -- by the Jakarta Repository implementation.

One example, and I want to stress that even if it's arguable, it's just an example among others, is Jakarta Security annotations. Frameworks would likely comply with jakarta.annotation.security.RolesAllowed through some kind of interceptors, perhaps even CDI interceptors, but the annotation itself is not an interceptor binding -- it's not meta-annotated with @jakarta.interceptor.InterceptorBinding

We could say that "security annotation should be annotated with @Inherited", but we would be wrong -- from https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/annotation/Inherited.html: "this meta-annotation only causes annotations to be inherited from superclasses; annotations on implemented interfaces have no effect". So, not a good match for Jakarta Data repositories.


Could we extend the definition of which annotations should be copied from the interface to the implementation?
Perhaps list Jakarta Security annotations?
Maybe decide that @Inherited annotations will be copied to implementations, thereby fixing the weird "official" definition of @Inherited in the JDK?

Alternatively -- or perhaps additionally -- could you confirm that the processor may chose to copy more annotations than what's mentioned in the spec? In which case this problem could be shifted to implementations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions