Class ConsoleWrites

java.lang.Object
org.apache.juneau.petstore.console.ConsoleWrites

public final class ConsoleWrites extends Object
The console's write gate. Console writes are open by default; with -Dpetstore.secure=true each one needs the demo bearer token (StubBearerTokenValidator.DEFAULT_TOKENS). Also names the audit actor.
Example:

@RestPost(path="/") public Pet create(RestRequest req, @Content Pet pet) { return store().createPet(pet, ConsoleWrites.actor(req)); }

  • Field Details

  • Method Details

    • roles

      public static List<String> roles(RestRequest req)
      The viewer's roles, for <@facts> and server-side omission of role-gated cards.

      Never an authorization check: writes still go through actor(RestRequest). Independent of petstore.secure.

      Parameters:
      req - The request.
      Returns:
      ["admin"] when the bearer token validates to the admin principal, else empty.
    • actor

      public static String actor(RestRequest req)
      Checks the write gate and returns the audit actor.
      Parameters:
      req - The request.
      Returns:
      "console:<user>" when a valid bearer token is present, else "console".
      Throws:
      Unauthorized - If the gate is on and the token is missing or unknown.
    • author

      public static String author(String actor)
      The audit actor reduced to the staging author.
      Parameters:
      actor - A actor(RestRequest) value.
      Returns:
      The bare user ("admin"), or "anonymous" when writes are unsecured.