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

公開メンバ関数

boolean configuredFor (KeycloakSession session, RealmModel realm, UserModel user)
 
boolean requiresUser ()
 
void authenticate (AuthenticationFlowContext context)
 
boolean invalidUser (AuthenticationFlowContext context, UserModel user)
 
void action (AuthenticationFlowContext context)
 
void setRequiredActions (KeycloakSession session, RealmModel realm, UserModel user)
 
void close ()
 
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"
 

限定公開メンバ関数

boolean onAuthenticate (AuthenticationFlowContext context, String[] challenge)
 
String getAuthorizationHeader (AuthenticationFlowContext context)
 
boolean checkUsernameAndPassword (AuthenticationFlowContext context, String username, String password)
 
String [] getChallenge (String authorizationHeader)
 
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)
 

非公開メンバ関数

boolean checkOtp (AuthenticationFlowContext context, String otp)
 

詳解

著者
Bill Burke
バージョン
Revision
1

関数詳解

◆ action()

void org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.action ( AuthenticationFlowContext  context)
inlineinherited
133  {
134 
135  }

◆ authenticate()

void org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.authenticate ( AuthenticationFlowContext  context)
inlineinherited
48  {
49  String authorizationHeader = getAuthorizationHeader(context);
50 
51  if (authorizationHeader == null) {
52  context.challenge(challengeResponse(context));
53  return;
54  }
55 
56  String[] challenge = getChallenge(authorizationHeader);
57 
58  if (challenge == null) {
59  context.challenge(challengeResponse(context));
60  return;
61  }
62 
63  if (onAuthenticate(context, challenge)) {
64  context.success();
65  return;
66  }
67 
68  context.setUser(null);
69  context.challenge(challengeResponse(context));
70  }
String getAuthorizationHeader(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:80
String [] getChallenge(String authorizationHeader)
Definition: BasicAuthAuthenticator.java:97
boolean onAuthenticate(AuthenticationFlowContext context, String[] challenge)
Definition: BasicAuthAuthenticator.java:72
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ checkOtp()

boolean org.keycloak.authentication.authenticators.challenge.BasicAuthOTPAuthenticator.checkOtp ( AuthenticationFlowContext  context,
String  otp 
)
inlineprivate
57  {
58  return context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(),
59  UserCredentialModel.otp(context.getRealm().getOTPPolicy().getType(), otp));
60  }

◆ checkUsernameAndPassword()

boolean org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.checkUsernameAndPassword ( AuthenticationFlowContext  context,
String  username,
String  password 
)
inlineprotectedinherited
84  {
85  MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
86 
87  map.putSingle(AuthenticationManager.FORM_USERNAME, username);
88  map.putSingle(CredentialRepresentation.PASSWORD, password);
89 
90  if (validateUserAndPassword(context, map)) {
91  return true;
92  }
93 
94  return false;
95  }
boolean validateUserAndPassword(AuthenticationFlowContext context, MultivaluedMap< String, String > inputData)
Definition: AbstractUsernameFormAuthenticator.java:136

◆ close()

void org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.close ( )
inlineinherited
147  {
148 
149  }

◆ configuredFor()

boolean org.keycloak.authentication.authenticators.challenge.BasicAuthOTPAuthenticator.configuredFor ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inline
63  {
64  return session.userCredentialManager().isConfiguredFor(realm, user, realm.getOTPPolicy().getType());
65  }

◆ disabledUser()

Response org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.disabledUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
113  {
114  return challengeResponse(context);
115  }
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ 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

◆ getAuthorizationHeader()

String org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.getAuthorizationHeader ( AuthenticationFlowContext  context)
inlineprotectedinherited
80  {
81  return context.getHttpRequest().getHttpHeaders().getRequestHeaders().getFirst(HttpHeaders.AUTHORIZATION);
82  }

◆ getChallenge()

String [] org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.getChallenge ( String  authorizationHeader)
inlineprotectedinherited
97  {
98  String[] challenge = BasicAuthHelper.parseHeader(authorizationHeader);
99 
100  if (challenge.length < 2) {
101  return null;
102  }
103 
104  return challenge;
105  }

◆ invalidCredentials()

Response org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.invalidCredentials ( AuthenticationFlowContext  context)
inlineprotectedinherited
123  {
124  return challengeResponse(context);
125  }
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ invalidUser() [1/2]

Response org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.invalidUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
108  {
109  return challengeResponse(context);
110  }
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ 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

◆ onAuthenticate()

boolean org.keycloak.authentication.authenticators.challenge.BasicAuthOTPAuthenticator.onAuthenticate ( AuthenticationFlowContext  context,
String []  challenge 
)
inlineprotected
34  {
35  String username = challenge[0];
36  String password = challenge[1];
37  OTPPolicy otpPolicy = context.getRealm().getOTPPolicy();
38  int otpLength = otpPolicy.getDigits();
39 
40  if (password.length() < otpLength) {
41  return false;
42  }
43 
44  password = password.substring(0, password.length() - otpLength);
45 
46  if (checkUsernameAndPassword(context, username, password)) {
47  String otp = password.substring(password.length() - otpLength);
48 
49  if (checkOtp(context, otp)) {
50  return true;
51  }
52  }
53 
54  return false;
55  }
boolean checkOtp(AuthenticationFlowContext context, String otp)
Definition: BasicAuthOTPAuthenticator.java:57
boolean checkUsernameAndPassword(AuthenticationFlowContext context, String username, String password)
Definition: BasicAuthAuthenticator.java:84

◆ requiresUser()

boolean org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.requiresUser ( )
inlineinherited
43  {
44  return false;
45  }

◆ 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.challenge.BasicAuthAuthenticator.setDuplicateUserChallenge ( AuthenticationFlowContext  context,
String  eventError,
String  loginFormError,
AuthenticationFlowError  authenticatorError 
)
inlineprotectedinherited
128  {
129  return challengeResponse(context);
130  }
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ setRequiredActions()

void org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.setRequiredActions ( KeycloakSession  session,
RealmModel  realm,
UserModel  user 
)
inlineinherited
143  {
144  }

◆ temporarilyDisabledUser()

Response org.keycloak.authentication.authenticators.challenge.BasicAuthAuthenticator.temporarilyDisabledUser ( AuthenticationFlowContext  context)
inlineprotectedinherited
118  {
119  return challengeResponse(context);
120  }
Response challengeResponse(AuthenticationFlowContext context)
Definition: BasicAuthAuthenticator.java:151

◆ 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

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