Class AuthMode

java.lang.Object
io.github.pimak.ntfy.core.AuthMode
Direct Known Subclasses:
AuthMode.BasicAuth, AuthMode.BearerToken, AuthMode.None

public abstract sealed class AuthMode extends Object permits AuthMode.BearerToken, AuthMode.BasicAuth, AuthMode.None
Auth strategy for an outbound ntfy publish request, modeled as a sealed hierarchy so each mode carries only the fields it needs and knows how to build its own Authorization header.

AuthMode.None is a valid, first-class configuration: an engine with no token and no username/password configured publishes without an Authorization header, which is a legitimate way to reach public ntfy.sh topics or a permissive self-hosted server.

  • Constructor Details

    • AuthMode

      public AuthMode()
  • Method Details

    • buildHeader

      public abstract Optional<String> buildHeader()
      Builds the Authorization header value for this auth mode, if any.
      Returns:
      Optional.of(headerValue) when this mode sends an Authorization header, or Optional.empty() when no header should be sent at all.
    • bearer

      public static AuthMode bearer(String token)
      Creates a AuthMode.BearerToken auth mode carrying the given token.
    • basic

      public static AuthMode basic(String username, String password)
      Creates a AuthMode.BasicAuth auth mode carrying the given username/password pair.
    • none

      public static AuthMode none()
      Returns the shared AuthMode.None instance (no Authorization header is sent).
    • fromCredentials

      public static AuthMode fromCredentials(String token, String username, String password)
      Derives the applicable AuthMode from raw configured credentials, encoding the same precedence as the engine's configuration surface: a non-blank token always wins, even if username/password are also set; otherwise a non-blank username AND password together select AuthMode.BasicAuth; otherwise AuthMode.None.

      This factory is silent — it never emits a diagnostic for the token-plus-basic overlap case. That one-time warning is the caller's responsibility (fired once, at engine startup).

      Returns:
      a AuthMode.BearerToken, AuthMode.BasicAuth, or the shared AuthMode.None instance