Annotation Interface RunAs


@Around @Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented public @interface RunAs
Applies a run-as authentication to intercepted method invocations.

The run-as authentication applies only to the annotated method. A synchronous method runs with it until it returns. For a method returning a reactive type, the method body, and the work the returned publisher does when it is subscribed to, asked for more elements or cancelled, run with it, while elements, errors and completion reach the subscriber with the authentication that was current when it subscribed. For a method returning a CompletionStage, or a Kotlin suspend function, the method body runs with it, while the dependents of the returned stage and the code after a suspend call run with the authentication that was current when the method was called. Code the caller chains after the call therefore runs with the caller's authentication. When the caller has no authentication, that code runs without one. Work that moves to a thread without context propagation does not see the run-as authentication. Cancelling the stage returned to the caller also cancels the method's own stage.

When both a class and one of its methods are annotated, the method's annotation is used on its own for that method: members it does not set do not come from the class's annotation. Repeat name() on the method when it can be called without an authentication, and appendRoles() or appendAttributes() when the class sets them to false. Methods without their own annotation use the class's annotation.

Since:
5.1.0
Author:
Sergio del Amo
  • Element Details

    • value

      @AliasFor(member="roles") String[] value
      Alias for roles().
      Returns:
      The roles for the run-as authentication
      Since:
      5.1.0
      Default:
      {}
    • name

      String name
      Returns:
      The user name for the run-as authentication, or the current user name when blank
      Default:
      ""
    • roles

      @AliasFor(member="value") String[] roles
      Returns:
      The roles for the run-as authentication
      Default:
      {}
    • appendRoles

      boolean appendRoles
      Returns:
      Whether the supplied roles should be appended to the current authentication roles.
      Since:
      5.1.0
      Default:
      true
    • attributes

      RunAs.Attribute[] attributes
      Returns:
      The attributes for the run-as authentication
      Default:
      {}
    • appendAttributes

      boolean appendAttributes
      Returns:
      Whether the supplied attributes should be appended to the current authentication attributes.
      Since:
      5.1.0
      Default:
      true