From 4750c8097b75cdb7e1d170545d2ff2e9504f13ea Mon Sep 17 00:00:00 2001 From: Amanda Ariyaratne Date: Thu, 16 Nov 2023 10:48:36 +0530 Subject: [PATCH] Reuse sso login constant --- .../connector/recaptcha/EmailOTPCaptchaConnector.java | 2 +- .../carbon/identity/captcha/util/CaptchaUtil.java | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/EmailOTPCaptchaConnector.java b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/EmailOTPCaptchaConnector.java index 4d5f78228f..7a8563725e 100644 --- a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/EmailOTPCaptchaConnector.java +++ b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/connector/recaptcha/EmailOTPCaptchaConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2023, WSO2 LLC (http://www.wso2.org). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/util/CaptchaUtil.java b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/util/CaptchaUtil.java index 4fd1af1b01..9ed2db14cf 100644 --- a/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/util/CaptchaUtil.java +++ b/components/org.wso2.carbon.identity.captcha/src/main/java/org/wso2/carbon/identity/captcha/util/CaptchaUtil.java @@ -85,6 +85,7 @@ import static org.wso2.carbon.identity.captcha.util.CaptchaConstants.ENABLE_GENERIC_CAPTCHA_VALIDATION; import static org.wso2.carbon.identity.captcha.util.CaptchaConstants.ON_FAILED_LOGIN_REDIRECT_URL; import static org.wso2.carbon.identity.captcha.util.CaptchaConstants.ReCaptchaConnectorPropertySuffixes; +import static org.wso2.carbon.identity.captcha.util.CaptchaConstants.SSO_LOGIN_RECAPTCHA_CONNECTOR_NAME; /** * Captcha util functions. @@ -449,13 +450,11 @@ public static boolean isMaximumFailedLoginAttemptsReached(String usernameWithDom public static boolean isMaximumFailedLoginAttemptsReached(String usernameWithDomain, String tenantDomain, String failedAttemptsClaim) throws CaptchaException { - String CONNECTOR_NAME = "sso.login.recaptcha"; - Property[] connectorConfigs; try { connectorConfigs = CaptchaDataHolder.getInstance().getIdentityGovernanceService() - .getConfiguration(new String[]{CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.ENABLE, - CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.MAX_ATTEMPTS}, tenantDomain); + .getConfiguration(new String[]{SSO_LOGIN_RECAPTCHA_CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.ENABLE, + SSO_LOGIN_RECAPTCHA_CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.MAX_ATTEMPTS}, tenantDomain); } catch (Exception e) { // Can happen due to invalid user/ invalid tenant/ invalid configuration if (log.isDebugEnabled()) { @@ -470,10 +469,10 @@ public static boolean isMaximumFailedLoginAttemptsReached(String usernameWithDom String maxAttemptsStr = null; for (Property property : connectorConfigs) { - if ((CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.ENABLE).equals(property.getName()) + if ((SSO_LOGIN_RECAPTCHA_CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.ENABLE).equals(property.getName()) && !Boolean.valueOf(property.getValue())) { return false; - } else if ((CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.MAX_ATTEMPTS).equals(property.getName())) { + } else if ((SSO_LOGIN_RECAPTCHA_CONNECTOR_NAME + ReCaptchaConnectorPropertySuffixes.MAX_ATTEMPTS).equals(property.getName())) { maxAttemptsStr = property.getValue(); } }