keycloak-service
公開メンバ関数 | 静的公開変数類 | 限定公開メンバ関数 | 全メンバ一覧
org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator クラス
org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator の継承関係図
Inheritance graph
org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator 連携図
Collaboration graph

公開メンバ関数

void action (AuthenticationFlowContext context)
 
void authenticate (AuthenticationFlowContext context)
 
void validateOTP (AuthenticationFlowContext context)
 
boolean requiresUser ()
 
boolean configuredFor (KeycloakSession session, RealmModel realm, UserModel user)
 
void setRequiredActions (KeycloakSession session, RealmModel realm, UserModel user)
 
void close ()
 
boolean invalidUser (AuthenticationFlowContext context, UserModel user)
 
boolean enabledUser (AuthenticationFlowContext context, UserModel user)
 
boolean validateUserAndPassword (AuthenticationFlowContext context, MultivaluedMap< String, String > inputData)
 
boolean validatePassword (AuthenticationFlowContext context, UserModel user, MultivaluedMap< String, String > inputData)
 

静的公開変数類

static final String REGISTRATION_FORM_ACTION = "registration_form"
 
static final String ATTEMPTED_USERNAME = "ATTEMPTED_USERNAME"
 

限定公開メンバ関数

Response challenge (AuthenticationFlowContext context, String error)
 
Response invalidUser (AuthenticationFlowContext context)
 
Response disabledUser (AuthenticationFlowContext context)
 
Response temporarilyDisabledUser (AuthenticationFlowContext context)
 
Response invalidCredentials (AuthenticationFlowContext context)
 
Response setDuplicateUserChallenge (AuthenticationFlowContext context, String eventError, String loginFormError, AuthenticationFlowError authenticatorError)
 
void runDefaultDummyHash (AuthenticationFlowContext context)
 
void dummyHash (AuthenticationFlowContext context)
 

詳解

著者
Bill Burke
バージョン
Revision
1

関数詳解

◆ action()

void org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.action ( AuthenticationFlowContext  context)
inline
41  {
42  validateOTP(context);
43  }
void validateOTP(AuthenticationFlowContext context)
Definition: OTPFormAuthenticator.java:51

◆ authenticate()

void org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.authenticate ( AuthenticationFlowContext  context)
inline
46  {
47  Response challengeResponse = challenge(context, null);
48  context.challenge(challengeResponse);
49  }
Response challenge(AuthenticationFlowContext context, String error)
Definition: OTPFormAuthenticator.java:80

◆ challenge()

Response org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.challenge ( AuthenticationFlowContext  context,
String  error 
)
inlineprotected
80  {
81  LoginFormsProvider forms = context.form();
82  if (error != null) forms.setError(error);
83 
84  return forms.createLoginTotp();
85  }

◆ close()

void org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.close ( )
inline
101  {
102 
103  }

◆ configuredFor()

boolean org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.configuredFor ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inline
88  {
89  return session.userCredentialManager().isConfiguredFor(realm, user, realm.getOTPPolicy().getType());
90  }

◆ disabledUser()

Response org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.disabledUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
65  {
66  return context.form()
67  .setError(Messages.ACCOUNT_DISABLED).createLogin();
68  }

◆ dummyHash()

void org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.dummyHash ( AuthenticationFlowContext  context)
inlineprotectedinherited
93  {
94  PasswordPolicy policy = context.getRealm().getPasswordPolicy();
95  if (policy == null) {
96  runDefaultDummyHash(context);
97  return;
98  } else {
99  PasswordHashProvider hash = context.getSession().getProvider(PasswordHashProvider.class, policy.getHashAlgorithm());
100  if (hash == null) {
101  runDefaultDummyHash(context);
102  return;
103 
104  } else {
105  hash.encode("dummypassword", policy.getHashIterations());
106  }
107  }
108 
109  }
void runDefaultDummyHash(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:88

◆ enabledUser()

boolean org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.enabledUser ( AuthenticationFlowContext  context,
UserModel  user 
)
inlineinherited
122  {
123  if (!user.isEnabled()) {
124  context.getEvent().user(user);
125  context.getEvent().error(Errors.USER_DISABLED);
126  Response challengeResponse = disabledUser(context);
127  // this is not a failure so don't call failureChallenge.
128  //context.failureChallenge(AuthenticationFlowError.USER_DISABLED, challengeResponse);
129  context.forceChallenge(challengeResponse);
130  return false;
131  }
132  if (isTemporarilyDisabledByBruteForce(context, user)) return false;
133  return true;
134  }
Response disabledUser(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:65
boolean isTemporarilyDisabledByBruteForce(AuthenticationFlowContext context, UserModel user)
Definition: AbstractUsernameFormAuthenticator.java:210

◆ invalidCredentials()

Response org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.invalidCredentials ( AuthenticationFlowContext  context)
inlineprotectedinherited
75  {
76  return context.form()
77  .setError(Messages.INVALID_USER).createLogin();
78  }

◆ invalidUser() [1/2]

Response org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.invalidUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
59  {
60  return context.form()
61  .setError(Messages.INVALID_USER)
62  .createLogin();
63  }

◆ invalidUser() [2/2]

boolean org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.invalidUser ( AuthenticationFlowContext  context,
UserModel  user 
)
inlineinherited
111  {
112  if (user == null) {
113  dummyHash(context);
114  context.getEvent().error(Errors.USER_NOT_FOUND);
115  Response challengeResponse = invalidUser(context);
116  context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse);
117  return true;
118  }
119  return false;
120  }
Response invalidUser(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:59
void dummyHash(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:93

◆ requiresUser()

boolean org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.requiresUser ( )
inline
76  {
77  return true;
78  }

◆ runDefaultDummyHash()

void org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.runDefaultDummyHash ( AuthenticationFlowContext  context)
inlineprotectedinherited
88  {
89  PasswordHashProvider hash = context.getSession().getProvider(PasswordHashProvider.class, PasswordPolicy.HASH_ALGORITHM_DEFAULT);
90  hash.encode("dummypassword", PasswordPolicy.HASH_ITERATIONS_DEFAULT);
91  }

◆ setDuplicateUserChallenge()

Response org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.setDuplicateUserChallenge ( AuthenticationFlowContext  context,
String  eventError,
String  loginFormError,
AuthenticationFlowError  authenticatorError 
)
inlineprotectedinherited
80  {
81  context.getEvent().error(eventError);
82  Response challengeResponse = context.form()
83  .setError(loginFormError).createLogin();
84  context.failureChallenge(authenticatorError, challengeResponse);
85  return challengeResponse;
86  }

◆ setRequiredActions()

void org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.setRequiredActions ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inline
93  {
94  if (!user.getRequiredActions().contains(UserModel.RequiredAction.CONFIGURE_TOTP.name())) {
95  user.addRequiredAction(UserModel.RequiredAction.CONFIGURE_TOTP.name());
96  }
97 
98  }

◆ temporarilyDisabledUser()

Response org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.temporarilyDisabledUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
70  {
71  return context.form()
72  .setError(Messages.INVALID_USER).createLogin();
73  }

◆ validateOTP()

void org.keycloak.authentication.authenticators.browser.OTPFormAuthenticator.validateOTP ( AuthenticationFlowContext  context)
inline
51  {
52  MultivaluedMap<String, String> inputData = context.getHttpRequest().getDecodedFormParameters();
53  if (inputData.containsKey("cancel")) {
54  context.resetFlow();
55  return;
56  }
57  String password = inputData.getFirst(CredentialRepresentation.TOTP);
58  if (password == null) {
59  Response challengeResponse = challenge(context, null);
60  context.challenge(challengeResponse);
61  return;
62  }
63  boolean valid = context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(),
64  UserCredentialModel.otp(context.getRealm().getOTPPolicy().getType(), password));
65  if (!valid) {
66  context.getEvent().user(context.getUser())
67  .error(Errors.INVALID_USER_CREDENTIALS);
68  Response challengeResponse = challenge(context, Messages.INVALID_TOTP);
69  context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, challengeResponse);
70  return;
71  }
72  context.success();
73  }
Response challenge(AuthenticationFlowContext context, String error)
Definition: OTPFormAuthenticator.java:80

◆ validatePassword()

boolean org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.validatePassword ( AuthenticationFlowContext  context,
UserModel  user,
MultivaluedMap< String, String >  inputData 
)
inlineinherited
191  {
192  List<CredentialInput> credentials = new LinkedList<>();
193  String password = inputData.getFirst(CredentialRepresentation.PASSWORD);
194  credentials.add(UserCredentialModel.password(password));
195 
196  if (isTemporarilyDisabledByBruteForce(context, user)) return false;
197 
198  if (password != null && !password.isEmpty() && context.getSession().userCredentialManager().isValid(context.getRealm(), user, credentials)) {
199  return true;
200  } else {
201  context.getEvent().user(user);
202  context.getEvent().error(Errors.INVALID_USER_CREDENTIALS);
203  Response challengeResponse = invalidCredentials(context);
204  context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, challengeResponse);
205  context.clearUser();
206  return false;
207  }
208  }
Response invalidCredentials(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:75
boolean isTemporarilyDisabledByBruteForce(AuthenticationFlowContext context, UserModel user)
Definition: AbstractUsernameFormAuthenticator.java:210

◆ validateUserAndPassword()

boolean org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.validateUserAndPassword ( AuthenticationFlowContext  context,
MultivaluedMap< String, String >  inputData 
)
inlineinherited
136  {
137  String username = inputData.getFirst(AuthenticationManager.FORM_USERNAME);
138  if (username == null) {
139  context.getEvent().error(Errors.USER_NOT_FOUND);
140  Response challengeResponse = invalidUser(context);
141  context.failureChallenge(AuthenticationFlowError.INVALID_USER, challengeResponse);
142  return false;
143  }
144 
145  // remove leading and trailing whitespace
146  username = username.trim();
147 
148  context.getEvent().detail(Details.USERNAME, username);
149  context.getAuthenticationSession().setAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, username);
150 
151  UserModel user = null;
152  try {
153  user = KeycloakModelUtils.findUserByNameOrEmail(context.getSession(), context.getRealm(), username);
154  } catch (ModelDuplicateException mde) {
155  ServicesLogger.LOGGER.modelDuplicateException(mde);
156 
157  // Could happen during federation import
158  if (mde.getDuplicateFieldName() != null && mde.getDuplicateFieldName().equals(UserModel.EMAIL)) {
159  setDuplicateUserChallenge(context, Errors.EMAIL_IN_USE, Messages.EMAIL_EXISTS, AuthenticationFlowError.INVALID_USER);
160  } else {
161  setDuplicateUserChallenge(context, Errors.USERNAME_IN_USE, Messages.USERNAME_EXISTS, AuthenticationFlowError.INVALID_USER);
162  }
163 
164  return false;
165  }
166 
167  if (invalidUser(context, user)) {
168  return false;
169  }
170 
171  if (!validatePassword(context, user, inputData)) {
172  return false;
173  }
174 
175  if (!enabledUser(context, user)) {
176  return false;
177  }
178 
179  String rememberMe = inputData.getFirst("rememberMe");
180  boolean remember = rememberMe != null && rememberMe.equalsIgnoreCase("on");
181  if (remember) {
182  context.getAuthenticationSession().setAuthNote(Details.REMEMBER_ME, "true");
183  context.getEvent().detail(Details.REMEMBER_ME, "true");
184  } else {
185  context.getAuthenticationSession().removeAuthNote(Details.REMEMBER_ME);
186  }
187  context.setUser(user);
188  return true;
189  }
Response invalidUser(AuthenticationFlowContext context)
Definition: AbstractUsernameFormAuthenticator.java:59
Response setDuplicateUserChallenge(AuthenticationFlowContext context, String eventError, String loginFormError, AuthenticationFlowError authenticatorError)
Definition: AbstractUsernameFormAuthenticator.java:80
boolean enabledUser(AuthenticationFlowContext context, UserModel user)
Definition: AbstractUsernameFormAuthenticator.java:122
boolean validatePassword(AuthenticationFlowContext context, UserModel user, MultivaluedMap< String, String > inputData)
Definition: AbstractUsernameFormAuthenticator.java:191

メンバ詳解

◆ ATTEMPTED_USERNAME

final String org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME = "ATTEMPTED_USERNAME"
staticinherited

◆ REGISTRATION_FORM_ACTION

final String org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.REGISTRATION_FORM_ACTION = "registration_form"
staticinherited

このクラス詳解は次のファイルから抽出されました: