use of org.wso2.carbon.identity.recovery.handler.AdminForcedPasswordResetHandler in project identity-governance by wso2-extensions.
the class IdentityRecoveryServiceComponent method activate.
@Activate
protected void activate(ComponentContext context) {
try {
BundleContext bundleContext = context.getBundleContext();
bundleContext.registerService(NotificationPasswordRecoveryManager.class.getName(), NotificationPasswordRecoveryManager.getInstance(), null);
bundleContext.registerService(SecurityQuestionPasswordRecoveryManager.class.getName(), SecurityQuestionPasswordRecoveryManager.getInstance(), null);
bundleContext.registerService(NotificationUsernameRecoveryManager.class.getName(), NotificationUsernameRecoveryManager.getInstance(), null);
bundleContext.registerService(UserSelfRegistrationManager.class.getName(), UserSelfRegistrationManager.getInstance(), null);
bundleContext.registerService(ChallengeQuestionManager.class.getName(), ChallengeQuestionManager.getInstance(), null);
bundleContext.registerService(ResendConfirmationManager.class.getName(), ResendConfirmationManager.getInstance(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new AccountConfirmationValidationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new UserSelfRegistrationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new LiteUserRegistrationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new UserEmailVerificationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new MobileNumberVerificationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new AdminForcedPasswordResetHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new TenantRegistrationVerificationHandler(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new IdentityUserMetadataMgtHandler(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new RecoveryConfigImpl(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new SelfRegistrationConfigImpl(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new LiteRegistrationConfigImpl(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new UserEmailVerificationConfigImpl(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new UserClaimUpdateConfigImpl(), null);
bundleContext.registerService(IdentityConnectorConfig.class.getName(), new AdminForcedPasswordResetConfigImpl(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new CodeInvalidationHandler(), null);
UsernameRecoveryManager usernameRecoveryManager = new UsernameRecoveryManagerImpl();
bundleContext.registerService(UsernameRecoveryManager.class.getName(), usernameRecoveryManager, null);
PasswordRecoveryManager passwordRecoveryManager = new PasswordRecoveryManagerImpl();
bundleContext.registerService(PasswordRecoveryManager.class.getName(), passwordRecoveryManager, null);
// Registering missing challenge question handler as a post authn handler
PostAuthenticationHandler postAuthnMissingChallengeQuestions = PostAuthnMissingChallengeQuestionsHandler.getInstance();
bundleContext.registerService(PostAuthenticationHandler.class.getName(), postAuthnMissingChallengeQuestions, null);
bundleContext.registerService(AbstractEventHandler.class.getName(), new ChallengeAnswerValidationHandler(), null);
} catch (Exception e) {
log.error("Error while activating identity governance component.", e);
}
// register the tenant management listener
TenantMgtListener tenantMgtListener = new TenantManagementListener();
context.getBundleContext().registerService(TenantMgtListener.class.getName(), tenantMgtListener, null);
// register default challenge questions
try {
if (log.isDebugEnabled()) {
log.debug("Loading default challenge questions for super tenant.");
}
loadDefaultChallengeQuestions();
// new ChallengeQuestionManager().getAllChallengeQuestions("carbon.super", "lk_LK");
} catch (IdentityRecoveryException e) {
log.error("Error persisting challenge question for super tenant.", e);
}
}
use of org.wso2.carbon.identity.recovery.handler.AdminForcedPasswordResetHandler in project identity-governance by wso2-extensions.
the class AdminForcedPasswordResetHandler method handleUpdateCredentialsByAdmin.
private void handleUpdateCredentialsByAdmin(Map<String, Object> eventProperties, UserStoreManager userStoreManager) throws IdentityEventException {
User user = getUser(eventProperties, userStoreManager);
if (log.isDebugEnabled()) {
log.debug("PostUpdateCredentialsByAdmin - AdminForcedPasswordResetHandler for user : " + user.toString());
}
UserRecoveryData userRecoveryData = getRecoveryData(user);
if (userRecoveryData != null) {
invalidateRecoveryData(user);
if (log.isDebugEnabled()) {
log.debug("PostUpdateCredentialsByAdmin - invalidate Recovery Data for user : " + user.toString());
}
}
}
use of org.wso2.carbon.identity.recovery.handler.AdminForcedPasswordResetHandler in project identity-governance by wso2-extensions.
the class AdminForcedPasswordResetHandler method handleClaimUpdate.
protected void handleClaimUpdate(Map<String, Object> eventProperties, UserStoreManager userStoreManager) throws IdentityEventException {
User user = getUser(eventProperties, userStoreManager);
if (log.isDebugEnabled()) {
log.debug("PreAuthenticate - AdminForcedPasswordResetHandler for : " + user.toString());
}
Map<String, String> claims = (Map<String, String>) eventProperties.get(IdentityEventConstants.EventProperty.USER_CLAIMS);
boolean adminPasswordResetOffline = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_ADMIN_PASSWORD_RESET_OFFLINE, user.getTenantDomain()));
boolean adminPasswordResetOTP = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_ADMIN_PASSWORD_RESET_WITH_OTP, user.getTenantDomain()));
boolean adminPasswordResetRecoveryLink = Boolean.parseBoolean(Utils.getConnectorConfig(IdentityRecoveryConstants.ConnectorConfig.ENABLE_ADMIN_PASSWORD_RESET_WITH_RECOVERY_LINK, user.getTenantDomain()));
boolean isAdminPasswordReset = adminPasswordResetOffline | adminPasswordResetOTP | adminPasswordResetRecoveryLink;
if (isAdminPasswordReset && Boolean.valueOf(claims.get(IdentityRecoveryConstants.ADMIN_FORCED_PASSWORD_RESET_CLAIM))) {
if (log.isDebugEnabled()) {
log.debug(IdentityRecoveryConstants.ADMIN_FORCED_PASSWORD_RESET_CLAIM + " update request.");
}
Utils.publishRecoveryEvent(eventProperties, IdentityEventConstants.Event.PRE_FORCE_PASSWORD_RESET_BY_ADMIN, null);
// Remove claim to prevent persisting this temporary claim
claims.remove(IdentityRecoveryConstants.ADMIN_FORCED_PASSWORD_RESET_CLAIM);
String OTP = generateOTPValue();
String notificationType = "";
Enum recoveryScenario = RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP;
if (adminPasswordResetOffline) {
if (claims.containsKey(IdentityRecoveryConstants.OTP_PASSWORD_CLAIM)) {
claims.remove(IdentityRecoveryConstants.OTP_PASSWORD_CLAIM);
}
setUserClaim(IdentityRecoveryConstants.OTP_PASSWORD_CLAIM, OTP, userStoreManager, user);
}
if (adminPasswordResetOTP) {
notificationType = IdentityRecoveryConstants.NOTIFICATION_TYPE_ADMIN_FORCED_PASSWORD_RESET_WITH_OTP;
}
if (adminPasswordResetRecoveryLink) {
OTP = UUIDGenerator.generateUUID();
recoveryScenario = RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK;
notificationType = IdentityRecoveryConstants.NOTIFICATION_TYPE_ADMIN_FORCED_PASSWORD_RESET;
}
claims.remove(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM);
setRecoveryData(user, recoveryScenario, RecoverySteps.UPDATE_PASSWORD, OTP);
lockAccountOnAdminPasswordReset(user, claims);
if (adminPasswordResetOTP | adminPasswordResetRecoveryLink) {
try {
triggerNotification(user, notificationType, OTP, Utils.getArbitraryProperties(), new UserRecoveryData(user, OTP, recoveryScenario, RecoverySteps.UPDATE_PASSWORD));
Utils.publishRecoveryEvent(eventProperties, IdentityEventConstants.Event.POST_FORCE_PASSWORD_RESET_BY_ADMIN, OTP);
} catch (IdentityRecoveryException e) {
throw new IdentityEventException("Error while sending notification ", e);
}
}
}
}
use of org.wso2.carbon.identity.recovery.handler.AdminForcedPasswordResetHandler in project identity-governance by wso2-extensions.
the class AdminForcedPasswordResetHandler method handleAuthenticate.
protected void handleAuthenticate(Map<String, Object> eventProperties, UserStoreManager userStoreManager) throws IdentityEventException {
User user = getUser(eventProperties, userStoreManager);
if (log.isDebugEnabled()) {
log.debug("PreAuthenticate - AdminForcedPasswordResetHandler for user : " + user.toString());
}
UserRecoveryData userRecoveryData = getRecoveryData(user);
if (userRecoveryData != null) {
Enum recoveryScenario = userRecoveryData.getRecoveryScenario();
if (log.isDebugEnabled()) {
log.debug("Handling recovery scenario : " + recoveryScenario.toString() + " for user : " + user.toString());
}
String errorCode = null;
String errorMsg = "User : " + user.toString();
boolean isForcedPasswordReset = false;
if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.equals(recoveryScenario)) {
errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_EMAIL_LINK_ERROR_CODE;
errorMsg = errorMsg + " needs to reset the password using the given link in email";
isForcedPasswordReset = true;
} else if (RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.equals(recoveryScenario)) {
String credential = (String) eventProperties.get(IdentityEventConstants.EventProperty.CREDENTIAL);
isForcedPasswordReset = true;
if (userRecoveryData.getSecret().equals(credential)) {
errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_OTP_ERROR_CODE;
errorMsg = errorMsg + " has given correct OTP";
} else {
errorCode = IdentityCoreConstants.ADMIN_FORCED_USER_PASSWORD_RESET_VIA_OTP_MISMATCHED_ERROR_CODE;
errorMsg = errorMsg + " has given in-correct OTP";
}
}
if (isForcedPasswordReset) {
if (log.isDebugEnabled()) {
log.debug(errorMsg);
}
IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(errorCode);
IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
throw new IdentityEventException(errorMsg);
}
}
}
Aggregations