Package org.attribyte.snook.auth
Class HMACCookieLoginAuthenticator<T>
java.lang.Object
org.attribyte.snook.auth.HMACCookieAuthenticator<T>
org.attribyte.snook.auth.HMACCookieLoginAuthenticator<T>
- All Implemented Interfaces:
Authenticator<T>,LoginAuthenticator<T>
public abstract class HMACCookieLoginAuthenticator<T>
extends HMACCookieAuthenticator<T>
implements LoginAuthenticator<T>
An authenticator that validates an
HMACToken sent as a cookie value.-
Field Summary
Fields inherited from class org.attribyte.snook.auth.HMACCookieAuthenticator
cookieKey, hmacFunctionsFields inherited from interface org.attribyte.snook.auth.Authenticator
base64Encoding, credentialHasher -
Constructor Summary
ConstructorsConstructorDescriptionHMACCookieLoginAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction) Creates an authenticator.HMACCookieLoginAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction, EnumSet<Cookies.Option> cookieOptions) Creates an authenticator. -
Method Summary
Modifier and TypeMethodDescriptionstatic HMACCookieLoginAuthenticator<Boolean> booleanAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction) static HMACCookieLoginAuthenticator<Boolean> booleanAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction, EnumSet<Cookies.Option> cookieOptions) doLogin(String username, String password, int tokenLifetimeSeconds, jakarta.servlet.http.HttpServletResponse resp) Performs a login.voiddoLogout(jakarta.servlet.http.HttpServletResponse resp) Performs a logout, if possible.abstract TinvalidCredentials(String username) Supplies credentials for an invalid login.abstract TvalidCredentials(String username) Supplies credentials for a valid login.Methods inherited from class org.attribyte.snook.auth.HMACCookieAuthenticator
authorized, authorizedUsername, booleanAuthenticator, credentials, schemeNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.attribyte.snook.auth.Authenticator
authorized, authorizedUsername, credentials, schemeName
-
Constructor Details
-
HMACCookieLoginAuthenticator
public HMACCookieLoginAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction) Creates an authenticator.- Parameters:
hmacFunctions- A map of HMAC function vs key id.checkPasswordFunction- A function to check username/password.hmacKeyFunction- A function that returns the key id for a username.
-
HMACCookieLoginAuthenticator
public HMACCookieLoginAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction, EnumSet<Cookies.Option> cookieOptions) Creates an authenticator.- Parameters:
hmacFunctions- A map of HMAC function vs key id.checkPasswordFunction- A function to check username/password.hmacKeyFunction- A function that returns the key id for a username.cookieOptions- The cookie options.
-
-
Method Details
-
booleanAuthenticator
public static HMACCookieLoginAuthenticator<Boolean> booleanAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction) - See Also:
-
booleanAuthenticator
public static HMACCookieLoginAuthenticator<Boolean> booleanAuthenticator(Cookies.CookieKey cookieKey, Function<String, com.google.common.hash.HashFunction> hmacFunctions, BiFunction<String, String, Boolean> checkPasswordFunction, Function<String, String> hmacKeyFunction, EnumSet<Cookies.Option> cookieOptions) - See Also:
-
doLogin
public T doLogin(String username, String password, int tokenLifetimeSeconds, jakarta.servlet.http.HttpServletResponse resp) Description copied from interface:LoginAuthenticatorPerforms a login.If username + password is valid, sets a header or a cookie on the response and returns
true. Otherwise, does nothing and returnsfalse.- Specified by:
doLoginin interfaceLoginAuthenticator<T>- Parameters:
username- The username.password- The password.tokenLifetimeSeconds- The authentication token lifetime in seconds.resp- The response.- Returns:
- Was the password valid and token saved and set as a cookie?
-
doLogout
public void doLogout(jakarta.servlet.http.HttpServletResponse resp) Description copied from interface:LoginAuthenticatorPerforms a logout, if possible.- Specified by:
doLogoutin interfaceLoginAuthenticator<T>- Parameters:
resp- The response.
-
validCredentials
Supplies credentials for a valid login.- Specified by:
validCredentialsin classHMACCookieAuthenticator<T>- Parameters:
username- The username.- Returns:
- The credentials.
-
invalidCredentials
Supplies credentials for an invalid login.- Specified by:
invalidCredentialsin classHMACCookieAuthenticator<T>- Parameters:
username- The username.- Returns:
- The credentials.
-