Class SecureApiRest

java.lang.Object
jakarta.servlet.GenericServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable, BasicUniversalConfig, DefaultConfig, DefaultHtmlConfig

public class SecureApiRest extends PetstoreConsolePage
The bearer-token protected API behind the Secure page.

Every op is gated by a fail-closed BearerTokenGuard backed by StubBearerTokenValidator: no token or an unknown token is a 401 with a WWW-Authenticate: Bearer realm="petstore" challenge. On success the resolved Principal reaches ops as an @Auth parameter.

Why a guard rather than a filter chain? AuthFilterChain composes several mechanisms and is fail-open by design, so a downstream guard decides. With one mechanism, the op-level guard is the whole story.

Example:

// One bean gates every op on the resource. @Bean public RestGuardList guards(BeanStore bs) { return RestGuardList.create(bs) .append(BearerTokenGuard.create().realm("petstore").validator(new StubBearerTokenValidator()).build()) .build(); } // curl -H 'Authorization: Bearer petstore-user' http://localhost:10000/console/dev/secure/api/pets

See Also:
  • Constructor Details

  • Method Details

    • guards

      Gates every op on this resource with a bearer-token guard.
      Parameters:
      bs - The bean store.
      Returns:
      The guard list.
    • pets

      public Collection<Pet> pets()
      Returns:
      All pets.
    • pet

      public Pet pet(@Path("id") long id)
      Parameters:
      id - The pet id.
      Returns:
      The pet.
      Throws:
      NotFound - If there is no such pet.
    • whoami

      public Map<String,String> whoami(@Auth Principal caller)
      Parameters:
      caller - The authenticated principal (never null: the guard rejects anonymous calls first).
      Returns:
      {name: <principal>}.