Skip to content

Commit d0f5d44

Browse files
Hanlde ASK password OTP failures and redirect to password reset page
1 parent 3b07ecc commit d0f5d44

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

components/org.wso2.carbon.identity.application.authenticator.basicauth/src/main/java/org/wso2/carbon/identity/application/authenticator/basicauth/BasicAuthenticator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.ACCOUNT_IS_LOCKED;
9595
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.ACCOUNT_LOCKED_REASON;
9696
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.ACCOUNT_PENDING_APPROVAL;
97+
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.ASK_PASSWORD_VIA_OTP;
9798
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.AUTHENTICATOR_BASIC;
9899
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.AUTHENTICATOR_MESSAGE;
99100
import static org.wso2.carbon.identity.application.authenticator.basicauth.BasicAuthenticatorConstants.DISPLAY_PASSWORD;
@@ -448,6 +449,33 @@ protected void initiateAuthenticationRequest(HttpServletRequest request,
448449
URLEncoder.encode(reason, BasicAuthenticatorConstants.UTF_8);
449450
setAuthenticatorErrorMessage(getErrorMessage(errorCode, FORCED_PASSWORD_RESET_VIA_OTP),
450451
context);
452+
} else if (errorCode.equals(IdentityCoreConstants.ASK_PASSWORD_SET_PASSWORD_VIA_OTP_ERROR_CODE)) {
453+
String username = request.getParameter(USER_NAME);
454+
String tenantDomain = getTenantDomainFromUserName(context, username);
455+
456+
// Setting callback so that the user is prompted to login after setting password.
457+
String callback;
458+
try {
459+
callback = ServiceURLBuilder.create().addPath(loginPage).build().getAbsolutePublicURL();
460+
} catch (URLBuilderException e) {
461+
throw new IdentityRuntimeException(
462+
"Error while building callback url for context: " + loginPage, e);
463+
}
464+
callback = callback + ("?" + queryParams)
465+
+ BasicAuthenticatorConstants.AUTHENTICATORS + getName() + ":" +
466+
BasicAuthenticatorConstants.LOCAL;
467+
String reason = RecoveryScenarios.ASK_PASSWORD_VIA_EMAIL_OTP.name();
468+
469+
redirectURL = recoveryPage + CONFIRM_RECOVERY_DO +
470+
BasicAuthenticatorConstants.USER_NAME_PARAM + URLEncoder.encode(username,
471+
BasicAuthenticatorConstants.UTF_8) + BasicAuthenticatorConstants.TENANT_DOMAIN_PARAM +
472+
URLEncoder.encode(tenantDomain, BasicAuthenticatorConstants.UTF_8) +
473+
BasicAuthenticatorConstants.CONFIRMATION_PARAM + URLEncoder.encode(password,
474+
BasicAuthenticatorConstants.UTF_8) + BasicAuthenticatorConstants.CALLBACK_PARAM +
475+
URLEncoder.encode(callback, BasicAuthenticatorConstants.UTF_8) +
476+
BasicAuthenticatorConstants.REASON_PARAM +
477+
URLEncoder.encode(reason, BasicAuthenticatorConstants.UTF_8);
478+
setAuthenticatorErrorMessage(getErrorMessage(errorCode, ASK_PASSWORD_VIA_OTP), context);
451479
} else if (errorCode.equals(
452480
IdentityCoreConstants.USER_ACCOUNT_PENDING_APPROVAL_ERROR_CODE)) {
453481
retryParam = BasicAuthenticatorConstants.AUTH_FAILURE_PARAM + "true" +

components/org.wso2.carbon.identity.application.authenticator.basicauth/src/main/java/org/wso2/carbon/identity/application/authenticator/basicauth/BasicAuthenticatorConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public abstract class BasicAuthenticatorConstants {
8181
" password via OTP.";
8282
public static final String FORCED_PASSWORD_RESET_VIA_EMAIL = "The admin has forced user to " +
8383
"reset password via Email.";
84+
public static final String ASK_PASSWORD_VIA_OTP = "User is requested to set the password via OTP.";
8485

8586
/**
8687
* Constants related to log management.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,11 @@
380380
<carbon.base.imp.pkg.version.range>[1.0.0, 2.0.0)</carbon.base.imp.pkg.version.range>
381381

382382
<!-- Carbon Identity Framework version -->
383-
<carbon.identity.framework.version>7.8.331</carbon.identity.framework.version>
383+
<carbon.identity.framework.version>7.8.334-SNAPSHOT</carbon.identity.framework.version>
384384
<carbon.identity.framework.imp.pkg.version.range>[5.19.14, 8.0.0)
385385
</carbon.identity.framework.imp.pkg.version.range>
386386

387-
<identity.governance.version>1.8.23</identity.governance.version>
387+
<identity.governance.version>1.11.107-SNAPSHOT</identity.governance.version>
388388
<identity.governance.imp.pkg.version.range>[1.5.89, 3.0.0)</identity.governance.imp.pkg.version.range>
389389

390390
<osgi.framework.imp.pkg.version.range>[1.7.0, 2.0.0)</osgi.framework.imp.pkg.version.range>

0 commit comments

Comments
 (0)