gluu
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.xdi.oxauth.auth.Authenticator クラス
org.xdi.oxauth.auth.Authenticator 連携図
Collaboration graph

公開メンバ関数

boolean authenticate ()
 
String authenticateWithOutcome ()
 
boolean authenticateWebService (HttpServletRequest servletRequest, boolean skipPassword)
 
boolean authenticateWebService (HttpServletRequest servletRequest)
 
boolean authenticateImpl (HttpServletRequest servletRequest, boolean interactive, boolean skipPassword)
 
boolean clientAuthentication (Credentials credentials, boolean interactive, boolean skipPassword)
 
String prepareAuthenticationForStep ()
 
boolean authenticateBySessionId (String p_sessionId)
 
boolean authenticateBySessionId (SessionId sessionId)
 
void configureSessionClient (Client client)
 
void addMessage (Severity severity, String summary)
 
String getMaskMobilenumber (String mobile_number)
 

非公開メンバ関数

void showClientAuthenticationLog (Client client)
 
boolean userAuthenticationInteractive ()
 
boolean updateSession (SessionId sessionId, Map< String, String > sessionIdAttributes)
 
boolean userAuthenticationService ()
 
void updateExtraParameters (CustomScriptConfiguration customScriptConfiguration, final int step, Map< String, String > sessionIdAttributes)
 
Map< String, String > getExternalScriptExtraParameters (Map< String, String > sessionIdAttributes)
 
void setExternalScriptExtraParameters (Map< String, String > sessionIdAttributes, Map< String, String > authExternalAttributes)
 
void clearExternalScriptExtraParameters (Map< String, String > sessionIdAttributes)
 
void setIdentityWorkingParameters (Map< String, String > sessionIdAttributes)
 
String prepareAuthenticationForStepImpl ()
 
void initCustomAuthenticatorVariables (Map< String, String > sessionIdAttributes)
 
boolean authenticationFailed ()
 
void authenticationFailedSessionInvalid ()
 
void authenticationSessionExpired ()
 
void markAuthStepAsPassed (Map< String, String > sessionIdAttributes, Integer authStep)
 
boolean isAuthStepPassed (Map< String, String > sessionIdAttributes, Integer authStep)
 
boolean isPassedPreviousAuthSteps (Map< String, String > sessionIdAttributes, Integer authStep)
 

非公開変数類

Logger logger
 
Identity identity
 
Credentials credentials
 
ClientService clientService
 
SessionIdService sessionIdService
 
AuthenticationService authenticationService
 
ExternalAuthenticationService externalAuthenticationService
 
AppConfiguration appConfiguration
 
FacesContext facesContext
 
ExternalContext externalContext
 
FacesService facesService
 
FacesMessages facesMessages
 
LanguageBean languageBean
 
RequestParameterService requestParameterService
 
String authAcr
 
Integer authStep
 
boolean addedErrorMessage
 

静的非公開変数類

static final String INVALID_SESSION_MESSAGE = "login.errorSessionInvalidMessage"
 
static final String AUTH_EXTERNAL_ATTRIBUTES = "auth_external_attributes"
 

詳解

Authenticator component

著者
Javier Rojas Blum
Yuriy Movchan
バージョン
August 23, 2018

関数詳解

◆ addMessage()

void org.xdi.oxauth.auth.Authenticator.addMessage ( Severity  severity,
String  summary 
)
inline
749  {
750  String msg = languageBean.getMessage(summary);
751  FacesMessage message = new FacesMessage(severity, msg, null);
752  facesContext.addMessage(null, message);
753  }
String getMessage(String key)
Definition: LanguageBean.java:59
LanguageBean languageBean
Definition: Authenticator.java:100
FacesContext facesContext
Definition: Authenticator.java:88

◆ authenticate()

boolean org.xdi.oxauth.auth.Authenticator.authenticate ( )
inline

Tries to authenticate an user, returns true if the authentication succeed

戻り値
Returns true if the authentication succeed
117  {
118  HttpServletRequest servletRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();
119  if (!authenticateImpl(servletRequest, true, false)) {
120  return authenticationFailed();
121  } else {
122  return true;
123  }
124  }
boolean authenticateImpl(HttpServletRequest servletRequest, boolean interactive, boolean skipPassword)
Definition: Authenticator.java:146
FacesContext facesContext
Definition: Authenticator.java:88
boolean authenticationFailed()
Definition: Authenticator.java:702

◆ authenticateBySessionId() [1/2]

boolean org.xdi.oxauth.auth.Authenticator.authenticateBySessionId ( String  p_sessionId)
inline
651  {
652  if (StringUtils.isNotBlank(p_sessionId) && appConfiguration.getSessionIdEnabled()) {
653  try {
654  SessionId sessionId = sessionIdService.getSessionId(p_sessionId);
655  return authenticateBySessionId(sessionId);
656  } catch (Exception e) {
657  logger.trace(e.getMessage(), e);
658  }
659  }
660 
661  return false;
662  }
SessionId getSessionId()
Definition: SessionIdService.java:360
boolean authenticateBySessionId(String p_sessionId)
Definition: Authenticator.java:651
Logger logger
Definition: Authenticator.java:64
AppConfiguration appConfiguration
Definition: Authenticator.java:85
SessionIdService sessionIdService
Definition: Authenticator.java:76
Boolean getSessionIdEnabled()
Definition: AppConfiguration.java:1049

◆ authenticateBySessionId() [2/2]

boolean org.xdi.oxauth.auth.Authenticator.authenticateBySessionId ( SessionId  sessionId)
inline
664  {
665  if (sessionId == null) {
666  return false;
667  }
668  String p_sessionId = sessionId.getId();
669 
670  logger.trace("authenticateBySessionId, sessionId = '{}', session = '{}', state= '{}'", p_sessionId, sessionId,
671  sessionId.getState());
672  // IMPORTANT : authenticate by session id only if state of session is
673  // authenticated!
674  if (SessionIdState.AUTHENTICATED == sessionId.getState()) {
675  final User user = authenticationService.getUserOrRemoveSession(sessionId);
676  if (user != null) {
677  try {
678  authenticationService.quietLogin(user.getUserId());
679 
681  } catch (Exception e) {
682  logger.trace(e.getMessage(), e);
683  }
684 
685  return true;
686  }
687  }
688 
689  return false;
690  }
SessionId configureEventUser()
Definition: AuthenticationService.java:449
User getUserOrRemoveSession(SessionId p_sessionId)
Definition: AuthenticationService.java:557
Logger logger
Definition: Authenticator.java:64
AuthenticationService authenticationService
Definition: Authenticator.java:79
void quietLogin(String userName)
Definition: AuthenticationService.java:477

◆ authenticateImpl()

boolean org.xdi.oxauth.auth.Authenticator.authenticateImpl ( HttpServletRequest  servletRequest,
boolean  interactive,
boolean  skipPassword 
)
inline
146  {
147  boolean authenticated = false;
148  try {
149  logger.trace("Authenticating ... (interactive: " + interactive + ", skipPassword: " + skipPassword
150  + ", credentials.username: " + credentials.getUsername() + ")");
151  if (StringHelper.isNotEmpty(credentials.getUsername())
152  && (skipPassword || StringHelper.isNotEmpty(credentials.getPassword()))
153  && servletRequest != null && servletRequest.getRequestURI().endsWith("/token")) {
154  authenticated = clientAuthentication(credentials, interactive, skipPassword);
155  } else {
156  if (interactive) {
157  authenticated = userAuthenticationInteractive();
158  } else {
159  authenticated = userAuthenticationService();
160  }
161  }
162  } catch (Exception ex) {
163  logger.error(ex.getMessage(), ex);
164  }
165 
166  if (authenticated) {
167  logger.trace("Authentication successfully for '{}'", credentials.getUsername());
168  return true;
169  }
170 
171  logger.info("Authentication failed for '{}'", credentials.getUsername());
172  return false;
173  }
boolean userAuthenticationService()
Definition: Authenticator.java:403
Logger logger
Definition: Authenticator.java:64
boolean userAuthenticationInteractive()
Definition: Authenticator.java:227
boolean clientAuthentication(Credentials credentials, boolean interactive, boolean skipPassword)
Definition: Authenticator.java:175
Credentials credentials
Definition: Authenticator.java:70

◆ authenticateWebService() [1/2]

boolean org.xdi.oxauth.auth.Authenticator.authenticateWebService ( HttpServletRequest  servletRequest,
boolean  skipPassword 
)
inline
138  {
139  return authenticateImpl(servletRequest, false, skipPassword);
140  }
boolean authenticateImpl(HttpServletRequest servletRequest, boolean interactive, boolean skipPassword)
Definition: Authenticator.java:146

◆ authenticateWebService() [2/2]

boolean org.xdi.oxauth.auth.Authenticator.authenticateWebService ( HttpServletRequest  servletRequest)
inline
142  {
143  return authenticateImpl(servletRequest, false, false);
144  }
boolean authenticateImpl(HttpServletRequest servletRequest, boolean interactive, boolean skipPassword)
Definition: Authenticator.java:146

◆ authenticateWithOutcome()

String org.xdi.oxauth.auth.Authenticator.authenticateWithOutcome ( )
inline
126  {
127  HttpServletRequest servletRequest = (HttpServletRequest) facesContext.getExternalContext().getRequest();
128  boolean result = authenticateImpl(servletRequest, true, false);
129  if (result) {
130  return Constants.RESULT_SUCCESS;
131  } else {
132  addMessage(FacesMessage.SEVERITY_ERROR, "login.failedToAuthenticate");
133  return Constants.RESULT_FAILURE;
134  }
135 
136  }
boolean authenticateImpl(HttpServletRequest servletRequest, boolean interactive, boolean skipPassword)
Definition: Authenticator.java:146
FacesContext facesContext
Definition: Authenticator.java:88
void addMessage(Severity severity, String summary)
Definition: Authenticator.java:749

◆ authenticationFailed()

boolean org.xdi.oxauth.auth.Authenticator.authenticationFailed ( )
inlineprivate
702  {
703  if (!this.addedErrorMessage) {
704  addMessage(FacesMessage.SEVERITY_ERROR, "login.errorMessage");
705  }
706  return false;
707  }
boolean addedErrorMessage
Definition: Authenticator.java:109
void addMessage(Severity severity, String summary)
Definition: Authenticator.java:749

◆ authenticationFailedSessionInvalid()

void org.xdi.oxauth.auth.Authenticator.authenticationFailedSessionInvalid ( )
inlineprivate
709  {
710  this.addedErrorMessage = true;
711  addMessage(FacesMessage.SEVERITY_ERROR, INVALID_SESSION_MESSAGE);
712  facesService.redirect("/error.xhtml");
713  }
boolean addedErrorMessage
Definition: Authenticator.java:109
FacesService facesService
Definition: Authenticator.java:94
static final String INVALID_SESSION_MESSAGE
Definition: Authenticator.java:59
void addMessage(Severity severity, String summary)
Definition: Authenticator.java:749

◆ authenticationSessionExpired()

void org.xdi.oxauth.auth.Authenticator.authenticationSessionExpired ( )
inlineprivate
715  {
716  this.addedErrorMessage = true;
717  facesService.redirect("/expiredSession.xhtml");
718  }
boolean addedErrorMessage
Definition: Authenticator.java:109
FacesService facesService
Definition: Authenticator.java:94

◆ clearExternalScriptExtraParameters()

void org.xdi.oxauth.auth.Authenticator.clearExternalScriptExtraParameters ( Map< String, String >  sessionIdAttributes)
inlineprivate
496  {
497  Map<String, String> authExternalAttributes = getExternalScriptExtraParameters(sessionIdAttributes);
498 
499  for (String authExternalAttribute : authExternalAttributes.keySet()) {
500  sessionIdAttributes.remove(authExternalAttribute);
501  }
502 
503  sessionIdAttributes.remove(AUTH_EXTERNAL_ATTRIBUTES);
504  }
static final String AUTH_EXTERNAL_ATTRIBUTES
Definition: Authenticator.java:61
Map< String, String > getExternalScriptExtraParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:472

◆ clientAuthentication()

boolean org.xdi.oxauth.auth.Authenticator.clientAuthentication ( Credentials  credentials,
boolean  interactive,
boolean  skipPassword 
)
inline
175  {
176  boolean isServiceUsesExternalAuthenticator = !interactive
177  && externalAuthenticationService.isEnabled(AuthenticationScriptUsageType.SERVICE);
178  if (isServiceUsesExternalAuthenticator) {
179  CustomScriptConfiguration customScriptConfiguration = externalAuthenticationService
180  .determineCustomScriptConfiguration(AuthenticationScriptUsageType.SERVICE, 1, this.authAcr);
181 
182  if (customScriptConfiguration == null) {
183  logger.error("Failed to get CustomScriptConfiguration. acr: '{}'", this.authAcr);
184  } else {
185  this.authAcr = customScriptConfiguration.getCustomScript().getName();
186 
187  boolean result = externalAuthenticationService.executeExternalAuthenticate(customScriptConfiguration,
188  null, 1);
189  logger.info("Authentication result for user '{}', result: '{}'", credentials.getUsername(), result);
190 
191  if (result) {
194  return true;
195  }
196  }
197  }
198 
199  boolean loggedIn = skipPassword;
200  if (!loggedIn) {
201  loggedIn = clientService.authenticate(credentials.getUsername(), credentials.getPassword());
202  }
203  if (loggedIn) {
206  return true;
207  }
208 
209  return false;
210  }
boolean executeExternalAuthenticate(CustomScriptConfiguration customScriptConfiguration, Map< String, String[]> requestParameters, int step)
Definition: ExternalAuthenticationService.java:169
Client configureSessionClient()
Definition: AuthenticationService.java:516
Logger logger
Definition: Authenticator.java:64
ExternalAuthenticationService externalAuthenticationService
Definition: Authenticator.java:82
String authAcr
Definition: Authenticator.java:105
boolean authenticate(String clientId, String password)
Definition: ClientService.java:107
ClientService clientService
Definition: Authenticator.java:73
AuthenticationService authenticationService
Definition: Authenticator.java:79
void showClientAuthenticationLog(Client client)
Definition: Authenticator.java:212
Credentials credentials
Definition: Authenticator.java:70
boolean isEnabled(AuthenticationScriptUsageType usageType)
Definition: ExternalAuthenticationService.java:280
CustomScriptConfiguration determineCustomScriptConfiguration(AuthenticationScriptUsageType usageType, int authStep, String acr)
Definition: ExternalAuthenticationService.java:301

◆ configureSessionClient()

void org.xdi.oxauth.auth.Authenticator.configureSessionClient ( Client  client)
inline
745  {
747  }
Client configureSessionClient()
Definition: AuthenticationService.java:516
AuthenticationService authenticationService
Definition: Authenticator.java:79

◆ getExternalScriptExtraParameters()

Map<String, String> org.xdi.oxauth.auth.Authenticator.getExternalScriptExtraParameters ( Map< String, String >  sessionIdAttributes)
inlineprivate
472  {
473  String authExternalAttributesString = sessionIdAttributes.get(AUTH_EXTERNAL_ATTRIBUTES);
474  Map<String, String> authExternalAttributes = new HashMap<String, String>();
475  try {
476  authExternalAttributes = Util.jsonObjectArrayStringAsMap(authExternalAttributesString);
477  } catch (JSONException ex) {
478  logger.error("Failed to convert JSON array of auth_external_attributes to Map<String, String>");
479  }
480 
481  return authExternalAttributes;
482  }
Logger logger
Definition: Authenticator.java:64
static final String AUTH_EXTERNAL_ATTRIBUTES
Definition: Authenticator.java:61

◆ getMaskMobilenumber()

String org.xdi.oxauth.auth.Authenticator.getMaskMobilenumber ( String  mobile_number)
inline
755  {
756  final String s = mobile_number.replaceAll("\\D", "");
757 
758  final int start = 0;
759  final int end = s.length() - 4;
760  final String overlay = StringUtils.repeat("*", end - start);
761 
762  return StringUtils.overlay(s, overlay, start, end);
763  }

◆ initCustomAuthenticatorVariables()

void org.xdi.oxauth.auth.Authenticator.initCustomAuthenticatorVariables ( Map< String, String >  sessionIdAttributes)
inlineprivate
692  {
693  if (sessionIdAttributes == null) {
694  logger.error("Failed to restore attributes from session attributes");
695  return;
696  }
697 
698  this.authStep = StringHelper.toInteger(sessionIdAttributes.get("auth_step"), null);
699  this.authAcr = sessionIdAttributes.get(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE);
700  }
Logger logger
Definition: Authenticator.java:64
String authAcr
Definition: Authenticator.java:105
Integer authStep
Definition: Authenticator.java:107

◆ isAuthStepPassed()

boolean org.xdi.oxauth.auth.Authenticator.isAuthStepPassed ( Map< String, String >  sessionIdAttributes,
Integer  authStep 
)
inlineprivate
725  {
726  String key = String.format("auth_step_passed_%d", authStep);
727  if (sessionIdAttributes.containsKey(key) && Boolean.parseBoolean(sessionIdAttributes.get(key))) {
728  return true;
729  }
730 
731  return false;
732  }
Integer authStep
Definition: Authenticator.java:107

◆ isPassedPreviousAuthSteps()

boolean org.xdi.oxauth.auth.Authenticator.isPassedPreviousAuthSteps ( Map< String, String >  sessionIdAttributes,
Integer  authStep 
)
inlineprivate
734  {
735  for (int i = 1; i < authStep; i++) {
736  boolean isAuthStepPassed = isAuthStepPassed(sessionIdAttributes, i);
737  if (!isAuthStepPassed) {
738  return false;
739  }
740  }
741 
742  return true;
743  }
boolean isAuthStepPassed(Map< String, String > sessionIdAttributes, Integer authStep)
Definition: Authenticator.java:725
Integer authStep
Definition: Authenticator.java:107

◆ markAuthStepAsPassed()

void org.xdi.oxauth.auth.Authenticator.markAuthStepAsPassed ( Map< String, String >  sessionIdAttributes,
Integer  authStep 
)
inlineprivate
720  {
721  String key = String.format("auth_step_passed_%d", authStep);
722  sessionIdAttributes.put(key, Boolean.TRUE.toString());
723  }
Integer authStep
Definition: Authenticator.java:107

◆ prepareAuthenticationForStep()

String org.xdi.oxauth.auth.Authenticator.prepareAuthenticationForStep ( )
inline
523  {
524  String result = prepareAuthenticationForStepImpl();
525 
526  if (Constants.RESULT_SUCCESS.equals(result)) {
527  } else if (Constants.RESULT_FAILURE.equals(result)) {
528  addMessage(FacesMessage.SEVERITY_ERROR, "login.failedToAuthenticate");
529  } else if (Constants.RESULT_NO_PERMISSIONS.equals(result)) {
530  addMessage(FacesMessage.SEVERITY_ERROR, "login.youDontHavePermission");
531  } else if (Constants.RESULT_EXPIRED.equals(result)) {
532  addMessage(FacesMessage.SEVERITY_ERROR, INVALID_SESSION_MESSAGE);
533  }
534 
535  return result;
536  }
static final String INVALID_SESSION_MESSAGE
Definition: Authenticator.java:59
String prepareAuthenticationForStepImpl()
Definition: Authenticator.java:538
void addMessage(Severity severity, String summary)
Definition: Authenticator.java:749

◆ prepareAuthenticationForStepImpl()

String org.xdi.oxauth.auth.Authenticator.prepareAuthenticationForStepImpl ( )
inlineprivate
538  {
539  SessionId sessionId = sessionIdService.getSessionId();
540  Map<String, String> sessionIdAttributes = sessionIdService.getSessionAttributes(sessionId);
541  if (sessionIdAttributes == null) {
542  logger.error("Failed to get attributes from session");
543  return Constants.RESULT_EXPIRED;
544  }
545 
546  // Set current state into identity to allow use in login form and
547  // authentication scripts
548  identity.setSessionId(sessionId);
549 
550  if (!externalAuthenticationService.isEnabled(AuthenticationScriptUsageType.INTERACTIVE)) {
551  return Constants.RESULT_SUCCESS;
552  }
553 
554  initCustomAuthenticatorVariables(sessionIdAttributes);
555  if (StringHelper.isEmpty(this.authAcr)) {
556  return Constants.RESULT_SUCCESS;
557  }
558 
559  if ((this.authStep == null) || (this.authStep < 1)) {
560  return Constants.RESULT_NO_PERMISSIONS;
561  }
562 
563  CustomScriptConfiguration customScriptConfiguration = externalAuthenticationService
564  .getCustomScriptConfiguration(AuthenticationScriptUsageType.INTERACTIVE, this.authAcr);
565  if (customScriptConfiguration == null) {
566  logger.error("Failed to get CustomScriptConfiguration. auth_step: '{}', acr: '{}'", this.authStep,
567  this.authAcr);
568  return Constants.RESULT_FAILURE;
569  }
570 
571  String currentauthAcr = customScriptConfiguration.getName();
572 
574  AuthenticationScriptUsageType.INTERACTIVE, customScriptConfiguration);
575  if (customScriptConfiguration == null) {
576  return Constants.RESULT_FAILURE;
577  } else {
578  String determinedauthAcr = customScriptConfiguration.getName();
579  if (!StringHelper.equalsIgnoreCase(currentauthAcr, determinedauthAcr)) {
580  // Redirect user to alternative login workflow
581  String redirectTo = externalAuthenticationService
582  .executeExternalGetPageForStep(customScriptConfiguration, this.authStep);
583 
584  if (StringHelper.isEmpty(redirectTo)) {
585  redirectTo = "/login.xhtml";
586  }
587 
588  CustomScriptConfiguration determinedCustomScriptConfiguration = externalAuthenticationService
589  .getCustomScriptConfiguration(AuthenticationScriptUsageType.INTERACTIVE, determinedauthAcr);
590  if (determinedCustomScriptConfiguration == null) {
591  logger.error("Failed to get determined CustomScriptConfiguration. auth_step: '{}', acr: '{}'",
592  this.authStep, this.authAcr);
593  return Constants.RESULT_FAILURE;
594  }
595 
596  logger.debug("Redirect to page: '{}'. Force to use acr: '{}'", redirectTo, determinedauthAcr);
597 
598  determinedauthAcr = determinedCustomScriptConfiguration.getName();
599  String determinedAuthLevel = Integer.toString(determinedCustomScriptConfiguration.getLevel());
600 
601  sessionIdAttributes.put("acr", determinedauthAcr);
602  sessionIdAttributes.put("auth_level", determinedAuthLevel);
603  sessionIdAttributes.put("auth_step", Integer.toString(1));
604 
605  // Remove old session parameters from session
606  clearExternalScriptExtraParameters(sessionIdAttributes);
607 
608  if (sessionId != null) {
609  boolean updateResult = updateSession(sessionId, sessionIdAttributes);
610  if (!updateResult) {
611  return Constants.RESULT_EXPIRED;
612  }
613  }
614 
615  facesService.redirectWithExternal(redirectTo, null);
616 
617  return Constants.RESULT_SUCCESS;
618  }
619  }
620 
621  // Check if all previous steps had passed
622  boolean passedPreviousSteps = isPassedPreviousAuthSteps(sessionIdAttributes, this.authStep);
623  if (!passedPreviousSteps) {
624  logger.error("There are authentication steps not marked as passed. acr: '{}', auth_step: '{}'", this.authAcr,
625  this.authStep);
626  return Constants.RESULT_FAILURE;
627  }
628 
629  // Restore identity working parameters from session
630  setIdentityWorkingParameters(sessionIdAttributes);
631 
632  Boolean result = externalAuthenticationService.executeExternalPrepareForStep(customScriptConfiguration,
633  externalContext.getRequestParameterValuesMap(), this.authStep);
634  if ((result != null) && result) {
635  // Store/Update extra parameters in session attributes map
636  updateExtraParameters(customScriptConfiguration, this.authStep, sessionIdAttributes);
637 
638  if (sessionId != null) {
639  boolean updateResult = updateSession(sessionId, sessionIdAttributes);
640  if (!updateResult) {
641  return Constants.RESULT_FAILURE;
642  }
643  }
644 
645  return Constants.RESULT_SUCCESS;
646  } else {
647  return Constants.RESULT_FAILURE;
648  }
649  }
CustomScriptConfiguration getCustomScriptConfiguration(AuthenticationScriptUsageType usageType, String name)
Definition: ExternalAuthenticationService.java:390
SessionId getSessionId()
Definition: SessionIdService.java:360
CustomScriptConfiguration determineExternalAuthenticatorForWorkflow(AuthenticationScriptUsageType usageType, CustomScriptConfiguration customScriptConfiguration)
Definition: ExternalAuthenticationService.java:360
FacesService facesService
Definition: Authenticator.java:94
Map< String, String > getSessionAttributes(SessionId sessionId)
Definition: SessionIdService.java:370
void setIdentityWorkingParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:506
Logger logger
Definition: Authenticator.java:64
Identity identity
Definition: Authenticator.java:67
void clearExternalScriptExtraParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:496
ExternalAuthenticationService externalAuthenticationService
Definition: Authenticator.java:82
String authAcr
Definition: Authenticator.java:105
Integer authStep
Definition: Authenticator.java:107
void initCustomAuthenticatorVariables(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:692
SessionIdService sessionIdService
Definition: Authenticator.java:76
ExternalContext externalContext
Definition: Authenticator.java:91
boolean updateSession(SessionId sessionId, Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:392
String executeExternalGetPageForStep(CustomScriptConfiguration customScriptConfiguration, int step)
Definition: ExternalAuthenticationService.java:253
boolean isPassedPreviousAuthSteps(Map< String, String > sessionIdAttributes, Integer authStep)
Definition: Authenticator.java:734
boolean isEnabled(AuthenticationScriptUsageType usageType)
Definition: ExternalAuthenticationService.java:280
void updateExtraParameters(CustomScriptConfiguration customScriptConfiguration, final int step, Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:444
void setSessionId(SessionId sessionId)
Definition: Identity.java:34
boolean executeExternalPrepareForStep(CustomScriptConfiguration customScriptConfiguration, Map< String, String[]> requestParameters, int step)
Definition: ExternalAuthenticationService.java:225

◆ setExternalScriptExtraParameters()

void org.xdi.oxauth.auth.Authenticator.setExternalScriptExtraParameters ( Map< String, String >  sessionIdAttributes,
Map< String, String >  authExternalAttributes 
)
inlineprivate
485  {
486  String authExternalAttributesString = null;
487  try {
488  authExternalAttributesString = Util.mapAsString(authExternalAttributes);
489  } catch (JSONException ex) {
490  logger.error("Failed to convert Map<String, String> of auth_external_attributes to JSON array");
491  }
492 
493  sessionIdAttributes.put(AUTH_EXTERNAL_ATTRIBUTES, authExternalAttributesString);
494  }
Logger logger
Definition: Authenticator.java:64
static final String AUTH_EXTERNAL_ATTRIBUTES
Definition: Authenticator.java:61

◆ setIdentityWorkingParameters()

void org.xdi.oxauth.auth.Authenticator.setIdentityWorkingParameters ( Map< String, String >  sessionIdAttributes)
inlineprivate
506  {
507  Map<String, String> authExternalAttributes = getExternalScriptExtraParameters(sessionIdAttributes);
508 
509  HashMap<String, Object> workingParameters = identity.getWorkingParameters();
510  for (Entry<String, String> authExternalAttributeEntry : authExternalAttributes.entrySet()) {
511  String authExternalAttributeName = authExternalAttributeEntry.getKey();
512  String authExternalAttributeType = authExternalAttributeEntry.getValue();
513 
514  if (sessionIdAttributes.containsKey(authExternalAttributeName)) {
515  String authExternalAttributeValue = sessionIdAttributes.get(authExternalAttributeName);
516  Object typedValue = requestParameterService.getTypedValue(authExternalAttributeValue, authExternalAttributeType);
517 
518  workingParameters.put(authExternalAttributeName, typedValue);
519  }
520  }
521  }
Object getTypedValue(String stringValue, String type)
Definition: RequestParameterService.java:198
Identity identity
Definition: Authenticator.java:67
RequestParameterService requestParameterService
Definition: Authenticator.java:103
Map< String, String > getExternalScriptExtraParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:472

◆ showClientAuthenticationLog()

void org.xdi.oxauth.auth.Authenticator.showClientAuthenticationLog ( Client  client)
inlineprivate
212  {
213  StringBuilder sb = new StringBuilder("Authentication success for Client");
214  if (StringHelper.toBoolean(appConfiguration.getLogClientIdOnClientAuthentication(), false)
215  || StringHelper.toBoolean(appConfiguration.getLogClientNameOnClientAuthentication(), false)) {
216  sb.append(":");
218  sb.append(" ").append("'").append(client.getClientId()).append("'");
219  }
221  sb.append(" ").append("('").append(client.getClientName()).append("')");
222  }
223  }
224  logger.info(sb.toString());
225  }
Logger logger
Definition: Authenticator.java:64
AppConfiguration appConfiguration
Definition: Authenticator.java:85
Boolean getLogClientNameOnClientAuthentication()
Definition: AppConfiguration.java:1361
Boolean getLogClientIdOnClientAuthentication()
Definition: AppConfiguration.java:1353

◆ updateExtraParameters()

void org.xdi.oxauth.auth.Authenticator.updateExtraParameters ( CustomScriptConfiguration  customScriptConfiguration,
final int  step,
Map< String, String >  sessionIdAttributes 
)
inlineprivate
445  {
446  List<String> extraParameters = externalAuthenticationService
447  .executeExternalGetExtraParametersForStep(customScriptConfiguration, step);
448 
449  // Load extra parameters set
450  Map<String, String> authExternalAttributes = getExternalScriptExtraParameters(sessionIdAttributes);
451 
452  if (extraParameters != null) {
453  for (String extraParameter : extraParameters) {
454  if (authenticationService.isParameterExists(extraParameter)) {
455  Pair<String, String> extraParameterValueWithType = requestParameterService.getParameterValueWithType(extraParameter);
456  String extraParameterValue = extraParameterValueWithType.getFirst();
457  String extraParameterType = extraParameterValueWithType.getSecond();
458 
459  // Store parameter name and value
460  sessionIdAttributes.put(extraParameter, extraParameterValue);
461 
462  // Store parameter name and type
463  authExternalAttributes.put(extraParameter, extraParameterType);
464  }
465  }
466  }
467 
468  // Store identity working parameters in session
469  setExternalScriptExtraParameters(sessionIdAttributes, authExternalAttributes);
470  }
boolean isParameterExists(String p_name)
Definition: AuthenticationService.java:590
List< String > executeExternalGetExtraParametersForStep(CustomScriptConfiguration customScriptConfiguration, int step)
Definition: ExternalAuthenticationService.java:239
Pair< String, String > getParameterValueWithType(String p_name)
Definition: RequestParameterService.java:177
void setExternalScriptExtraParameters(Map< String, String > sessionIdAttributes, Map< String, String > authExternalAttributes)
Definition: Authenticator.java:484
ExternalAuthenticationService externalAuthenticationService
Definition: Authenticator.java:82
RequestParameterService requestParameterService
Definition: Authenticator.java:103
AuthenticationService authenticationService
Definition: Authenticator.java:79
Map< String, String > getExternalScriptExtraParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:472

◆ updateSession()

boolean org.xdi.oxauth.auth.Authenticator.updateSession ( SessionId  sessionId,
Map< String, String >  sessionIdAttributes 
)
inlineprivate
392  {
393  sessionId.setSessionAttributes(sessionIdAttributes);
394  boolean updateResult = sessionIdService.updateSessionId(sessionId, true, true, true);
395  if (!updateResult) {
396  logger.debug("Failed to update session entry: '{}'", sessionId.getId());
397  return false;
398  }
399 
400  return true;
401  }
Logger logger
Definition: Authenticator.java:64
SessionIdService sessionIdService
Definition: Authenticator.java:76
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534

◆ userAuthenticationInteractive()

boolean org.xdi.oxauth.auth.Authenticator.userAuthenticationInteractive ( )
inlineprivate
227  {
228  SessionId sessionId = sessionIdService.getSessionId();
229  Map<String, String> sessionIdAttributes = sessionIdService.getSessionAttributes(sessionId);
230  if (sessionIdAttributes == null) {
231  logger.error("Failed to get session attributes");
233  return false;
234  }
235 
236  // Set current state into identity to allow use in login form and
237  // authentication scripts
238  identity.setSessionId(sessionId);
239 
240  initCustomAuthenticatorVariables(sessionIdAttributes);
241  boolean useExternalAuthenticator = externalAuthenticationService
242  .isEnabled(AuthenticationScriptUsageType.INTERACTIVE);
243  if (useExternalAuthenticator && !StringHelper.isEmpty(this.authAcr)) {
244  initCustomAuthenticatorVariables(sessionIdAttributes);
245  if ((this.authStep == null) || StringHelper.isEmpty(this.authAcr)) {
246  logger.error("Failed to determine authentication mode");
248  return false;
249  }
250 
251  CustomScriptConfiguration customScriptConfiguration = externalAuthenticationService
252  .getCustomScriptConfiguration(AuthenticationScriptUsageType.INTERACTIVE, this.authAcr);
253  if (customScriptConfiguration == null) {
254  logger.error("Failed to get CustomScriptConfiguration for acr: '{}', auth_step: '{}'", this.authAcr,
255  this.authStep);
256  return false;
257  }
258 
259  // Check if all previous steps had passed
260  boolean passedPreviousSteps = isPassedPreviousAuthSteps(sessionIdAttributes, this.authStep);
261  if (!passedPreviousSteps) {
262  logger.error("There are authentication steps not marked as passed. acr: '{}', auth_step: '{}'",
263  this.authAcr, this.authStep);
264  return false;
265  }
266 
267  // Restore identity working parameters from session
268  setIdentityWorkingParameters(sessionIdAttributes);
269 
270  boolean result = externalAuthenticationService.executeExternalAuthenticate(customScriptConfiguration,
271  externalContext.getRequestParameterValuesMap(), this.authStep);
272  logger.debug("Authentication result for user '{}'. auth_step: '{}', result: '{}', credentials: '{}'",
273  credentials.getUsername(), this.authStep, result, System.identityHashCode(credentials));
274 
275  int overridenNextStep = -1;
276 
277  int apiVersion = externalAuthenticationService.executeExternalGetApiVersion(customScriptConfiguration);
278  if (apiVersion > 1) {
279  logger.trace("According to API version script supports steps overriding");
280  overridenNextStep = externalAuthenticationService.getNextStep(customScriptConfiguration,
281  externalContext.getRequestParameterValuesMap(), this.authStep);
282  logger.debug("Get next step from script: '{}'", overridenNextStep);
283  }
284 
285  if (!result && (overridenNextStep == -1)) {
286  // Force session lastUsedAt update if authentication attempt is failed
288  return false;
289  }
290 
291  boolean overrideCurrentStep = false;
292  if (overridenNextStep > -1) {
293  overrideCurrentStep = true;
294  // Reload session id
295  sessionId = sessionIdService.getSessionId();
296 
297  // Reset to specified step
298  sessionIdService.resetToStep(sessionId, overridenNextStep);
299 
300  this.authStep = overridenNextStep;
301  logger.info("Authentication reset to step : '{}'", this.authStep);
302  }
303 
304  // Update parameters map to allow access it from count
305  // authentication steps method
306  updateExtraParameters(customScriptConfiguration, this.authStep + 1, sessionIdAttributes);
307 
308  // Determine count authentication methods
309  int countAuthenticationSteps = externalAuthenticationService
310  .executeExternalGetCountAuthenticationSteps(customScriptConfiguration);
311 
312  // Reload from LDAP to make sure that we are updating latest session
313  // attributes
314  sessionId = sessionIdService.getSessionId();
315  sessionIdAttributes = sessionIdService.getSessionAttributes(sessionId);
316 
317  // Prepare for next step
318  if ((this.authStep < countAuthenticationSteps) || overrideCurrentStep) {
319  int nextStep;
320  if (overrideCurrentStep) {
321  nextStep = overridenNextStep;
322  } else {
323  nextStep = this.authStep + 1;
324  }
325 
326  String redirectTo = externalAuthenticationService
327  .executeExternalGetPageForStep(customScriptConfiguration, nextStep);
328  if (StringHelper.isEmpty(redirectTo) || redirectTo == null) {
329  redirectTo = "/error.xhtml";
330  }
331 
332  // Store/Update extra parameters in session attributes map
333  updateExtraParameters(customScriptConfiguration, nextStep, sessionIdAttributes);
334 
335  if (!overrideCurrentStep) {
336  // Update auth_step
337  sessionIdAttributes.put("auth_step", Integer.toString(nextStep));
338 
339  // Mark step as passed
340  markAuthStepAsPassed(sessionIdAttributes, this.authStep);
341  }
342 
343  if (sessionId != null) {
344  boolean updateResult = updateSession(sessionId, sessionIdAttributes);
345  if (!updateResult) {
346  return false;
347  }
348  }
349 
350  logger.trace("Redirect to page: '{}'", redirectTo);
351  facesService.redirectWithExternal(redirectTo, null);
352 
353  return true;
354  }
355 
356  if (this.authStep == countAuthenticationSteps) {
357  SessionId eventSessionId = authenticationService.configureSessionUser(sessionId, sessionIdAttributes);
358 
360 
361  // Redirect to authorization workflow
362  logger.debug("Sending event to trigger user redirection: '{}'", credentials.getUsername());
364 
365  logger.info("Authentication success for User: '{}'", credentials.getUsername());
366  return true;
367  }
368  } else {
369  if (StringHelper.isNotEmpty(credentials.getUsername())) {
370  boolean authenticated = authenticationService.authenticate(credentials.getUsername(),
371  credentials.getPassword());
372  if (authenticated) {
373  SessionId eventSessionId = authenticationService.configureSessionUser(sessionId,
374  sessionIdAttributes);
375 
376  // Redirect to authorization workflow
377  logger.debug("Sending event to trigger user redirection: '{}'", credentials.getUsername());
379  } else {
380  // Force session lastUsedAt update if authentication attempt is failed
382  }
383 
384  logger.info("Authentication success for User: '{}'", credentials.getUsername());
385  return true;
386  }
387  }
388 
389  return false;
390  }
CustomScriptConfiguration getCustomScriptConfiguration(AuthenticationScriptUsageType usageType, String name)
Definition: ExternalAuthenticationService.java:390
SessionId getSessionId()
Definition: SessionIdService.java:360
boolean executeExternalAuthenticate(CustomScriptConfiguration customScriptConfiguration, Map< String, String[]> requestParameters, int step)
Definition: ExternalAuthenticationService.java:169
int executeExternalGetApiVersion(CustomScriptConfiguration customScriptConfiguration)
Definition: ExternalAuthenticationService.java:267
FacesService facesService
Definition: Authenticator.java:94
Map< String, String > getSessionAttributes(SessionId sessionId)
Definition: SessionIdService.java:370
void setIdentityWorkingParameters(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:506
Logger logger
Definition: Authenticator.java:64
Identity identity
Definition: Authenticator.java:67
ExternalAuthenticationService externalAuthenticationService
Definition: Authenticator.java:82
String authAcr
Definition: Authenticator.java:105
void authenticationSessionExpired()
Definition: Authenticator.java:715
Integer authStep
Definition: Authenticator.java:107
void authenticationFailedSessionInvalid()
Definition: Authenticator.java:709
SessionId configureSessionUser(SessionId sessionId, Map< String, String > sessionIdAttributes)
Definition: AuthenticationService.java:428
int getNextStep(CustomScriptConfiguration customScriptConfiguration, Map< String, String[]> requestParameters, int step)
Definition: ExternalAuthenticationService.java:183
AuthenticationService authenticationService
Definition: Authenticator.java:79
void initCustomAuthenticatorVariables(Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:692
SessionIdService sessionIdService
Definition: Authenticator.java:76
void onSuccessfulLogin(SessionId sessionUser)
Definition: AuthenticationService.java:535
void markAuthStepAsPassed(Map< String, String > sessionIdAttributes, Integer authStep)
Definition: Authenticator.java:720
boolean updateSessionId(final SessionId sessionId)
Definition: SessionIdService.java:534
ExternalContext externalContext
Definition: Authenticator.java:91
boolean authenticate(String userName, String password)
Definition: AuthenticationService.java:124
Credentials credentials
Definition: Authenticator.java:70
void quietLogin(String userName)
Definition: AuthenticationService.java:477
void resetToStep(SessionId session, int resetToStep)
Definition: SessionIdService.java:195
boolean updateSession(SessionId sessionId, Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:392
String executeExternalGetPageForStep(CustomScriptConfiguration customScriptConfiguration, int step)
Definition: ExternalAuthenticationService.java:253
boolean isPassedPreviousAuthSteps(Map< String, String > sessionIdAttributes, Integer authStep)
Definition: Authenticator.java:734
int executeExternalGetCountAuthenticationSteps(CustomScriptConfiguration customScriptConfiguration)
Definition: ExternalAuthenticationService.java:155
boolean isEnabled(AuthenticationScriptUsageType usageType)
Definition: ExternalAuthenticationService.java:280
void updateExtraParameters(CustomScriptConfiguration customScriptConfiguration, final int step, Map< String, String > sessionIdAttributes)
Definition: Authenticator.java:444
void setSessionId(SessionId sessionId)
Definition: Identity.java:34

◆ userAuthenticationService()

boolean org.xdi.oxauth.auth.Authenticator.userAuthenticationService ( )
inlineprivate
403  {
404  if (externalAuthenticationService.isEnabled(AuthenticationScriptUsageType.SERVICE)) {
405  CustomScriptConfiguration customScriptConfiguration = externalAuthenticationService
406  .determineCustomScriptConfiguration(AuthenticationScriptUsageType.SERVICE, 1, this.authAcr);
407 
408  if (customScriptConfiguration == null) {
409  logger.error("Failed to get CustomScriptConfiguration. auth_step: '{}', acr: '{}'", this.authStep,
410  this.authAcr);
411  } else {
412  this.authAcr = customScriptConfiguration.getName();
413 
414  boolean result = externalAuthenticationService.executeExternalAuthenticate(customScriptConfiguration,
415  null, 1);
416  logger.info("Authentication result for '{}'. auth_step: '{}', result: '{}'", credentials.getUsername(),
417  this.authStep, result);
418 
419  if (result) {
421 
422  logger.info("Authentication success for User: '{}'", credentials.getUsername());
423  return true;
424  }
425  logger.info("Authentication failed for User: '{}'", credentials.getUsername());
426  }
427  }
428 
429  if (StringHelper.isNotEmpty(credentials.getUsername())) {
430  boolean authenticated = authenticationService.authenticate(credentials.getUsername(),
431  credentials.getPassword());
432  if (authenticated) {
434 
435  logger.info("Authentication success for User: '{}'", credentials.getUsername());
436  return true;
437  }
438  logger.info("Authentication failed for User: '{}'", credentials.getUsername());
439  }
440 
441  return false;
442  }
SessionId configureEventUser()
Definition: AuthenticationService.java:449
boolean executeExternalAuthenticate(CustomScriptConfiguration customScriptConfiguration, Map< String, String[]> requestParameters, int step)
Definition: ExternalAuthenticationService.java:169
Logger logger
Definition: Authenticator.java:64
ExternalAuthenticationService externalAuthenticationService
Definition: Authenticator.java:82
String authAcr
Definition: Authenticator.java:105
Integer authStep
Definition: Authenticator.java:107
AuthenticationService authenticationService
Definition: Authenticator.java:79
boolean authenticate(String userName, String password)
Definition: AuthenticationService.java:124
Credentials credentials
Definition: Authenticator.java:70
boolean isEnabled(AuthenticationScriptUsageType usageType)
Definition: ExternalAuthenticationService.java:280
CustomScriptConfiguration determineCustomScriptConfiguration(AuthenticationScriptUsageType usageType, int authStep, String acr)
Definition: ExternalAuthenticationService.java:301

メンバ詳解

◆ addedErrorMessage

boolean org.xdi.oxauth.auth.Authenticator.addedErrorMessage
private

◆ appConfiguration

AppConfiguration org.xdi.oxauth.auth.Authenticator.appConfiguration
private

◆ AUTH_EXTERNAL_ATTRIBUTES

final String org.xdi.oxauth.auth.Authenticator.AUTH_EXTERNAL_ATTRIBUTES = "auth_external_attributes"
staticprivate

◆ authAcr

String org.xdi.oxauth.auth.Authenticator.authAcr
private

◆ authenticationService

AuthenticationService org.xdi.oxauth.auth.Authenticator.authenticationService
private

◆ authStep

Integer org.xdi.oxauth.auth.Authenticator.authStep
private

◆ clientService

ClientService org.xdi.oxauth.auth.Authenticator.clientService
private

◆ credentials

Credentials org.xdi.oxauth.auth.Authenticator.credentials
private

◆ externalAuthenticationService

ExternalAuthenticationService org.xdi.oxauth.auth.Authenticator.externalAuthenticationService
private

◆ externalContext

ExternalContext org.xdi.oxauth.auth.Authenticator.externalContext
private

◆ facesContext

FacesContext org.xdi.oxauth.auth.Authenticator.facesContext
private

◆ facesMessages

FacesMessages org.xdi.oxauth.auth.Authenticator.facesMessages
private

◆ facesService

FacesService org.xdi.oxauth.auth.Authenticator.facesService
private

◆ identity

Identity org.xdi.oxauth.auth.Authenticator.identity
private

◆ INVALID_SESSION_MESSAGE

final String org.xdi.oxauth.auth.Authenticator.INVALID_SESSION_MESSAGE = "login.errorSessionInvalidMessage"
staticprivate

◆ languageBean

LanguageBean org.xdi.oxauth.auth.Authenticator.languageBean
private

◆ logger

Logger org.xdi.oxauth.auth.Authenticator.logger
private

◆ requestParameterService

RequestParameterService org.xdi.oxauth.auth.Authenticator.requestParameterService
private

◆ sessionIdService

SessionIdService org.xdi.oxauth.auth.Authenticator.sessionIdService
private

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