Class ConditionalOtpFormAuthenticator
- java.lang.Object
- 
- org.keycloak.authentication.AbstractFormAuthenticator
- 
- org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator
- 
- org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator
- 
- org.keycloak.authentication.authenticators.browser.ConditionalOtpFormAuthenticator
 
 
 
 
- 
- All Implemented Interfaces:
- Authenticator,- CredentialValidator<OTPCredentialProvider>,- Provider
 
 public class ConditionalOtpFormAuthenticator extends OTPFormAuthenticator AnOTPFormAuthenticatorthat can conditionally require OTP authentication.The decision for whether or not to require OTP authentication can be made based on multiple conditions which are evaluated in the following order. The first matching condition determines the outcome. - User Attribute
- Role
- Request Header
- Configured Default
 If no condition matches, the ConditionalOtpFormAuthenticatorfallback is to require OTP authentication.User AttributeA User Attribute likeotp_authcan be used to control OTP authentication on individual user level. The supported values are skip and force. If the value is set to skip then the OTP auth is skipped for the user, otherwise if the value is force then the OTP auth is enforced. The setting is ignored for any other value.RoleA role can be used to control the OTP authentication. If the user has the specified skip OTP role then OTP authentication is skipped for the user. If the user has the specified force OTP role, then the OTP authentication is required for the user. If not configured, e.g. if no role is selected, then this setting is ignored.Request HeaderRequest Headers are matched via regex Patterns and can be specified as a whitelist and blacklist. No OTP for Header specifies the pattern for which OTP authentication is not required. This can be used to specify trusted networks, e.g. via:X-Forwarded-Host: (1.2.3.4|1.2.3.5)where The IPs 1.2.3.4, 1.2.3.5 denote trusted machines. Force OTP for Header specifies the pattern for which OTP authentication is required. Whitelist entries take precedence before blacklist entries.Configured DefaultA default fall-though behaviour can be specified to handle cases where all previous conditions did not lead to a conclusion. An OTP authentication is required in case no default is configured.- Author:
- Thomas Darimont
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringDEFAULT_OTP_OUTCOMEstatic StringFORCEstatic StringFORCE_OTP_FOR_HTTP_HEADERstatic StringFORCE_OTP_ROLEstatic StringOTP_CONTROL_USER_ATTRIBUTEstatic StringSKIPstatic StringSKIP_OTP_FOR_HTTP_HEADERstatic StringSKIP_OTP_ROLE- 
Fields inherited from class org.keycloak.authentication.authenticators.browser.OTPFormAuthenticatorSELECTED_OTP_CREDENTIAL_ID, UNNAMED
 - 
Fields inherited from class org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticatorATTEMPTED_USERNAME, REGISTRATION_FORM_ACTION, USER_SET_BEFORE_USERNAME_PASSWORD_AUTH
 
- 
 - 
Constructor SummaryConstructors Constructor Description ConditionalOtpFormAuthenticator()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidauthenticate(AuthenticationFlowContext context)Initial call for the authenticator.voidsetRequiredActions(KeycloakSession session, RealmModel realm, UserModel user)Set actions to configure authenticator- 
Methods inherited from class org.keycloak.authentication.authenticators.browser.OTPFormAuthenticatoraction, close, configuredFor, createLoginForm, disabledByBruteForceError, disabledByBruteForceFieldError, getCredentialProvider, getRequiredActions, requiresUser, validateOTP
 - 
Methods inherited from class org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticatorchallenge, challenge, dummyHash, enabledUser, getDefaultChallengeMessage, isDisabledByBruteForce, isUserAlreadySetBeforeUsernamePasswordAuth, runDefaultDummyHash, setDuplicateUserChallenge, testInvalidUser, validatePassword, validateUser, validateUserAndPassword
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.authentication.AuthenticatorareRequiredActionsEnabled
 - 
Methods inherited from interface org.keycloak.authentication.CredentialValidatorgetCredentials, getType
 
- 
 
- 
- 
- 
Field Detail- 
SKIPpublic static final String SKIP - See Also:
- Constant Field Values
 
 - 
FORCEpublic static final String FORCE - See Also:
- Constant Field Values
 
 - 
OTP_CONTROL_USER_ATTRIBUTEpublic static final String OTP_CONTROL_USER_ATTRIBUTE - See Also:
- Constant Field Values
 
 - 
SKIP_OTP_ROLEpublic static final String SKIP_OTP_ROLE - See Also:
- Constant Field Values
 
 - 
FORCE_OTP_ROLEpublic static final String FORCE_OTP_ROLE - See Also:
- Constant Field Values
 
 - 
SKIP_OTP_FOR_HTTP_HEADERpublic static final String SKIP_OTP_FOR_HTTP_HEADER - See Also:
- Constant Field Values
 
 - 
FORCE_OTP_FOR_HTTP_HEADERpublic static final String FORCE_OTP_FOR_HTTP_HEADER - See Also:
- Constant Field Values
 
 - 
DEFAULT_OTP_OUTCOMEpublic static final String DEFAULT_OTP_OUTCOME - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
authenticatepublic void authenticate(AuthenticationFlowContext context) Description copied from interface:AuthenticatorInitial call for the authenticator. This method should check the current HTTP request to determine if the request satifies the Authenticator's requirements. If it doesn't, it should send back a challenge response by calling the AuthenticationFlowContext.challenge(Response). If this challenge is a authentication, the action URL of the form must point to /realms/{realm}/login-actions/authenticate?code={session-code}&execution={executionId} or /realms/{realm}/login-actions/registration?code={session-code}&execution={executionId} {session-code} pertains to the code generated from AuthenticationFlowContext.generateAccessCode(). The {executionId} pertains to the AuthenticationExecutionModel.getId() value obtained from AuthenticationFlowContext.getExecution(). The action URL will invoke the action() method described below.- Specified by:
- authenticatein interface- Authenticator
- Overrides:
- authenticatein class- OTPFormAuthenticator
 
 - 
setRequiredActionspublic void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) Description copied from interface:AuthenticatorSet actions to configure authenticator- Specified by:
- setRequiredActionsin interface- Authenticator
- Overrides:
- setRequiredActionsin class- OTPFormAuthenticator
 
 
- 
 
-