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

公開メンバ関数

 DefaultAuthenticationFlow (AuthenticationProcessor processor, AuthenticationFlowModel flow)
 
Response processAction (String actionExecution)
 
Response processFlow ()
 
Response processResult (AuthenticationProcessor.Result result, boolean isAction)
 
Response sendChallenge (AuthenticationProcessor.Result result, AuthenticationExecutionModel execution)
 

限定公開メンバ関数

boolean isProcessed (AuthenticationExecutionModel model)
 
Authenticator createAuthenticator (AuthenticatorFactory factory)
 

変数

Response alternativeChallenge = null
 
AuthenticationExecutionModel challengedAlternativeExecution = null
 
boolean alternativeSuccessful = false
 
List< AuthenticationExecutionModel > executions
 
Iterator< AuthenticationExecutionModel > executionIterator
 
AuthenticationProcessor processor
 
AuthenticationFlowModel flow
 

静的非公開変数類

static final Logger logger = Logger.getLogger(DefaultAuthenticationFlow.class)
 

詳解

著者
Bill Burke
バージョン
Revision
1

構築子と解体子

◆ DefaultAuthenticationFlow()

org.keycloak.authentication.DefaultAuthenticationFlow.DefaultAuthenticationFlow ( AuthenticationProcessor  processor,
AuthenticationFlowModel  flow 
)
inline
46  {
47  this.processor = processor;
48  this.flow = flow;
49  this.executions = processor.getRealm().getAuthenticationExecutions(flow.getId());
50  this.executionIterator = executions.iterator();
51  }
List< AuthenticationExecutionModel > executions
Definition: DefaultAuthenticationFlow.java:41
AuthenticationFlowModel flow
Definition: DefaultAuthenticationFlow.java:44
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43
Iterator< AuthenticationExecutionModel > executionIterator
Definition: DefaultAuthenticationFlow.java:42
RealmModel getRealm()
Definition: AuthenticationProcessor.java:128

関数詳解

◆ createAuthenticator()

Authenticator org.keycloak.authentication.DefaultAuthenticationFlow.createAuthenticator ( AuthenticatorFactory  factory)
inlineprotected
62  {
63  String display = processor.getAuthenticationSession().getAuthNote(OAuth2Constants.DISPLAY);
64  if (display == null) return factory.create(processor.getSession());
65 
66 
67  if (factory instanceof DisplayTypeAuthenticatorFactory) {
68  Authenticator authenticator = ((DisplayTypeAuthenticatorFactory)factory).createDisplay(processor.getSession(), display);
69  if (authenticator != null) return authenticator;
70  }
71  // todo create a provider for handling lack of display support
72  if (OAuth2Constants.DISPLAY_CONSOLE.equalsIgnoreCase(display)) {
73  processor.getAuthenticationSession().removeAuthNote(OAuth2Constants.DISPLAY);
74  throw new AuthenticationFlowException(AuthenticationFlowError.DISPLAY_NOT_SUPPORTED,
75  ConsoleDisplayMode.browserContinue(processor.getSession(), processor.getRefreshUrl(true).toString()));
76 
77  } else {
78  return factory.create(processor.getSession());
79  }
80  }
KeycloakSession getSession()
Definition: AuthenticationProcessor.java:156
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
URI getRefreshUrl(boolean authSessionIdParam)
Definition: AuthenticationProcessor.java:255
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43

◆ isProcessed()

boolean org.keycloak.authentication.DefaultAuthenticationFlow.isProcessed ( AuthenticationExecutionModel  model)
inlineprotected
53  {
54  if (model.isDisabled()) return true;
55  AuthenticationSessionModel.ExecutionStatus status = processor.getAuthenticationSession().getExecutionStatus().get(model.getId());
56  if (status == null) return false;
57  return status == AuthenticationSessionModel.ExecutionStatus.SUCCESS || status == AuthenticationSessionModel.ExecutionStatus.SKIPPED
58  || status == AuthenticationSessionModel.ExecutionStatus.ATTEMPTED
59  || status == AuthenticationSessionModel.ExecutionStatus.SETUP_REQUIRED;
60  }
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43

◆ processAction()

Response org.keycloak.authentication.DefaultAuthenticationFlow.processAction ( String  actionExecution)
inline
84  {
85  logger.debugv("processAction: {0}", actionExecution);
86  while (executionIterator.hasNext()) {
87  AuthenticationExecutionModel model = executionIterator.next();
88  logger.debugv("check: {0} requirement: {1}", model.getAuthenticator(), model.getRequirement().toString());
89  if (isProcessed(model)) {
90  logger.debug("execution is processed");
91  if (!alternativeSuccessful && model.isAlternative() && processor.isSuccessful(model))
92  alternativeSuccessful = true;
93  continue;
94  }
95  if (model.isAuthenticatorFlow()) {
96  AuthenticationFlow authenticationFlow = processor.createFlowExecution(model.getFlowId(), model);
97  Response flowChallenge = authenticationFlow.processAction(actionExecution);
98  if (flowChallenge == null) {
99  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SUCCESS);
100  if (model.isAlternative()) alternativeSuccessful = true;
101  return processFlow();
102  } else {
103  return flowChallenge;
104  }
105  } else if (model.getId().equals(actionExecution)) {
106  AuthenticatorFactory factory = (AuthenticatorFactory) processor.getSession().getKeycloakSessionFactory().getProviderFactory(Authenticator.class, model.getAuthenticator());
107  if (factory == null) {
108  throw new RuntimeException("Unable to find factory for AuthenticatorFactory: " + model.getAuthenticator() + " did you forget to declare it in a META-INF/services file?");
109  }
110  Authenticator authenticator = createAuthenticator(factory);
111  AuthenticationProcessor.Result result = processor.createAuthenticatorContext(model, authenticator, executions);
112  logger.debugv("action: {0}", model.getAuthenticator());
113  authenticator.action(result);
114  Response response = processResult(result, true);
115  if (response == null) {
116  processor.getAuthenticationSession().removeAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION);
117  return processFlow();
118  } else return response;
119  }
120  }
121  throw new AuthenticationFlowException("action is not in current execution", AuthenticationFlowError.INTERNAL_ERROR);
122  }
AuthenticationFlow createFlowExecution(String flowId, AuthenticationExecutionModel execution)
Definition: AuthenticationProcessor.java:757
List< AuthenticationExecutionModel > executions
Definition: DefaultAuthenticationFlow.java:41
boolean alternativeSuccessful
Definition: DefaultAuthenticationFlow.java:40
boolean isSuccessful(AuthenticationExecutionModel model)
Definition: AuthenticationProcessor.java:650
KeycloakSession getSession()
Definition: AuthenticationProcessor.java:156
static final Logger logger
Definition: DefaultAuthenticationFlow.java:37
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
Response processFlow()
Definition: DefaultAuthenticationFlow.java:125
AuthenticationProcessor.Result createAuthenticatorContext(AuthenticationExecutionModel model, Authenticator authenticator, List< AuthenticationExecutionModel > executions)
Definition: AuthenticationProcessor.java:1016
Response processResult(AuthenticationProcessor.Result result, boolean isAction)
Definition: DefaultAuthenticationFlow.java:229
Authenticator createAuthenticator(AuthenticatorFactory factory)
Definition: DefaultAuthenticationFlow.java:62
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43
Iterator< AuthenticationExecutionModel > executionIterator
Definition: DefaultAuthenticationFlow.java:42
boolean isProcessed(AuthenticationExecutionModel model)
Definition: DefaultAuthenticationFlow.java:53

◆ processFlow()

Response org.keycloak.authentication.DefaultAuthenticationFlow.processFlow ( )
inline
125  {
126  logger.debug("processFlow");
127  while (executionIterator.hasNext()) {
128  AuthenticationExecutionModel model = executionIterator.next();
129  logger.debugv("check execution: {0} requirement: {1}", model.getAuthenticator(), model.getRequirement().toString());
130 
131  if (isProcessed(model)) {
132  logger.debug("execution is processed");
133  if (!alternativeSuccessful && model.isAlternative() && processor.isSuccessful(model))
134  alternativeSuccessful = true;
135  continue;
136  }
137  if (model.isAlternative() && alternativeSuccessful) {
138  logger.debug("Skip alternative execution");
139  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SKIPPED);
140  continue;
141  }
142  if (model.isAuthenticatorFlow()) {
143  logger.debug("execution is flow");
144  AuthenticationFlow authenticationFlow = processor.createFlowExecution(model.getFlowId(), model);
145 
146  Response flowChallenge = null;
147  try {
148  flowChallenge = authenticationFlow.processFlow();
149  } catch (AuthenticationFlowException afe) {
150  if (model.isAlternative()) {
151  logger.debug("Thrown exception in alternative Subflow. Ignoring Subflow");
152  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.ATTEMPTED);
153  continue;
154  } else {
155  throw afe;
156  }
157  }
158 
159  if (flowChallenge == null) {
160  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SUCCESS);
161  if (model.isAlternative()) alternativeSuccessful = true;
162  continue;
163  } else {
164  if (model.isAlternative()) {
165  alternativeChallenge = flowChallenge;
167  } else if (model.isRequired()) {
168  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
169  return flowChallenge;
170  } else if (model.isOptional()) {
171  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SKIPPED);
172  continue;
173  } else {
174  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SKIPPED);
175  continue;
176  }
177  return flowChallenge;
178  }
179  }
180 
181  AuthenticatorFactory factory = (AuthenticatorFactory) processor.getSession().getKeycloakSessionFactory().getProviderFactory(Authenticator.class, model.getAuthenticator());
182  if (factory == null) {
183  throw new RuntimeException("Unable to find factory for AuthenticatorFactory: " + model.getAuthenticator() + " did you forget to declare it in a META-INF/services file?");
184  }
185  Authenticator authenticator = createAuthenticator(factory);
186  logger.debugv("authenticator: {0}", factory.getId());
187  UserModel authUser = processor.getAuthenticationSession().getAuthenticatedUser();
188 
189  if (authenticator.requiresUser() && authUser == null) {
190  if (alternativeChallenge != null) {
191  processor.getAuthenticationSession().setExecutionStatus(challengedAlternativeExecution.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
192  return alternativeChallenge;
193  }
194  throw new AuthenticationFlowException("authenticator: " + factory.getId(), AuthenticationFlowError.UNKNOWN_USER);
195  }
196  boolean configuredFor = false;
197  if (authenticator.requiresUser() && authUser != null) {
198  configuredFor = authenticator.configuredFor(processor.getSession(), processor.getRealm(), authUser);
199  if (!configuredFor) {
200  if (model.isRequired()) {
201  if (factory.isUserSetupAllowed()) {
202  logger.debugv("authenticator SETUP_REQUIRED: {0}", factory.getId());
203  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SETUP_REQUIRED);
204  authenticator.setRequiredActions(processor.getSession(), processor.getRealm(), processor.getAuthenticationSession().getAuthenticatedUser());
205  continue;
206  } else {
207  throw new AuthenticationFlowException(AuthenticationFlowError.CREDENTIAL_SETUP_REQUIRED);
208  }
209  } else if (model.isOptional()) {
210  processor.getAuthenticationSession().setExecutionStatus(model.getId(), AuthenticationSessionModel.ExecutionStatus.SKIPPED);
211  continue;
212  }
213  }
214  }
215  // skip if action as successful already
216 // Response redirect = processor.checkWasSuccessfulBrowserAction();
217 // if (redirect != null) return redirect;
218 
219  AuthenticationProcessor.Result context = processor.createAuthenticatorContext(model, authenticator, executions);
220  logger.debugv("invoke authenticator.authenticate: {0}", factory.getId());
221  authenticator.authenticate(context);
222  Response response = processResult(context, false);
223  if (response != null) return response;
224  }
225  return null;
226  }
AuthenticationFlow createFlowExecution(String flowId, AuthenticationExecutionModel execution)
Definition: AuthenticationProcessor.java:757
List< AuthenticationExecutionModel > executions
Definition: DefaultAuthenticationFlow.java:41
boolean alternativeSuccessful
Definition: DefaultAuthenticationFlow.java:40
boolean isSuccessful(AuthenticationExecutionModel model)
Definition: AuthenticationProcessor.java:650
KeycloakSession getSession()
Definition: AuthenticationProcessor.java:156
AuthenticationExecutionModel challengedAlternativeExecution
Definition: DefaultAuthenticationFlow.java:39
static final Logger logger
Definition: DefaultAuthenticationFlow.java:37
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
AuthenticationProcessor.Result createAuthenticatorContext(AuthenticationExecutionModel model, Authenticator authenticator, List< AuthenticationExecutionModel > executions)
Definition: AuthenticationProcessor.java:1016
Response alternativeChallenge
Definition: DefaultAuthenticationFlow.java:38
Response processResult(AuthenticationProcessor.Result result, boolean isAction)
Definition: DefaultAuthenticationFlow.java:229
Authenticator createAuthenticator(AuthenticatorFactory factory)
Definition: DefaultAuthenticationFlow.java:62
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43
Iterator< AuthenticationExecutionModel > executionIterator
Definition: DefaultAuthenticationFlow.java:42
RealmModel getRealm()
Definition: AuthenticationProcessor.java:128
boolean isProcessed(AuthenticationExecutionModel model)
Definition: DefaultAuthenticationFlow.java:53

◆ processResult()

Response org.keycloak.authentication.DefaultAuthenticationFlow.processResult ( AuthenticationProcessor.Result  result,
boolean  isAction 
)
inline
229  {
230  AuthenticationExecutionModel execution = result.getExecution();
231  FlowStatus status = result.getStatus();
232  switch (status) {
233  case SUCCESS:
234  logger.debugv("authenticator SUCCESS: {0}", execution.getAuthenticator());
235  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.SUCCESS);
236  if (execution.isAlternative()) alternativeSuccessful = true;
237  return null;
238  case FAILED:
239  logger.debugv("authenticator FAILED: {0}", execution.getAuthenticator());
241  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.FAILED);
242  if (result.getChallenge() != null) {
243  return sendChallenge(result, execution);
244  }
245  throw new AuthenticationFlowException(result.getError());
246  case FORK:
247  logger.debugv("reset browser login from authenticator: {0}", execution.getAuthenticator());
248  processor.getAuthenticationSession().setAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION, execution.getId());
249  throw new ForkFlowException(result.getSuccessMessage(), result.getErrorMessage());
250  case FORCE_CHALLENGE:
251  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
252  return sendChallenge(result, execution);
253  case CHALLENGE:
254  logger.debugv("authenticator CHALLENGE: {0}", execution.getAuthenticator());
255  if (execution.isRequired()) {
256  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
257  return sendChallenge(result, execution);
258  }
259  UserModel authenticatedUser = processor.getAuthenticationSession().getAuthenticatedUser();
260  if (execution.isOptional() && authenticatedUser != null && result.getAuthenticator().configuredFor(processor.getSession(), processor.getRealm(), authenticatedUser)) {
261  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
262  return sendChallenge(result, execution);
263  }
264  if (execution.isAlternative()) {
265  alternativeChallenge = result.getChallenge();
266  challengedAlternativeExecution = execution;
267  } else {
268  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.SKIPPED);
269  }
270  return null;
271  case FAILURE_CHALLENGE:
272  logger.debugv("authenticator FAILURE_CHALLENGE: {0}", execution.getAuthenticator());
274  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.CHALLENGED);
275  return sendChallenge(result, execution);
276  case ATTEMPTED:
277  logger.debugv("authenticator ATTEMPTED: {0}", execution.getAuthenticator());
278  if (execution.getRequirement() == AuthenticationExecutionModel.Requirement.REQUIRED) {
279  throw new AuthenticationFlowException(AuthenticationFlowError.INVALID_CREDENTIALS);
280  }
281  processor.getAuthenticationSession().setExecutionStatus(execution.getId(), AuthenticationSessionModel.ExecutionStatus.ATTEMPTED);
282  return null;
283  case FLOW_RESET:
285  return processor.authenticate();
286  default:
287  logger.debugv("authenticator INTERNAL_ERROR: {0}", execution.getAuthenticator());
288  ServicesLogger.LOGGER.unknownResultStatus();
289  throw new AuthenticationFlowException(AuthenticationFlowError.INTERNAL_ERROR);
290  }
291  }
Response sendChallenge(AuthenticationProcessor.Result result, AuthenticationExecutionModel execution)
Definition: DefaultAuthenticationFlow.java:293
boolean alternativeSuccessful
Definition: DefaultAuthenticationFlow.java:40
KeycloakSession getSession()
Definition: AuthenticationProcessor.java:156
AuthenticationExecutionModel challengedAlternativeExecution
Definition: DefaultAuthenticationFlow.java:39
static final Logger logger
Definition: DefaultAuthenticationFlow.java:37
void logFailure()
Definition: AuthenticationProcessor.java:619
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
Response alternativeChallenge
Definition: DefaultAuthenticationFlow.java:38
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43
void resetFlow()
Definition: AuthenticationProcessor.java:805
Response authenticate()
Definition: AuthenticationProcessor.java:777
RealmModel getRealm()
Definition: AuthenticationProcessor.java:128

◆ sendChallenge()

Response org.keycloak.authentication.DefaultAuthenticationFlow.sendChallenge ( AuthenticationProcessor.Result  result,
AuthenticationExecutionModel  execution 
)
inline
293  {
294  processor.getAuthenticationSession().setAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION, execution.getId());
295  return result.getChallenge();
296  }
AuthenticationSessionModel getAuthenticationSession()
Definition: AuthenticationProcessor.java:144
AuthenticationProcessor processor
Definition: DefaultAuthenticationFlow.java:43

メンバ詳解

◆ alternativeChallenge

Response org.keycloak.authentication.DefaultAuthenticationFlow.alternativeChallenge = null
package

◆ alternativeSuccessful

boolean org.keycloak.authentication.DefaultAuthenticationFlow.alternativeSuccessful = false
package

◆ challengedAlternativeExecution

AuthenticationExecutionModel org.keycloak.authentication.DefaultAuthenticationFlow.challengedAlternativeExecution = null
package

◆ executionIterator

Iterator<AuthenticationExecutionModel> org.keycloak.authentication.DefaultAuthenticationFlow.executionIterator
package

◆ executions

List<AuthenticationExecutionModel> org.keycloak.authentication.DefaultAuthenticationFlow.executions
package

◆ flow

AuthenticationFlowModel org.keycloak.authentication.DefaultAuthenticationFlow.flow
package

◆ logger

final Logger org.keycloak.authentication.DefaultAuthenticationFlow.logger = Logger.getLogger(DefaultAuthenticationFlow.class)
staticprivate

◆ processor

AuthenticationProcessor org.keycloak.authentication.DefaultAuthenticationFlow.processor
package

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