Package no.polaric.core.auth
Class HmacAuthenticator
java.lang.Object
no.polaric.core.auth.HmacAuthenticator
- All Implemented Interfaces:
org.pac4j.core.credentials.authenticator.Authenticator
public class HmacAuthenticator
extends Object
implements org.pac4j.core.credentials.authenticator.Authenticator
Authenticator using a SHA-256 HMAC. Implements Arctic-HMAC authentication.
-
Field Summary
Fields inherited from interface org.pac4j.core.credentials.authenticator.Authenticator
ALWAYS_VALIDATE, NEVER_VALIDATE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal HttpRequest.BuilderaddAuth(HttpRequest.Builder bld, String body, String userid) Add 'Authorization' header to http requestfinal StringauthString(String body, String userid) Generate an authentication string to use in a URL.final UserCheck authentication fields: userid, nonce, hmac and data)final voidexpireUserKey(String userid) Expire session-key for a user if older than MAX_SESSION_LENGTH.final StringgetUserKey(String userid) Get session-key for a uservoidSave keys to file.final voidsetUserKey(String userid, String key) Set session-key for a user.protected voidthrowsException(String message) Optional<org.pac4j.core.credentials.Credentials> validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials cred) Validate credentials (do authentication).
-
Constructor Details
-
HmacAuthenticator
-
-
Method Details
-
getUserKey
Get session-key for a user -
setUserKey
Set session-key for a user. This is done when user successfully logs in. A timestamp is also set to be able to expire the session. -
expireUserKey
Expire session-key for a user if older than MAX_SESSION_LENGTH. If expired, remove the session-key and the user-login. -
saveLogins
public void saveLogins()Save keys to file. Assume that these are personal user-logins. -
getUserLogins
-
validate
public Optional<org.pac4j.core.credentials.Credentials> validate(org.pac4j.core.context.CallContext ctx, org.pac4j.core.credentials.Credentials cred) throws org.pac4j.core.exception.CredentialsException Validate credentials (do authentication).- Specified by:
validatein interfaceorg.pac4j.core.credentials.authenticator.Authenticator- Throws:
org.pac4j.core.exception.CredentialsException
-
getRole
-
checkAuth
public final User checkAuth(String userid, String nonce, String rmac, String data) throws org.pac4j.core.exception.CredentialsException Check authentication fields: userid, nonce, hmac and data)- Throws:
org.pac4j.core.exception.CredentialsException
-
authString
Generate an authentication string to use in a URL. Consists of: - userid - nonce: Base64 encoded 8 byte random number. - hmac: Base64 encoded hmac-digest based on nonce+data and a secret key. Truncated to 44 characters. -
addAuth
Add 'Authorization' header to http request -
throwsException
- Throws:
org.pac4j.core.exception.CredentialsException
-