Package io.github.pimak.ntfy.core
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSendsAuthorization: Basic <base64(username:password)>.static final classSendsAuthorization: Bearer <token>.static final classSends noAuthorizationheader at all — a valid anonymous publish. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AuthModeCreates aAuthMode.BasicAuthauth mode carrying the given username/password pair.static AuthModeCreates aAuthMode.BearerTokenauth mode carrying the given token.Builds theAuthorizationheader value for this auth mode, if any.static AuthModefromCredentials(String token, String username, String password) Derives the applicableAuthModefrom raw configured credentials, encoding the same precedence as the engine's configuration surface: a non-blanktokenalways wins, even ifusername/passwordare also set; otherwise a non-blankusernameANDpasswordtogether selectAuthMode.BasicAuth; otherwiseAuthMode.None.static AuthModenone()Returns the sharedAuthMode.Noneinstance (noAuthorizationheader is sent).
-
Constructor Details
-
AuthMode
public AuthMode()
-
-
Method Details
-
buildHeader
Builds theAuthorizationheader value for this auth mode, if any.- Returns:
Optional.of(headerValue)when this mode sends anAuthorizationheader, orOptional.empty()when no header should be sent at all.
-
bearer
Creates aAuthMode.BearerTokenauth mode carrying the given token. -
basic
Creates aAuthMode.BasicAuthauth mode carrying the given username/password pair. -
none
Returns the sharedAuthMode.Noneinstance (noAuthorizationheader is sent). -
fromCredentials
Derives the applicableAuthModefrom raw configured credentials, encoding the same precedence as the engine's configuration surface: a non-blanktokenalways wins, even ifusername/passwordare also set; otherwise a non-blankusernameANDpasswordtogether selectAuthMode.BasicAuth; otherwiseAuthMode.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 sharedAuthMode.Noneinstance
-