Class ScriptBasedAuthenticator
- java.lang.Object
-
- org.keycloak.authentication.authenticators.browser.ScriptBasedAuthenticator
-
- All Implemented Interfaces:
org.keycloak.authentication.Authenticator,org.keycloak.provider.Provider
public class ScriptBasedAuthenticator extends Object implements org.keycloak.authentication.Authenticator
AnAuthenticatorthat can execute a configured script during authentication flow.Scripts must at least provide one of the following functions:
authenticate(..)which is called fromAuthenticator.authenticate(AuthenticationFlowContext)action(..)which is called fromAuthenticator.action(AuthenticationFlowContext)
Custom
Authenticator'sshould at least provide theauthenticate(..)function. The following scriptBindingsare available for convenient use within script code.scripttheScriptModelto access script metadatarealmtheRealmModeluserthe currentUserModelsessionthe activeKeycloakSessionauthenticationSessionthe currentAuthenticationSessionModelhttpRequestthe currentHttpRequestLOGaLoggerscoped toScriptBasedAuthenticator
Note that the
uservariable is only defined when the user was identified by a preceeding authentication step, e.g. by theUsernamePasswordFormauthenticator.Additional context information can be extracted from the
contextargument passed to theauthenticate(context)oraction(context)function.An example
ScriptBasedAuthenticatordefinition could look as follows:AuthenticationFlowError = Java.type("org.keycloak.authentication.AuthenticationFlowError"); function authenticate(context) { var username = user ? user.username : "anonymous"; LOG.info(script.name + " --> trace auth for: " + username); if ( username === "tester" && user.getAttribute("someAttribute") && user.getAttribute("someAttribute").contains("someValue")) { context.failure(AuthenticationFlowError.INVALID_USER); return; } context.success(); }- Author:
- Thomas Darimont
-
-
Constructor Summary
Constructors Constructor Description ScriptBasedAuthenticator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaction(org.keycloak.authentication.AuthenticationFlowContext context)voidauthenticate(org.keycloak.authentication.AuthenticationFlowContext context)voidclose()booleanconfiguredFor(org.keycloak.models.KeycloakSession session, org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user)protected org.keycloak.models.AuthenticatorConfigModelgetAuthenticatorConfig(org.keycloak.authentication.AuthenticationFlowContext context)booleanrequiresUser()voidsetRequiredActions(org.keycloak.models.KeycloakSession session, org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user)
-
-
-
Method Detail
-
authenticate
public void authenticate(org.keycloak.authentication.AuthenticationFlowContext context)
- Specified by:
authenticatein interfaceorg.keycloak.authentication.Authenticator
-
action
public void action(org.keycloak.authentication.AuthenticationFlowContext context)
- Specified by:
actionin interfaceorg.keycloak.authentication.Authenticator
-
getAuthenticatorConfig
protected org.keycloak.models.AuthenticatorConfigModel getAuthenticatorConfig(org.keycloak.authentication.AuthenticationFlowContext context)
-
requiresUser
public boolean requiresUser()
- Specified by:
requiresUserin interfaceorg.keycloak.authentication.Authenticator
-
configuredFor
public boolean configuredFor(org.keycloak.models.KeycloakSession session, org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user)- Specified by:
configuredForin interfaceorg.keycloak.authentication.Authenticator
-
setRequiredActions
public void setRequiredActions(org.keycloak.models.KeycloakSession session, org.keycloak.models.RealmModel realm, org.keycloak.models.UserModel user)- Specified by:
setRequiredActionsin interfaceorg.keycloak.authentication.Authenticator
-
close
public void close()
- Specified by:
closein interfaceorg.keycloak.provider.Provider
-
-