diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java index 71a9a8e1942..10ed79f3ffa 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java @@ -244,6 +244,9 @@ public Object run() throws Exception { boolean isClientException = e.getCause().getCause() instanceof UserStoreClientException; String errorCode = ((UserStoreException) e.getCause().getCause()).getErrorCode(); String errorMessage = e.getCause().getCause().getMessage(); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } if (isClientException) { if (StringUtils.isBlank(errorCode)) { throw new UserStoreClientException(errorCode, e); diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreConstants.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreConstants.java index 6915b9081cb..25bd018c8e3 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreConstants.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreConstants.java @@ -51,6 +51,8 @@ public class JDBCUserStoreConstants { private static final String VALIDATION_INTERVAL = "validationInterval"; private static final String DISPLAY_NAME_ATTRIBUTE_DESCRIPTION = "This is the attribute name to display as the Display Name"; public static final String DISPLAY_NAME_ATTRIBUTE = "DisplayNameAttribute"; + public static final String SET_QUERY_TIMEOUT_ERROR_MSG = "Error while setting the query timeout value."; + public static final String UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG = "Unsupported credential type."; static { diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreManager.java index dbe40b085bd..c2767714d07 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCUserStoreManager.java @@ -96,7 +96,7 @@ public class JDBCUserStoreManager extends AbstractUserStoreManager { // private boolean useOnlyInternalRoles; - private static Log log = LogFactory.getLog(JDBCUserStoreManager.class); + private static final Log log = LogFactory.getLog(JDBCUserStoreManager.class); private static final String QUERY_FILTER_STRING_ANY = "*"; private static final String SQL_FILTER_STRING_ANY = "%"; @@ -495,7 +495,7 @@ public String[] doListUsers(String filter, int maxItemLimit) throws UserStoreExc prepStmt.setQueryTimeout(searchTime); } catch (Exception e) { // this can be ignored since timeout method is not implemented - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } try { @@ -697,7 +697,11 @@ public String[] doGetRoleNames(String filter, int maxItemLimit) throws UserStore } throw new UserStoreException(msg, e); } catch (Exception e) { - throw new UserStoreException("Error while retrieving the DB type. ", e); + String msg = "Error while retrieving the DB type."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } finally { DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); } @@ -734,7 +738,7 @@ private void setPSRestrictions(PreparedStatement ps, int maxItemLimit) throws SQ ps.setQueryTimeout(searchTime); } catch (Exception e) { // this can be ignored since timeout method is not implemented - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } } @@ -824,7 +828,11 @@ protected String[] doGetSharedRoleNames(String tenantDomain, String filter, int } throw new UserStoreException(errorMessage, e); } catch (Exception e) { - throw new UserStoreException("Error while retrieving the DB type for tenant domain: " + tenantDomain, e); + String msg = "Error while retrieving the DB type for tenant domain: " + tenantDomain + "."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } finally { DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); } @@ -1247,6 +1255,9 @@ private String[] getStringValuesFromDatabaseWithConstraints(String sqlStmt, int .getStringValuesFromDatabaseWithConstraints(dbConnection, sqlStmt, maxRows, queryTimeout, params); } catch (SQLException e) { String msg = "Error occurred while accessing the database connection."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } throw new UserStoreException(msg, e); } return values; @@ -1528,7 +1539,10 @@ protected void persistUser(String userName, Object credential, String[] roleList try { credentialObj = Secret.getSecret(credential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (log.isDebugEnabled()) { + log.debug(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } try { @@ -1791,7 +1805,7 @@ private int getTenantIdFromRole(String roleBase) { try { tenantId = Integer.parseInt(postfix[1]); } catch (NumberFormatException e) { - log.error(e); + log.error("An error occurred while parsing the tenant id to an integer.", e); tenantId = MultitenantConstants.SUPER_TENANT_ID; } } @@ -2648,7 +2662,11 @@ private String generateSaltValue() { secureRandom.nextBytes(bytes); saltValue = Base64.encode(bytes); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("SHA1PRNG algorithm could not be found."); + String msg = "SHA1PRNG algorithm could not be found."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new RuntimeException(msg, e); } return saltValue; } @@ -2920,7 +2938,10 @@ protected String preparePassword(Object password, String saltValue) throws UserS try { credentialObj = Secret.getSecret(password); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (log.isDebugEnabled()) { + log.debug(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } String digestFunction = realmConfig.getUserStoreProperties().get(JDBCRealmConstants.DIGEST_FUNCTION); if (digestFunction != null) { @@ -3088,7 +3109,7 @@ public boolean isValidRememberMeToken(String userName, String token) return isExistingRememberMeToken(userName, token); } } catch (Exception e) { - log.error("Validating remember me token failed for" + userName); + log.error("Validating remember me token failed for" + userName + ".", e); // not throwing exception. // because we need to seamlessly direct them to login uis } @@ -3171,7 +3192,7 @@ public String[] getUserListFromProperties(String property, String value, String prepStmt.setQueryTimeout(searchTime); } catch (Exception e) { // this can be ignored since timeout method is not implemented - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } rs = prepStmt.executeQuery(); while (rs.next()) { @@ -3328,6 +3349,7 @@ protected Map> getUsersPropertyValues(List u String errorMessage = "Error Occurred while getting property values"; if (log.isDebugEnabled()) { errorMessage = errorMessage + ": " + users; + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } finally { @@ -3406,6 +3428,7 @@ protected Map> doGetExternalRoleListOfUsers(List us String errorMessage = "Error Occurred while getting role lists of users"; if (log.isDebugEnabled()) { errorMessage = errorMessage + ": " + userNames; + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } finally { @@ -3848,7 +3871,7 @@ protected PaginatedSearchResult doListUsers(String filter, int limit, int offset prepStmt.setQueryTimeout(searchTime); } catch (Exception e) { // this can be ignored since timeout method is not implemented - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } try { @@ -3964,10 +3987,15 @@ public long doCountUsersWithClaims(String claimUri, String value) throws UserSto } catch (SQLException e) { String msg = "Error while executing the SQL " + sqlStmt; if (log.isDebugEnabled()) { - log.debug(msg + sqlStmt); + log.debug(msg + sqlStmt, e); } throw new UserStoreException(msg, e); } catch (UserStoreException ex) { + String msg = UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_COUNT_USERS + .getMessage(); + if (log.isDebugEnabled()) { + log.debug(msg, ex); + } handleGetUserCountFailure(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_COUNT_USERS .getCode(), String.format(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_COUNT_USERS @@ -3975,8 +4003,11 @@ public long doCountUsersWithClaims(String claimUri, String value) throws UserSto ex.getMessage()), claimUri, value); throw ex; } catch (org.wso2.carbon.user.api.UserStoreException e) { - String ErrorMsg = "Error while getting attribute name from " + claimUri ; - throw new UserStoreException(ErrorMsg, e); + String msg = "Error while getting attribute name from " + claimUri + "."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } } @@ -4037,6 +4068,11 @@ public long doCountRoles(String filter) throws UserStoreException { throw new UserStoreException(msg, e); } catch (UserStoreException ex) { + String msg = UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_ROLES_COUNT + .getMessage(); + if (log.isDebugEnabled()) { + log.debug(msg, ex); + } handleGetUserCountFailure(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_ROLES_COUNT .getCode(), String.format(UserCoreErrorConstants.ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_ROLES_COUNT diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCUserStoreManager.java index 9ab14d5ee9a..594e6078f29 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCUserStoreManager.java @@ -84,7 +84,7 @@ public class UniqueIDJDBCUserStoreManager extends JDBCUserStoreManager { - private static Log log = LogFactory.getLog(UniqueIDJDBCUserStoreManager.class); + private static final Log log = LogFactory.getLog(UniqueIDJDBCUserStoreManager.class); private static final String QUERY_FILTER_STRING_ANY = "*"; private static final String SQL_FILTER_STRING_ANY = "%"; @@ -208,7 +208,7 @@ public List doListUsersWithID(String filter, int maxItemLimit) throws User } catch (Exception e) { // this can be ignored since timeout method is not implemented if (log.isDebugEnabled()) { - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } } @@ -541,6 +541,9 @@ private List getUsersFromDatabaseWithConstraints(UserStoreManager userStor params); } catch (SQLException e) { String msg = "Error occurred while accessing the database connection."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } throw new UserStoreException(msg, e); } return values; @@ -725,6 +728,10 @@ protected AuthenticationResult doAuthenticateWithID(List loginI user.setTenantDomain(getTenantDomain(tenantId)); user.setUserStoreDomain(UserCoreUtil.getDomainName(realmConfig)); } catch (org.wso2.carbon.user.api.UserStoreException e) { + if (log.isDebugEnabled()) { + log.debug("An error occurred while setting either the user's tenant or users store" + + " domain.", e); + } throw new UserStoreException(e); } authenticationResult = new AuthenticationResult( @@ -1137,7 +1144,10 @@ protected void persistUser(String userID, String userName, Object credential, St try { credentialObj = Secret.getSecret(credential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type.", e); + if (log.isDebugEnabled()) { + log.debug(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(JDBCUserStoreConstants.UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } try { @@ -1333,6 +1343,9 @@ public String getUserIDFromProperties(String claimURI, String claimValue, String return userIds.get(0); } } catch (org.wso2.carbon.user.api.UserStoreException e) { + if (log.isDebugEnabled()) { + log.debug("An error occurred while extracting the user id from properties.", e); + } throw new UserStoreException( "Error occurred while retrieving the userId of domain : " + getMyDomainName() + " and " + "claim" + claimURI + " value: " + claimValue, e); @@ -2122,7 +2135,7 @@ private String generateSaltValue() { secureRandom.nextBytes(bytes); saltValue = Base64.encode(bytes); } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("SHA1PRNG algorithm could not be found."); + throw new RuntimeException("SHA1PRNG algorithm could not be found.", e); } return saltValue; } @@ -2381,7 +2394,7 @@ public List doGetUserListFromPropertiesWithID(String property, String va } catch (SQLException e) { // If SQL exception occurred here, we can ignore cause timeout method is not implemented. if (log.isDebugEnabled()) { - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } } rs = prepStmt.executeQuery(); @@ -2985,7 +2998,7 @@ protected UniqueIDPaginatedSearchResult doListUsersWithID(String filter, int lim prepStmt.setQueryTimeout(searchTime); } catch (Exception e) { // this can be ignored since timeout method is not implemented - log.debug(e); + log.debug(JDBCUserStoreConstants.SET_QUERY_TIMEOUT_ERROR_MSG, e); } try { diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ActiveDirectoryUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ActiveDirectoryUserStoreManager.java index 242f8f58e96..276fb409d68 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ActiveDirectoryUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ActiveDirectoryUserStoreManager.java @@ -73,7 +73,7 @@ */ public class ActiveDirectoryUserStoreManager extends ReadWriteLDAPUserStoreManager { - private static Log logger = LogFactory.getLog(ActiveDirectoryUserStoreManager.class); + private static final Log logger = LogFactory.getLog(ActiveDirectoryUserStoreManager.class); private boolean isADLDSRole = false; private boolean isSSLConnection = false; private String userAccountControl = "512"; @@ -93,6 +93,7 @@ public class ActiveDirectoryUserStoreManager extends ReadWriteLDAPUserStoreManag // For AD's this value is 1500 by default, hence overriding the default value. protected static final int MEMBERSHIP_ATTRIBUTE_RANGE_VALUE = 1500; + private static final String UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG = "Unsupported credential type."; static { setAdvancedProperties(); @@ -171,7 +172,10 @@ public void doAddUser(String userName, Object credential, String[] roleList, try { credentialObj = Secret.getSecret(credential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (logger.isDebugEnabled()) { + logger.debug(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } Name compoundName = null; @@ -212,10 +216,16 @@ public void doAddUser(String userName, Object credential, String[] roleList, dirContext.unbind(compoundName); } catch (NamingException e1) { errorMessage = "Error while accessing the Active Directory for user : " + userName; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } errorMessage = "Error while enabling the user account. Please check password policy at DC for user : " + userName; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } } throw new UserStoreException(errorMessage, e); } finally { @@ -255,6 +265,9 @@ protected void setUserClaims(Map claims, BasicAttributes basicAt attributeName = getClaimAtrribute(claimURI, userName, null); } catch (org.wso2.carbon.user.api.UserStoreException e) { String errorMessage = "Error in obtaining claim mapping."; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } @@ -318,7 +331,10 @@ public void doUpdateCredential(String userName, Object newCredential, Object old try { credentialObj = Secret.getSecret(newCredential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (logger.isDebugEnabled()) { + logger.debug(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } if (logger.isDebugEnabled()) { @@ -431,7 +447,7 @@ public void doUpdateCredentialByAdmin(String userName, Object newCredential) try { credentialObj = Secret.getSecret(newCredential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + throw new UserStoreException(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } try { @@ -647,7 +663,7 @@ public String[] getUserListOfLDAPRole(RoleContext context, String filter) throws } catch (NumberFormatException e) { if (debug) { logger.debug("Error occurred while reading user store property: " - + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST + " : " + e); + + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST + " : " + e, e); } givenMax = UserCoreConstants.MAX_USER_ROLE_LIST; } @@ -658,7 +674,7 @@ public String[] getUserListOfLDAPRole(RoleContext context, String filter) throws } catch (NumberFormatException e) { if (debug) { logger.debug("Error occurred while reading user store property: " - + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME + " : " + e); + + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME + " : " + e, e); } searchTime = UserCoreConstants.MAX_SEARCH_TIME; } @@ -810,6 +826,11 @@ private void handleException(Exception e, String userName) throws UserStoreExcep logger.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); + } else { + String errorMessage = "Error while performing the operation with the user : " + userName + "."; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } } } diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadOnlyLDAPUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadOnlyLDAPUserStoreManager.java index d5e0640b96e..08192db0077 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadOnlyLDAPUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadOnlyLDAPUserStoreManager.java @@ -123,7 +123,7 @@ public class ReadOnlyLDAPUserStoreManager extends AbstractUserStoreManager { protected static final String MEMBERSHIP_ATTRIBUTE_RANGE_DISPLAY_NAME = "Membership Attribute Range"; private static final String USER_CACHE_NAME_PREFIX = CachingConstants.LOCAL_CACHE_PREFIX + "UserCache-"; private static final String USER_CACHE_MANAGER = "UserCacheManager"; - private static Log log = LogFactory.getLog(ReadOnlyLDAPUserStoreManager.class); + private static final Log log = LogFactory.getLog(ReadOnlyLDAPUserStoreManager.class); protected static final int MAX_USER_CACHE = 200; private static final String PROPERTY_REFERRAL_IGNORE = "ignore"; private static final String MULTI_ATTRIBUTE_SEPARATOR = "MultiAttributeSeparator"; @@ -149,7 +149,6 @@ public class ReadOnlyLDAPUserStoreManager extends AbstractUserStoreManager { private static final String USE_ANONYMOUS_BIND = "AnonymousBind"; protected static final int MEMBERSHIP_ATTRIBUTE_RANGE_VALUE = 0; private static final int MAX_ITEM_LIMIT_UNLIMITED = -1; - private static Log logger = LogFactory.getLog(ReadOnlyLDAPUserStoreManager.class); private String cacheExpiryTimeAttribute = ""; //Default: expire with default system wide cache expiry private long userDnCacheExpiryTime = 0; //Default: No cache @@ -254,7 +253,7 @@ public ReadOnlyLDAPUserStoreManager(RealmConfiguration realmConfig, // Skipped to throw a UserStoreException and log the error message in-order to successfully initiate and // create the user-store object. log.error("Cannot create connection to LDAP server. Connection URL: " + realmConfig - .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage()); + .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage(), e); } finally { JNDIUtil.closeContext(dirContext); } @@ -456,7 +455,11 @@ public boolean doAuthenticate(String userName, Object credential) throws UserSto try { credentialObj = Secret.getSecret(credential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + String msg = "Unsupported credential type."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } if (userName.equals("") || credentialObj.isEmpty()) { @@ -830,7 +833,7 @@ protected boolean isExistingLDAPRole(RoleContext context) throws UserStoreExcept answer = dirContext.search(escapeDNForSearch(pattern), searchFilter, searchCtls); } catch (NamingException e) { if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } // ignore } @@ -854,7 +857,7 @@ protected boolean isExistingLDAPRole(RoleContext context) throws UserStoreExcept } } catch (NamingException e) { if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } // ignore } @@ -1347,7 +1350,7 @@ protected boolean bindAsUser(String dn, String credentials) throws NamingExcepti // we avoid throwing an exception here since we throw that exception // in a one level above this. if (debug) { - log.debug("Authentication failed " + e); + log.debug("Authentication failed " + e, e); } } finally { @@ -1426,7 +1429,7 @@ private boolean bindAsUser(String userName, String dn, Object credentials) throw // we avoid throwing an exception here since we throw that exception // in a one level above this. if (debug) { - log.debug("Authentication failed " + e); + log.debug("Authentication failed " + e, e); log.debug("Clearing cache for DN: " + dn); } if (userName != null) { @@ -1984,7 +1987,7 @@ public String[] getUserListOfLDAPRole(RoleContext context, String filter) throws } catch (NamingException e) { // ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } } } @@ -2017,7 +2020,7 @@ public String[] getUserListOfLDAPRole(RoleContext context, String filter) throws } catch (NamingException e) { // ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } } } @@ -2349,7 +2352,7 @@ protected String[] getLDAPRoleListOfUser(String userName, String filter, String membershipValue = escapeLdapNameForFilter(ldn); } } catch (InvalidNameException e) { - log.error("Error while creating LDAP name from: " + nameInSpace); + log.error("Error while creating LDAP name from: " + nameInSpace, e); throw new UserStoreException("Invalid naming exception for : " + nameInSpace, e); } } else { @@ -2682,7 +2685,7 @@ protected List getAttributeListOfOneElement(String searchBases, String s } catch (NamingException e) { //ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } } } @@ -2746,7 +2749,7 @@ private List getListOfNames(String searchBases, String searchFilter, } catch (NamingException e) { // ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } } @@ -2960,11 +2963,11 @@ protected PaginatedSearchResult doGetUserList(Condition condition, String profil result.setUsers(ldapUsers.toArray(new String[0])); return result; } catch (NamingException e) { - log.error(String.format("Error occurred while performing paginated search, %s", e.getMessage())); + log.error(String.format("Error occurred while performing paginated search, %s", e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } catch (IOException e) { log.error(String.format("Error occurred while setting paged results controls for paginated search, %s", - e.getMessage())); + e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeContext(dirContext); @@ -3149,18 +3152,19 @@ private List performLDAPSearch(LdapContext ldapContext, LDAPSearchSpecif // Can be due to referrals in AD. So just ignore error. if (isIgnorePartialResultException()) { if (log.isDebugEnabled()) { - log.debug(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter)); + log.debug(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter), + e); } } else { - log.error(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter)); + log.error(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter), e); throw new UserStoreException(e.getMessage(), e); } } catch (NamingException e) { log.error(String.format("Error occurred while searching for user(s) for filter: %s, %s", - searchFilter, e.getMessage())); + searchFilter, e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } catch (IOException e) { - log.error(String.format("Error occurred while doing paginated search, %s", e.getMessage())); + log.error(String.format("Error occurred while doing paginated search, %s", e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeNamingEnumeration(answer); @@ -3274,7 +3278,7 @@ this case, the intersection (AND operation) should not be performed on the filte } } } catch (NamingException e) { - log.error(String.format("Error occurred while getting user list from group filter %s", e.getMessage())); + log.error(String.format("Error occurred while getting user list from group filter %s", e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeNamingEnumeration(attrs); @@ -3338,7 +3342,7 @@ private List getUserNamesFromDNList(List userListFromSearch) thr } } catch (NamingException e) { log.error(String.format("Error in reading user information in the user store for the user %s, %s", - user, e.getMessage())); + user, e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } } @@ -3404,7 +3408,8 @@ private List getUserListFromNonGroupFilterResult(NamingEnumeration getUserListFromClaimFiltering(List exp } } catch (NamingException e) { log.error(String.format("Error occurred while doing claim filtering for user(s) with filter: %s, %s", - claimSearch.getSearchFilterQuery(), e.getMessage())); + claimSearch.getSearchFilterQuery(), e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeContext(claimSearchDirContext); @@ -3738,7 +3743,7 @@ public boolean doCheckIsUserInRole(String userName, String roleName) throws User LdapName ldn = new LdapName(nameInSpace); membershipValue = escapeLdapNameForFilter(ldn); } catch (InvalidNameException e) { - log.error("Error while creating LDAP name from: " + nameInSpace); + log.error("Error while creating LDAP name from: " + nameInSpace, e); throw new UserStoreException("Invalid naming exception for : " + nameInSpace, e); } } else { @@ -3772,7 +3777,7 @@ public boolean doCheckIsUserInRole(String userName, String roleName) throws User answer = dirContext.search(escapeDNForSearch(searchBases), searchFilter, searchCtls); } catch (NamingException e) { if (log.isDebugEnabled()) { - log.debug(e); + log.debug("An error occurred while extracting the answer.", e); } //ignore } @@ -4031,7 +4036,7 @@ public boolean isValidRememberMeToken(String userName, String token) return jdbcUserStore.isExistingRememberMeToken(userName, token); } } catch (Exception e) { - log.error("Validating remember me token failed for" + userName); + log.error("Validating remember me token failed for" + userName, e); /* * not throwing exception. because we need to seamlessly direct them * to login uis @@ -4089,13 +4094,7 @@ private List getGroupNameAttributeValuesOfGroups(List groupDNs } } } - } catch (UserStoreException e) { - String errorMessage = "Error in getting group name attribute values of groups"; - if (log.isDebugEnabled()) { - log.debug(errorMessage, e); - } - throw new UserStoreException(errorMessage, e); - } catch (NamingException e) { + } catch (UserStoreException | NamingException e) { String errorMessage = "Error in getting group name attribute values of groups"; if (log.isDebugEnabled()) { log.debug(errorMessage, e); @@ -4792,13 +4791,13 @@ protected void processAttributesAfterRetrieval(String userName, Map convertedTimestampAttributeValues = Arrays.stream(timestampAttributes) @@ -4807,14 +4806,14 @@ protected void processAttributesAfterRetrieval(String userName, Map convertDateFormatFromLDAP(userStorePropertyValues.get(attribute)))); - if (logger.isDebugEnabled()) { - logger.debug("Converted timestamp attribute values: " + convertedTimestampAttributeValues); + if (log.isDebugEnabled()) { + log.debug("Converted timestamp attribute values: " + convertedTimestampAttributeValues); } userStorePropertyValues.putAll(convertedTimestampAttributeValues); - if (logger.isDebugEnabled()) { - logger.debug("Retrieved user store properties after type conversions: " + userStorePropertyValues); + if (log.isDebugEnabled()) { + log.debug("Retrieved user store properties after type conversions: " + userStorePropertyValues); } } } diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadWriteLDAPUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadWriteLDAPUserStoreManager.java index 8099bd8a528..f7a4df5e2cd 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadWriteLDAPUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/ReadWriteLDAPUserStoreManager.java @@ -102,8 +102,7 @@ public class ReadWriteLDAPUserStoreManager extends ReadOnlyLDAPUserStoreManager /* To track whether this is the first time startup of the server. */ protected static boolean isFirstStartup = true; - private static Log logger = LogFactory.getLog(ReadWriteLDAPUserStoreManager.class); - private static Log log = LogFactory.getLog(ReadWriteLDAPUserStoreManager.class); + private static final Log log = LogFactory.getLog(ReadWriteLDAPUserStoreManager.class); private static final String BULK_IMPORT_SUPPORT = "BulkImportSupported"; protected Random random = new Random(); @@ -171,7 +170,7 @@ public ReadWriteLDAPUserStoreManager(RealmConfiguration realmConfig, // Skipped to throw a UserStoreException and log the error message in-order to successfully initiate and // create the user-store object. log.error("Cannot create connection to LDAP server. Connection URL: " + realmConfig - .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage()); + .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage(), e); } finally { JNDIUtil.closeContext(dirContext); } @@ -1270,7 +1269,7 @@ protected void addLDAPRole(RoleContext context) throws UserStoreException { } else { String errorMsg = "There is no user with the user name: " + userName + " to be added to this role."; - logger.error(errorMsg); + log.error(errorMsg); throw new UserStoreException(errorMsg); } // get his DN @@ -1290,12 +1289,6 @@ protected void addLDAPRole(RoleContext context) throws UserStoreException { Name compoundGroupName = ldapParser.parse("cn=" + roleName); groupContext.bind(compoundGroupName, null, groupAttributes); - } catch (NamingException e) { - String errorMsg = "Role: " + roleName + " could not be added."; - if (log.isDebugEnabled()) { - log.debug(errorMsg, e); - } - throw new UserStoreException(errorMsg, e); } catch (Exception e) { String errorMsg = "Role: " + roleName + " could not be added."; if (log.isDebugEnabled()) { @@ -1709,7 +1702,7 @@ protected void modifyUserInRole(String userNameDN, String groupRDN, int modifyTy throws UserStoreException { if (log.isDebugEnabled()) { - logger.debug("Modifying role: " + groupRDN + " with type: " + modifyType + " user: " + userNameDN + log.debug("Modifying role: " + groupRDN + " with type: " + modifyType + " user: " + userNameDN + " in search base: " + searchBase); } @@ -1726,7 +1719,7 @@ protected void modifyUserInRole(String userNameDN, String groupRDN, int modifyTy groupContext.modifyAttributes(groupRDN, modifyType, modifyingAttributes); if (log.isDebugEnabled()) { - logger.debug("User: " + userNameDN + " was successfully " + "modified in LDAP group: " + log.debug("User: " + userNameDN + " was successfully " + "modified in LDAP group: " + groupRDN); } } catch (NamingException e) { @@ -2133,6 +2126,9 @@ protected void setUserClaims(Map claims, BasicAttributes basicAt attributeName = getClaimAtrribute(claimURI, userName, null); } catch (org.wso2.carbon.user.api.UserStoreException e) { String errorMessage = "Error in obtaining claim mapping."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } @@ -2239,36 +2235,41 @@ private void handleException(Exception e, String userName) throws UserStoreExcep if (e instanceof InvalidAttributeValueException) { String errorMessage = "One or more attribute values provided are incompatible for user : " + userName + "Please check and try again."; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof InvalidAttributeIdentifierException) { String errorMessage = "One or more attributes you are trying to add/update are not " + "supported by underlying LDAP for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof NoSuchAttributeException) { String errorMessage = "One or more attributes you are trying to add/update are not " + "supported by underlying LDAP for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof NamingException) { String errorMessage = "Profile information could not be updated in LDAP user store for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof org.wso2.carbon.user.api.UserStoreException) { String errorMessage = "Error in obtaining claim mapping for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); + } else { + String errorMessage = "Error while performing the operation with the user : " + userName + "."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } } } @@ -2509,13 +2510,13 @@ protected void processAttributesBeforeUpdate(String userName, Map claims, BasicAttributes basicAt attributeName = getClaimAtrribute(claimURI, userName, null); } catch (org.wso2.carbon.user.api.UserStoreException e) { String errorMessage = "Error in obtaining claim mapping."; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } @@ -355,7 +371,7 @@ public List getUserListOfLDAPRoleWithID(RoleContext context, String filter } catch (NumberFormatException e) { if (debug) { logger.debug("Error occurred while reading user store property: " - + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST + " : " + e); + + UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST + " : " + e, e); } givenMax = UserCoreConstants.MAX_USER_ROLE_LIST; } @@ -366,7 +382,7 @@ public List getUserListOfLDAPRoleWithID(RoleContext context, String filter } catch (NumberFormatException e) { if (debug) { logger.debug("Error occurred while reading user store property: " - + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME + " : " + e); + + UserCoreConstants.RealmConfig.PROPERTY_MAX_SEARCH_TIME + " : " + e, e); } searchTime = UserCoreConstants.MAX_SEARCH_TIME; } @@ -504,7 +520,10 @@ public void doUpdateCredentialWithID(String userID, Object newCredential, Object try { credentialObj = Secret.getSecret(newCredential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (logger.isDebugEnabled()) { + logger.debug(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } if (logger.isDebugEnabled()) { @@ -515,7 +534,11 @@ public void doUpdateCredentialWithID(String userID, Object newCredential, Object .getNameInNamespace()); } } catch (NamingException e) { - logger.debug("Error while getting DN of search base", e); + String msg = "Error while getting DN of search base."; + if (logger.isDebugEnabled()) { + logger.debug(msg, e); + } + logger.debug(msg, e); } } @@ -622,7 +645,10 @@ public void doUpdateCredentialByAdminWithID(String userID, Object newCredential) try { credentialObj = Secret.getSecret(newCredential); } catch (UnsupportedSecretTypeException e) { - throw new UserStoreException("Unsupported credential type", e); + if (logger.isDebugEnabled()) { + logger.debug(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); + } + throw new UserStoreException(UNSUPPORTED_CREDENTIAL_TYPE_ERROR_MSG, e); } try { @@ -893,6 +919,11 @@ private void handleException(Exception e, String userName) throws UserStoreExcep logger.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); + } else { + String errorMessage = "Error while performing the operation with the user : " + userName + "."; + if (logger.isDebugEnabled()) { + logger.debug(errorMessage, e); + } } } diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadOnlyLDAPUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadOnlyLDAPUserStoreManager.java index d1c137f5a62..4e7d2d99d26 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadOnlyLDAPUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadOnlyLDAPUserStoreManager.java @@ -117,14 +117,13 @@ public class UniqueIDReadOnlyLDAPUserStoreManager extends ReadOnlyLDAPUserStoreManager { - private static Log logger = LogFactory.getLog(UniqueIDReadOnlyLDAPUserStoreManager.class); public static final String MEMBER_UID = "memberUid"; protected static final String OBJECT_GUID = "objectGUID"; protected static final String MEMBERSHIP_ATTRIBUTE_RANGE = "MembershipAttributeRange"; protected static final String MEMBERSHIP_ATTRIBUTE_RANGE_DISPLAY_NAME = "Membership Attribute Range"; private static final String USER_CACHE_NAME_PREFIX = CachingConstants.LOCAL_CACHE_PREFIX + "UserCache-"; private static final String USER_CACHE_MANAGER = "UserCacheManager"; - private static Log log = LogFactory.getLog(UniqueIDReadOnlyLDAPUserStoreManager.class); + private static final Log log = LogFactory.getLog(UniqueIDReadOnlyLDAPUserStoreManager.class); private static final String MULTI_ATTRIBUTE_SEPARATOR_DESCRIPTION = "This is the separator for multiple claim " + "values"; @@ -146,6 +145,7 @@ public class UniqueIDReadOnlyLDAPUserStoreManager extends ReadOnlyLDAPUserStoreM + "Values {0: expire immediately, -1: never expire, '': i.e. empty, system default}."; protected static final String USER_DN_CACHE_ENABLED_ATTRIBUTE_DESCRIPTION = "Enables the user cache. Default true," + " Unless set to false. Empty value is interpreted as true."; + private static final String EXTRACTING_ANSWER_ERROR_MSG = "An error occurred while extracting the answer."; // Authenticating to LDAP via Anonymous Bind. private static final String USE_ANONYMOUS_BIND = "AnonymousBind"; @@ -616,9 +616,13 @@ private String getUserIDFromProperty(String property, String claimValue) throws return userIds.get(0); } } catch (org.wso2.carbon.user.api.UserStoreException e) { + String msg ="Error occurred while retrieving the userId of domain : " + getMyDomainName() + " and " + + "property" + property + " value: " + claimValue + "."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } throw new UserStoreException( - "Error occurred while retrieving the userId of domain : " + getMyDomainName() + " and " + "property" - + property + " value: " + claimValue, e); + msg, e); } } @@ -1006,7 +1010,7 @@ protected List getUserListOfLDAPRoleWithID(RoleContext context, String fil } catch (NamingException e) { // ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug(EXTRACTING_ANSWER_ERROR_MSG, e); } } } @@ -1039,7 +1043,7 @@ protected List getUserListOfLDAPRoleWithID(RoleContext context, String fil } catch (NamingException e) { // ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug(EXTRACTING_ANSWER_ERROR_MSG, e); } } } @@ -1311,7 +1315,7 @@ protected List getAttributeListOfOneElement(String searchBases, String s } catch (NamingException e) { //ignore if (log.isDebugEnabled()) { - log.debug(e); + log.debug(EXTRACTING_ANSWER_ERROR_MSG, e); } } } @@ -1533,11 +1537,11 @@ protected UniqueIDPaginatedSearchResult doGetUserListWithID(Condition condition, result.setUsers(users); return result; } catch (NamingException e) { - log.error(String.format("Error occurred while performing paginated search, %s", e.getMessage())); + log.error(String.format("Error occurred while performing paginated search, %s.", e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } catch (IOException e) { - log.error(String.format("Error occurred while setting paged results controls for paginated search, %s", - e.getMessage())); + log.error(String.format("Error occurred while setting paged results controls for paginated search, %s.", + e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeContext(dirContext); @@ -1817,8 +1821,11 @@ private List paginateLDAPNameList(List groups, int offset, i paginatedGroups.add(group); } } catch (NamingException e) { - throw new UserStoreException(ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getMessage(), - ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getCode(), e); + String msg = ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getMessage(); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getCode(), e); } return paginatedGroups; } @@ -1887,7 +1894,7 @@ private List getGroupsFromMembership(String username, int limit, int offs membershipValue = escapeLdapNameForFilter(ldn); } } catch (InvalidNameException e) { - log.error("Error while creating LDAP name from: " + nameInSpace); + log.error("Error while creating LDAP name from: " + nameInSpace + ".", e); throw new UserStoreException("Invalid naming exception for : " + nameInSpace, e); } String[] returnedAttributes = getMandatoryGroupsAttributesList().toArray(new String[0]); @@ -1957,13 +1964,13 @@ private List getListOfGroups(String searchBases, String groupFilter, int } } catch (NamingException e) { if (log.isDebugEnabled()) { - log.error("Error occurred while performing paginated search", e); + log.error("Error occurred while performing paginated search.", e); } throw new UserStoreException(ERROR_WHILE_GETTING_GROUPS.getMessage(), ERROR_WHILE_GETTING_GROUPS.getCode(), e); } catch (IOException e) { if (log.isDebugEnabled()) { - log.error("Error occurred while setting paged results controls for paginated search", e); + log.error("Error occurred while setting paged results controls for paginated search.", e); } throw new UserStoreException(ERROR_WHILE_GETTING_GROUPS.getMessage(), ERROR_WHILE_GETTING_GROUPS.getCode(), e); @@ -2023,7 +2030,7 @@ private List getListOfNames(String searchBases, String searchFilter, Str return names; } catch (NamingException e) { if (log.isDebugEnabled()) { - log.error("Error occurred while performing paginated search", e); + log.error("Error occurred while performing paginated search.", e); } throw new UserStoreException(ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getMessage(), ERROR_WHILE_PERFORMING_PAGINATED_SEARCH.getCode(), e); @@ -2058,8 +2065,11 @@ private List getGroupFromGroupDNs(List groups) throws UserStore } } } catch (UserStoreException | NamingException e) { - throw new UserStoreException(ERROR_WHILE_GETTING_GROUPS.getMessage(), - ERROR_WHILE_GETTING_GROUPS.getCode(), e); + String msg = ERROR_WHILE_GETTING_GROUPS.getMessage(); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_GETTING_GROUPS.getCode(), e); } finally { JNDIUtil.closeContext(dirContext); } @@ -2074,7 +2084,7 @@ private List buildLDAPNamingList(List groupDNs) { groups.add(new LdapName(groupDN)); } catch (InvalidNameException e) { if (log.isDebugEnabled()) { - log.debug("LDAP Name error for dn: " + groupDN, e); + log.debug("LDAP Name error for dn: " + groupDN + ".", e); } } } @@ -2705,7 +2715,11 @@ protected void initUserCache() throws UserStoreException { log.debug("Tenant domain : " + tenantDomain + " found for the tenant ID : " + tenantId); } } catch (org.wso2.carbon.user.api.UserStoreException e) { - throw new UserStoreException("Could not get the tenant domain for tenant id : " + tenantId, e); + String msg = "Could not get the tenant domain for tenant id : " + tenantId + "."; + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } } @@ -2906,13 +2920,13 @@ protected void processAttributesAfterRetrievalWithID(String userID, Map convertedTimestampAttributeValues = Arrays.stream(timestampAttributes) @@ -2920,14 +2934,14 @@ protected void processAttributesAfterRetrievalWithID(String userID, Map convertDateFormatFromLDAP(userStorePropertyValues.get(attribute)))); - if (logger.isDebugEnabled()) { - logger.debug("Converted timestamp attribute values: " + convertedTimestampAttributeValues); + if (log.isDebugEnabled()) { + log.debug("Converted timestamp attribute values: " + convertedTimestampAttributeValues); } userStorePropertyValues.putAll(convertedTimestampAttributeValues); - if (logger.isDebugEnabled()) { - logger.debug("Retrieved user store properties after type conversions: " + userStorePropertyValues); + if (log.isDebugEnabled()) { + log.debug("Retrieved user store properties after type conversions: " + userStorePropertyValues); } } } @@ -3007,18 +3021,19 @@ private List performLDAPSearch(LdapContext ldapContext, LDAPSearchSpecific // Can be due to referrals in AD. So just ignore error. if (isIgnorePartialResultException()) { if (log.isDebugEnabled()) { - log.debug(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter)); + log.debug(String.format("Error occurred while searching for user(s) for filter: %s.", searchFilter), + e); } } else { - log.error(String.format("Error occurred while searching for user(s) for filter: %s", searchFilter)); + log.error(String.format("Error occurred while searching for user(s) for filter: %s.", searchFilter)); throw new UserStoreException(e.getMessage(), e); } } catch (NamingException e) { - log.error(String.format("Error occurred while searching for user(s) for filter: %s, %s", - searchFilter, e.getMessage())); + log.error(String.format("Error occurred while searching for user(s) for filter: %s, %s.", + searchFilter, e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } catch (IOException e) { - log.error(String.format("Error occurred while doing paginated search, %s", e.getMessage())); + log.error(String.format("Error occurred while doing paginated search, %s.", e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeNamingEnumeration(answer); @@ -3132,7 +3147,8 @@ private List getUserListFromNonGroupFilterResult(NamingEnumeration getUserListFromMemberOfGroupFilterResult(NamingEnumeration getUserListFromDNList(List userListFromSearch) throws } } } catch (NamingException e) { - log.error(String.format("Error in reading user information in the user store for the user %s, %s", - userFromSearch, e.getMessage())); + log.error(String.format("Error in reading user information in the user store for the user %s, %s.", + userFromSearch, e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } } @@ -3488,8 +3505,8 @@ private List getUserListFromClaimFiltering(List expre Arrays.asList(claimSearchControls.getReturningAttributes())); } } catch (NamingException e) { - log.error(String.format("Error occurred while doing claim filtering for user(s) with filter: %s, %s", - claimSearch.getSearchFilterQuery(), e.getMessage())); + log.error(String.format("Error occurred while doing claim filtering for user(s) with filter: %s, %s.", + claimSearch.getSearchFilterQuery(), e.getMessage()), e); throw new UserStoreException(e.getMessage(), e); } finally { JNDIUtil.closeContext(claimSearchDirContext); @@ -3536,14 +3553,22 @@ private Attributes getGroupAttributesBySearchBase(String groupIdentifier, String } } } catch (NamingException e) { + String msg; // We need to throw different exception if the identifier is group name. if (isGroupNameIdentifier) { - throw new UserStoreException(String.format(ERROR_WHILE_GETTING_GROUP_BY_NAME.getMessage(), - groupIdentifier, getMyDomainName(), tenantId), - ERROR_WHILE_GETTING_GROUP_BY_NAME.getCode(), e); + msg = String.format(ERROR_WHILE_GETTING_GROUP_BY_NAME.getMessage(), groupIdentifier, + getMyDomainName(), tenantId); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, e); } - throw new UserStoreException(String.format(ERROR_WHILE_GETTING_GROUP_BY_ID.getMessage(), - groupIdentifier, getMyDomainName(), tenantId), ERROR_WHILE_GETTING_GROUP_BY_ID.getCode(), e); + msg = (String.format(ERROR_WHILE_GETTING_GROUP_BY_ID.getMessage(), + groupIdentifier, getMyDomainName(), tenantId)); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_GETTING_GROUP_BY_ID.getCode(), e); } finally { JNDIUtil.closeNamingEnumeration(answer); JNDIUtil.closeContext(dirContext); @@ -3590,8 +3615,12 @@ private Attributes getGroupAttributesByDNPatterns(String groupName, String group } } } catch (NamingException e) { - throw new UserStoreException(String.format(ERROR_WHILE_GETTING_GROUP_BY_NAME.getMessage(), - groupName, getMyDomainName(), tenantId), ERROR_WHILE_GETTING_GROUP_BY_NAME.getCode(), e); + String msg = String.format(ERROR_WHILE_GETTING_GROUP_BY_NAME.getMessage(), + groupName, getMyDomainName(), tenantId); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_GETTING_GROUP_BY_NAME.getCode(), e); } finally { JNDIUtil.closeNamingEnumeration(answer); JNDIUtil.closeContext(dirContext); @@ -3638,8 +3667,12 @@ private Group buildGroupFromAttributes(String[] responseAttributes, Attributes a } } } catch (NamingException e) { - throw new UserStoreException(String.format(ERROR_WHILE_BUILDING_GROUP_RESPONSE.getMessage(), - getMyDomainName(), tenantId), ERROR_WHILE_BUILDING_GROUP_RESPONSE.getCode(), e); + String msg = String.format(ERROR_WHILE_BUILDING_GROUP_RESPONSE.getMessage(), + getMyDomainName(), tenantId); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_BUILDING_GROUP_RESPONSE.getCode(), e); } group.setUserStoreDomain(getMyDomainName()); group.setTenantDomain(tenantDomain); @@ -3865,8 +3898,11 @@ private List getListOfGroupNamesWithPrimaryGroup(String searchBase, Stri throw new UserStoreException(errorMessage, e); } } catch (NamingException e) { - throw new UserStoreException(ERROR_WHILE_GETTING_GROUPS.getMessage(), - ERROR_WHILE_GETTING_GROUPS.getCode(), e); + String msg = ERROR_WHILE_GETTING_GROUPS.getMessage(); + if (log.isDebugEnabled()) { + log.debug(msg, e); + } + throw new UserStoreException(msg, ERROR_WHILE_GETTING_GROUPS.getCode(), e); } finally { JNDIUtil.closeNamingEnumeration(answer); JNDIUtil.closeContext(dirContext); diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadWriteLDAPUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadWriteLDAPUserStoreManager.java index f3b6cd54921..734aae4030d 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadWriteLDAPUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/ldap/UniqueIDReadWriteLDAPUserStoreManager.java @@ -103,8 +103,7 @@ public class UniqueIDReadWriteLDAPUserStoreManager extends UniqueIDReadOnlyLDAPU /* To track whether this is the first time startup of the server. */ protected static boolean isFirstStartup = true; - private static Log logger = LogFactory.getLog(UniqueIDReadWriteLDAPUserStoreManager.class); - private static Log log = LogFactory.getLog(UniqueIDReadWriteLDAPUserStoreManager.class); + private static final Log log = LogFactory.getLog(UniqueIDReadWriteLDAPUserStoreManager.class); private static final String BULK_IMPORT_SUPPORT = "BulkImportSupported"; protected Random random = new Random(); @@ -169,7 +168,7 @@ public UniqueIDReadWriteLDAPUserStoreManager(RealmConfiguration realmConfig, Map // Skipped to throw a UserStoreException and log the error message in-order to successfully initiate and // create the user-store object. log.error("Cannot create connection to LDAP server. Connection URL: " + realmConfig - .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage()); + .getUserStoreProperty(LDAPConstants.CONNECTION_URL) + " Error message: " + e.getMessage(), e); } finally { JNDIUtil.closeContext(dirContext); } @@ -392,6 +391,9 @@ protected void setUserClaimsWithID(Map claims, BasicAttributes b attributeName = getClaimAtrribute(claimURI, userName, null); } catch (org.wso2.carbon.user.api.UserStoreException e) { String errorMessage = "Error in obtaining claim mapping."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } @@ -1492,7 +1494,7 @@ protected void addLDAPRole(RoleContext context) throws UserStoreException { } else { String errorMsg = "There is no user with the user name: " + userName + " to be added to this role."; - logger.error(errorMsg); + log.error(errorMsg); throw new UserStoreException(errorMsg); } // get his DN @@ -1512,12 +1514,6 @@ protected void addLDAPRole(RoleContext context) throws UserStoreException { Name compoundGroupName = ldapParser.parse("cn=" + roleName); groupContext.bind(compoundGroupName, null, groupAttributes); - } catch (NamingException e) { - String errorMsg = "Role: " + roleName + " could not be added."; - if (log.isDebugEnabled()) { - log.debug(errorMsg, e); - } - throw new UserStoreException(errorMsg, e); } catch (Exception e) { String errorMsg = "Role: " + roleName + " could not be added."; if (log.isDebugEnabled()) { @@ -1727,6 +1723,9 @@ private String resolveGroupDN(String searchFilter, String role, LDAPRoleContext return groupDN; } catch (NamingException e) { String errorMessage = "Error while resolving the GroupDN."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } throw new UserStoreException(errorMessage, e); } finally { JNDIUtil.closeContext(mainDirContext); @@ -1906,7 +1905,7 @@ protected void modifyUserInRole(String userNameDN, String groupRDN, int modifyTy throws UserStoreException { if (log.isDebugEnabled()) { - logger.debug("Modifying role: " + groupRDN + " with type: " + modifyType + " user: " + userNameDN + log.debug("Modifying role: " + groupRDN + " with type: " + modifyType + " user: " + userNameDN + " in search base: " + searchBase); } @@ -1923,7 +1922,7 @@ protected void modifyUserInRole(String userNameDN, String groupRDN, int modifyTy groupContext.modifyAttributes(groupRDN, modifyType, modifyingAttributes); if (log.isDebugEnabled()) { - logger.debug("User: " + userNameDN + " was successfully " + "modified in LDAP group: " + groupRDN); + log.debug("User: " + userNameDN + " was successfully " + "modified in LDAP group: " + groupRDN); } } catch (NamingException e) { String errorMessage = @@ -2342,36 +2341,41 @@ private void handleException(Exception e, String userName) throws UserStoreExcep if (e instanceof InvalidAttributeValueException) { String errorMessage = "One or more attribute values provided are incompatible for user : " + userName + "Please check and try again."; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof InvalidAttributeIdentifierException) { String errorMessage = "One or more attributes you are trying to add/update are not " + "supported by underlying LDAP for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof NoSuchAttributeException) { String errorMessage = "One or more attributes you are trying to add/update are not " + "supported by underlying LDAP for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof NamingException) { String errorMessage = "Profile information could not be updated in LDAP user store for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); } else if (e instanceof org.wso2.carbon.user.api.UserStoreException) { String errorMessage = "Error in obtaining claim mapping for user : " + userName; - if (logger.isDebugEnabled()) { - logger.debug(errorMessage, e); + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); } throw new UserStoreException(errorMessage, e); + } else { + String errorMessage = "Error while performing the operation with the user : " + userName + "."; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } } } @@ -2536,13 +2540,13 @@ protected void processAttributesBeforeUpdateWithID(String userID, String[] immutableAttributes = StringUtils.split(immutableAttributesProperty, ","); - if (logger.isDebugEnabled()) { - logger.debug("Retrieved user store properties for update: " + userStorePropertyValues); + if (log.isDebugEnabled()) { + log.debug("Retrieved user store properties for update: " + userStorePropertyValues); } if (ArrayUtils.isNotEmpty(immutableAttributes)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping Unique read only maintained default attributes: " + if (log.isDebugEnabled()) { + log.debug("Skipping Unique read only maintained default attributes: " + Arrays.toString(immutableAttributes)); }