From 50f95c50707223620d969230836a74dad28ded0f Mon Sep 17 00:00:00 2001 From: Lakshan Date: Thu, 12 Oct 2023 09:52:34 +0530 Subject: [PATCH] Update debug logs and comments --- .../idp/mgt/IdentityProviderManager.java | 3 +- .../idp/mgt/dao/CacheBackedIdPMgtDAO.java | 42 +++++++++++-------- .../carbon/idp/mgt/dao/IdPManagementDAO.java | 9 ++-- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java index 9d3ea4bac67c..55f22222167e 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java @@ -1675,8 +1675,7 @@ public IdentityProvider getEnabledIdPByRealmId(String realmId, String tenantDoma int tenantId = IdentityTenantUtil.getTenantId(tenantDomain); if (StringUtils.isEmpty(realmId)) { - String msg = "Invalid argument: Identity Provider Home Realm Identifier value is empty"; - throw new IdentityProviderManagementException(msg); + throw new IdentityProviderManagementException("Invalid argument: Identity Provider Home Realm Identifier value is empty"); } IdentityProvider identityProvider = dao.getEnabledIdPByRealmId(realmId, tenantId, tenantDomain); diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAO.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAO.java index 42502a3a3dbf..1e5c5c34a2ec 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAO.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/CacheBackedIdPMgtDAO.java @@ -518,12 +518,12 @@ public IdentityProvider getIdPByRealmId(String realmId, int tenantId, } /** - * Get the enabled IDP of the given realm id + * Get the enabled IDP of the given realm id. * - * @param realmId - * @param tenantId - * @param tenantDomain - * @return + * @param realmId Realm ID of the required identity provider. + * @param tenantId Tenant ID of the required identity provider. + * @param tenantDomain Tenant domain of the required identity provider. + * @return Enabled identity provider of the given realm id. * @throws IdentityProviderManagementException */ public IdentityProvider getEnabledIdPByRealmId(String realmId, int tenantId, @@ -532,32 +532,40 @@ public IdentityProvider getEnabledIdPByRealmId(String realmId, int tenantId, IdPHomeRealmIdCacheKey cacheKey = new IdPHomeRealmIdCacheKey(realmId); IdPCacheEntry entry = idPCacheByHRI.getValueFromCache(cacheKey, tenantDomain); if (entry != null) { - log.debug("Cache entry found for Identity Provider with Home Realm ID " + realmId); - //Check whether tne idp in the cache is enabled. + if (log.isDebugEnabled()) { + log.debug("Cache entry found for Identity Provider with Home Realm ID " + realmId); + } + //Check whether the idp in the cache is enabled. if (entry.getIdentityProvider().isEnable()) { return entry.getIdentityProvider(); } - log.debug("Identity Provider with Home Realm ID " + realmId + "available in the cache is disabled. " + - "Fetching entry from DB."); - + if (log.isDebugEnabled()) { + log.debug("Identity Provider with Home Realm ID " + realmId + "available in the cache is disabled. " + + "Fetching entry from DB."); + } } else { - log.debug("Cache entry not found for Identity Provider with Home Realm ID " + realmId - + ". Fetching entry from DB."); + if (log.isDebugEnabled()) { + log.debug("Cache entry not found for Identity Provider with Home Realm ID " + realmId + + ". Fetching entry from DB."); + } } IdentityProvider identityProvider = idPMgtDAO.getEnabledIdPByRealmId(realmId, tenantId, tenantDomain); if (identityProvider != null) { - log.debug("Entry fetched from DB for Identity Provider with Home Realm ID " + realmId - + ". Updating cache."); + if (log.isDebugEnabled()) { + log.debug("Entry fetched from DB for Identity Provider with Home Realm ID " + realmId + + ". Updating cache."); + } idPCacheByHRI.addToCache(cacheKey, new IdPCacheEntry(identityProvider), tenantDomain); IdPNameCacheKey idPNameCacheKey = new IdPNameCacheKey(identityProvider.getIdentityProviderName()); idPCacheByName.addToCache(idPNameCacheKey, new IdPCacheEntry(identityProvider), tenantDomain); } else { - log.debug("Entry for Identity Provider with Home Realm ID " + realmId - + " not found in cache or DB."); + if (log.isDebugEnabled()) { + log.debug("Entry for Identity Provider with Home Realm ID " + realmId + + " not found in cache or DB."); + } } - return identityProvider; } diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java index cd57c61ab743..87ca54efde83 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java @@ -2804,10 +2804,10 @@ public IdentityProvider getIdPByRealmId(String realmId, int tenantId, String ten } /** - * @param realmId - * @param tenantId - * @param tenantDomain - * @return + * @param realmId Realm ID of the required identity provider. + * @param tenantId Tenant ID of the required identity provider. + * @param tenantDomain Tenant domain of the required identity provider. + * @return Enabled identity provider of the given realm id. * @throws IdentityProviderManagementException * @throws SQLException */ @@ -2837,7 +2837,6 @@ public IdentityProvider getEnabledIdPByRealmId(String realmId, int tenantId, Str } finally { IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); } - } /**