Skip to content

Commit

Permalink
Update debug logs and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshan-Banneheke committed Oct 12, 2023
1 parent 71241c9 commit d99d8ff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -2837,7 +2837,6 @@ public IdentityProvider getEnabledIdPByRealmId(String realmId, int tenantId, Str
} finally {
IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ public void testGetEnabledIdPRealmId(String idpName, String realmId, int tenantI
when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
addTestIdps();

IdentityProvider idpResult = idPManagementDAO.getIdPByRealmId(realmId, tenantId, TENANT_DOMAIN);
IdentityProvider idpResult = idPManagementDAO.getEnabledIdPByRealmId(realmId, tenantId, TENANT_DOMAIN);
if (isExist && isEnabled) {
assertEquals(idpResult.getIdentityProviderName(), idpName, "'getIDPbyRealmId' method fails");
} else {
Expand Down

0 comments on commit d99d8ff

Please sign in to comment.