From 3d38c26b2d992e34c2ad7a7405aafcdd63cd2e0c Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 22 Mar 2024 15:33:39 +0530 Subject: [PATCH 01/13] Add recursive check in getUserCountByRole method. --- .../user/core/common/AbstractUserStoreManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 a5c3ddecd93..6adf97635fc 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 @@ -19223,6 +19223,16 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx return count; } + UserStore userStore = getUserStoreOfRoles(roleName); + + if (userStore.isRecurssive()) { + UserStoreManager resolvedUserStoreManager = userStore.getUserStoreManager(); + if (resolvedUserStoreManager instanceof AbstractUserStoreManager) { + return ((AbstractUserStoreManager) resolvedUserStoreManager) + .getUserCountByRole(userStore.getDomainFreeName(), filter); + } + } + if (readGroupsEnabled) { count += doGetUserCountOfRole(roleName, filter); } From 931c0663e3e4f0900606f6c6fe132a995cb6fa7b Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 22 Mar 2024 17:39:08 +0530 Subject: [PATCH 02/13] Add hybrid role check in getUserCountByRole method. --- .../core/common/AbstractUserStoreManager.java | 23 +++++++++++++ .../user/core/hybrid/HybridJDBCConstants.java | 3 ++ .../user/core/hybrid/HybridRoleManager.java | 32 +++++++++++++++++++ 3 files changed, 58 insertions(+) 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 6adf97635fc..8362f81a7bd 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 @@ -19233,6 +19233,29 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx } } + if (userStore.isHybridRole()) { + if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { + count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainFreeName()); + } else { + count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainAwareName()); + } + + // Get the users of associated groups of the role. + if (isRoleAndGroupSeparationEnabled()) { + String[] groupsOfRole; + if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { + groupsOfRole = hybridRoleManager.getGroupListOfHybridRole(userStore.getDomainFreeName()); + } else { + groupsOfRole = hybridRoleManager.getGroupListOfHybridRole(userStore.getDomainAwareName()); + } + for (String group : groupsOfRole) { + count += getUserCountByRole(group, filter); + } + } + + return count; + } + if (readGroupsEnabled) { count += doGetUserCountOfRole(roleName, filter); } diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java index 510fdef2d29..bf692cb38a4 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java @@ -136,6 +136,9 @@ public class HybridJDBCConstants { public static final String GET_USER_LIST_OF_ROLE_SQL = "SELECT UM_USER_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_USER_ROLE, UM_DOMAIN WHERE " + "UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=? " + "AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID"; + public static final String GET_USER_COUNT_OF_ROLE_SQL = "SELECT COUNT(UM_ID) FROM UM_HYBRID_USER_ROLE, UM_DOMAIN " + + "WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) " + + "AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=? AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID"; public static final String GET_GROUP_LIST_OF_ROLE_SQL = "SELECT UM_GROUP_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_GROUP_ROLE, UM_DOMAIN WHERE " diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java index eac2341a08d..5b71fc7d428 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java @@ -1551,4 +1551,36 @@ private boolean isTableExists(String tableName) { } return false; } + + /** + * Retrieve the number of users assigned to a role. + * + * @param roleName Given role. + * @return Number of users assigned to the given role. + * @throws UserStoreException An unexpected exception has occurred. + */ + public int getUserCountOfHybridRole(String roleName) throws UserStoreException { + + if (UserCoreUtil.isEveryoneRole(roleName, realmConfig)) { + return userRealm.getUserStoreManager().listUsers("*", -1).length; + } + + // ########### Domain-less Roles and Domain-aware Users from here onwards ############# + + String sqlStmt = HybridJDBCConstants.GET_USER_COUNT_OF_ROLE_SQL; + Connection dbConnection = null; + try { + dbConnection = DatabaseUtil.getDBConnection(dataSource); + return DatabaseUtil.getIntegerValueFromDatabase(dbConnection, sqlStmt, + roleName, tenantId, tenantId); + } catch (SQLException e) { + String errorMessage = "Error occurred while getting user list from hybrid role : " + roleName; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } + throw new UserStoreException(errorMessage, e); + } finally { + DatabaseUtil.closeAllConnections(dbConnection); + } + } } From 5a9d97a04769dd84737f255a0005a52e9feff50a Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 22 Mar 2024 17:40:18 +0530 Subject: [PATCH 03/13] Update comment --- .../wso2/carbon/user/core/common/AbstractUserStoreManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8362f81a7bd..2039cafbc1f 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 @@ -19240,7 +19240,7 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainAwareName()); } - // Get the users of associated groups of the role. + // Get the user count of associated groups of the role. if (isRoleAndGroupSeparationEnabled()) { String[] groupsOfRole; if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { From 7ca4d192d602f69e4da1bd3fbb228d1c847b3c3a Mon Sep 17 00:00:00 2001 From: dhaura Date: Mon, 25 Mar 2024 17:04:41 +0530 Subject: [PATCH 04/13] Add backward compatibility to retrieve user count when unique id feature is disabled. --- .../core/common/AbstractUserStoreManager.java | 26 ++++++- .../user/core/jdbc/JDBCRealmConstants.java | 7 +- .../user/core/jdbc/JDBCUserStoreManager.java | 67 +++++++++++++++++++ .../jdbc/UniqueIDJDBCUserStoreManager.java | 10 ++- .../carbon/user/core/util/JDBCRealmUtil.java | 8 ++- 5 files changed, 112 insertions(+), 6 deletions(-) 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 2039cafbc1f..116cd850f1a 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 @@ -9479,7 +9479,7 @@ protected List doGetUserListOfRoleWithID(String roleName, String filter) t } /** - * Return the count of users belong to the given role for the given filter. + * Return the count of users belong to the given role for the given filter when unique id feature is not enabled. * * @param roleName role name. * @param filter filter. @@ -9495,6 +9495,23 @@ protected int doGetUserCountOfRole(String roleName, String filter) throws UserSt "doGetUserCountOfRole operation is not implemented in: " + this.getClass()); } + /** + * Return the count of users belong to the given role for the given filter. + * + * @param roleName role name. + * @param filter filter. + * @return user count for the given role. + * @throws UserStoreException Thrown by the underlying UserStoreManager. + */ + protected int doGetUserCountOfRoleWithID(String roleName, String filter) throws UserStoreException { + + if (log.isDebugEnabled()) { + log.debug("doGetUserCountOfRoleWithID operation is not implemented in: " + this.getClass()); + } + throw new NotImplementedException( + "doGetUserCountOfRoleWithID operation is not implemented in: " + this.getClass()); + } + /** * Return the list of users belong to the given role for the given filter. * @@ -19257,7 +19274,12 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx } if (readGroupsEnabled) { - count += doGetUserCountOfRole(roleName, filter); + // If unique id feature is not enabled, we have to call the legacy methods. + if (!isUniqueUserIdEnabledInUserStore(userStore)) { + count += doGetUserCountOfRole(roleName, filter); + } else { + count += doGetUserCountOfRoleWithID(roleName, filter); + } } return count; diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java index 5f32db0413d..159433eafab 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java @@ -57,6 +57,7 @@ public final class JDBCRealmConstants { public static final String GET_USERS_IN_ROLE_FILTER = "GetUserListOfRoleFilterSQL"; public static final String GET_USERS_IN_ROLE_FILTER_WITH_ID = "GetUserListOfRoleFilterWithIDSQL"; public static final String GET_USERS_COUNT_WITH_FILTER_ROLE = "GetUserCountWithFilterRoleSQL"; + public static final String GET_USERS_COUNT_WITH_FILTER_ROLE_WITH_ID = "GetUserCountWithFilterRoleWithIDSQL"; public static final String GET_USERS_IN_SHARED_ROLE = "GetUserListOfSharedRoleSQL"; public static final String GET_USERS_IN_SHARED_ROLE_FILTER = "GetUserListOfSharedRoleFilterSQL"; public static final String GET_USERS_IN_SHARED_ROLE_FILTER_WITH_ID = "GetUserListOfSharedRoleFilterWithIDSQL"; @@ -270,7 +271,11 @@ public final class JDBCRealmConstants { + "UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE" + ".UM_TENANT_ID=? AND UM_USER.UM_TENANT_ID=?"; - public static final String GET_USERS_COUNT_WITH_FILTER_ROLE_SQL = "SELECT count(UM_ID) FROM UM_USER_ROLE " + + public static final String GET_USERS_COUNT_WITH_FILTER_ROLE_SQL = "SELECT COUNT(UM_USER_NAME) FROM " + + "UM_USER_ROLE, UM_ROLE, UM_USER WHERE UM_ROLE.UM_ROLE_NAME=? AND UM_USER.UM_ID=UM_USER_ROLE.UM_USER_ID " + + "AND UM_ROLE.UM_ID=UM_USER_ROLE.UM_ROLE_ID AND UM_USER_ROLE.UM_TENANT_ID=? AND UM_ROLE.UM_TENANT_ID=? " + + "AND UM_USER.UM_TENANT_ID=?"; + public static final String GET_USERS_COUNT_WITH_FILTER_ROLE_SQL_WITH_ID = "SELECT COUNT(UM_ID) FROM UM_USER_ROLE " + "WHERE UM_ROLE_ID = ? AND UM_TENANT_ID = ?"; public static final String GET_ROLE_ID_BY_NAME_SQL = "SELECT UM_ID FROM UM_ROLE " + 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 18b469c8f7b..7471d711d83 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 @@ -851,6 +851,12 @@ public String[] doGetUserListOfRole(String roleName, String filter) throws UserS return getUserListOfJDBCRole(roleContext, filter); } + public int doGetUserCountOfRole(String roleName, String filter) throws UserStoreException { + + RoleContext roleContext = createRoleContext(roleName); + return getUserCountByRole(roleContext, filter); + } + /** * */ @@ -934,6 +940,67 @@ public String[] getUserListOfJDBCRole(RoleContext ctx, String filter, int maxIte return names; } + /** + * Return the count of users belong to the given role for the given {@link RoleContext} and filter. + * + * @param ctx {@link RoleContext} corresponding to the role. + * @param filter String filter for the users. + * @throws UserStoreException If an unexpected error occurs. + */ + public int getUserCountByRole(RoleContext ctx, String filter) throws UserStoreException { + + String roleName = ctx.getRoleName(); + + if (StringUtils.isNotEmpty(filter)) { + filter = filter.trim(); + filter = filter.replace("*", "%"); + filter = filter.replace("?", "_"); + } else { + filter = "%"; + } + return getUserCountByRoleFromDatabase(roleName, filter); + } + + /** + * Return the count of users belong to the given role for the given {@link RoleContext} and filter. + * + * @param roleName Name of the role. + * @param filter String filter for the users. + * @return The count of users matching the provided constraints. + * @throws UserStoreException If an unexpected error occurs. + */ + private int getUserCountByRoleFromDatabase(String roleName, String filter) + throws UserStoreException { + + Connection dbConnection = null; + PreparedStatement prepStmt = null; + ResultSet rs = null; + int count = 0 ; + String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE); + try { + dbConnection = getDBConnection(); + prepStmt = dbConnection.prepareStatement(sqlStmt); + prepStmt.setString(1, roleName); + prepStmt.setInt(2, tenantId); + prepStmt.setInt(3, tenantId); + prepStmt.setInt(4, tenantId); + rs = prepStmt.executeQuery(); + while (rs.next()) { + count = rs.getInt(1); + } + return count; + } catch (SQLException e) { + String errorMessage = + "Error occurred while getting the count of users in the role : " + roleName; + if (log.isDebugEnabled()) { + log.debug(errorMessage, e); + } + throw new UserStoreException(errorMessage, e); + } finally { + DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); + } + } + /** * */ 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 16a26a6e0bf..fd36d59ea8a 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 @@ -352,7 +352,13 @@ public List doGetUserListOfRoleWithID(String roleName, String filter) thro } @Override - public int doGetUserCountOfRole(String roleName, String filter) + public int doGetUserCountOfRole(String roleName, String filter) throws UserStoreException { + + throw new UserStoreException("Operation is not supported."); + } + + @Override + public int doGetUserCountOfRoleWithID(String roleName, String filter) throws UserStoreException { RoleContext roleContext = createRoleContext(roleName); @@ -461,7 +467,7 @@ public int getUserCountByRoleFromDatabase(String roleName, String filter) PreparedStatement prepStmt = null; ResultSet rs = null; int count = 0 ; - String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE); + String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_WITH_ID); try { dbConnection = getDBConnection(); prepStmt = dbConnection.prepareStatement(sqlStmt); diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java index 7603468c133..15f18664765 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java @@ -536,7 +536,13 @@ public static Map getSQL(Map properties) { } if (!properties.containsKey(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE)) { - properties.put(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE, JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_SQL); + properties.put(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE, + JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_SQL); + } + + if (!properties.containsKey(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_WITH_ID)) { + properties.put(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_WITH_ID, + JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_SQL_WITH_ID); } if (!properties.containsKey(JDBCRealmConstants.GET_ROLE_ID_BY_NAME)) { From 0f80a5bd0339cd1b852d109e0f1e8e7e547e93dd Mon Sep 17 00:00:00 2001 From: dhaura Date: Mon, 25 Mar 2024 17:19:01 +0530 Subject: [PATCH 05/13] Add comment --- .../wso2/carbon/user/core/common/AbstractUserStoreManager.java | 2 ++ 1 file changed, 2 insertions(+) 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 116cd850f1a..1bf453f6519 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 @@ -19250,6 +19250,8 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx } } + // #################### Domain Name Free Zone Starts Here ################################ + if (userStore.isHybridRole()) { if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainFreeName()); From 5864c85154feaf5a05744203a9410b24179f23bc Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 26 Mar 2024 10:06:10 +0530 Subject: [PATCH 06/13] Remove unused filter param from role user count retrieval methods. --- .../core/common/AbstractUserStoreManager.java | 38 +++++++-------- .../user/core/jdbc/JDBCUserStoreManager.java | 47 +++---------------- .../jdbc/UniqueIDJDBCUserStoreManager.java | 34 +++----------- 3 files changed, 29 insertions(+), 90 deletions(-) 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 1bf453f6519..913ff077169 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 @@ -9482,11 +9482,10 @@ protected List doGetUserListOfRoleWithID(String roleName, String filter) t * Return the count of users belong to the given role for the given filter when unique id feature is not enabled. * * @param roleName role name. - * @param filter filter. * @return user count for the given role. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ - protected int doGetUserCountOfRole(String roleName, String filter) throws UserStoreException { + protected int doGetUserCountOfRole(String roleName) throws UserStoreException { if (log.isDebugEnabled()) { log.debug("doGetUserCountOfRole operation is not implemented in: " + this.getClass()); @@ -9499,11 +9498,10 @@ protected int doGetUserCountOfRole(String roleName, String filter) throws UserSt * Return the count of users belong to the given role for the given filter. * * @param roleName role name. - * @param filter filter. * @return user count for the given role. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ - protected int doGetUserCountOfRoleWithID(String roleName, String filter) throws UserStoreException { + protected int doGetUserCountOfRoleWithID(String roleName) throws UserStoreException { if (log.isDebugEnabled()) { log.debug("doGetUserCountOfRoleWithID operation is not implemented in: " + this.getClass()); @@ -19215,23 +19213,19 @@ public UserUniqueIDDomainResolver getUserUniqueIDDomainResolver() { return userUniqueIDDomainResolver; } - public int getUserCountForRole(String roleName) throws UserStoreException { - - if (!isSecureCall.get()) { - Class argTypes[] = new Class[] { String.class, String.class }; - Object object = callSecure("getUserCountByRole", new Object[] { roleName, QUERY_FILTER_STRING_ANY }, argTypes); - return (int) object; - } - - return getUserCountByRole(roleName, QUERY_FILTER_STRING_ANY); - } - - public int getUserCountByRole(String roleName, String filter) throws UserStoreException { + /** + * Retrieves the user count that belongs to a given role. + * + * @param roleName Name of the role. + * @return User count of the given role. + * @throws UserStoreException If an unexpected error occurs while accessing user store. + */ + public int getUserCountForRole(String roleName) throws UserStoreException { int count = 0; if (!isSecureCall.get()) { - Class argTypes[] = new Class[] { String.class, String.class }; - Object object = callSecure("getUserCountByRole", new Object[] { roleName, filter }, argTypes); + Class argTypes[] = new Class[] { String.class }; + Object object = callSecure("getUserCountForRole", new Object[] { roleName }, argTypes); return (int) object; } @@ -19246,7 +19240,7 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx UserStoreManager resolvedUserStoreManager = userStore.getUserStoreManager(); if (resolvedUserStoreManager instanceof AbstractUserStoreManager) { return ((AbstractUserStoreManager) resolvedUserStoreManager) - .getUserCountByRole(userStore.getDomainFreeName(), filter); + .getUserCountForRole(userStore.getDomainFreeName()); } } @@ -19268,7 +19262,7 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx groupsOfRole = hybridRoleManager.getGroupListOfHybridRole(userStore.getDomainAwareName()); } for (String group : groupsOfRole) { - count += getUserCountByRole(group, filter); + count += getUserCountForRole(group); } } @@ -19278,9 +19272,9 @@ public int getUserCountByRole(String roleName, String filter) throws UserStoreEx if (readGroupsEnabled) { // If unique id feature is not enabled, we have to call the legacy methods. if (!isUniqueUserIdEnabledInUserStore(userStore)) { - count += doGetUserCountOfRole(roleName, filter); + count += doGetUserCountOfRole(roleName); } else { - count += doGetUserCountOfRoleWithID(roleName, filter); + count += doGetUserCountOfRoleWithID(roleName); } } 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 7471d711d83..b5c15155baa 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 @@ -851,10 +851,11 @@ public String[] doGetUserListOfRole(String roleName, String filter) throws UserS return getUserListOfJDBCRole(roleContext, filter); } - public int doGetUserCountOfRole(String roleName, String filter) throws UserStoreException { + @Override + public int doGetUserCountOfRole(String roleName) throws UserStoreException { RoleContext roleContext = createRoleContext(roleName); - return getUserCountByRole(roleContext, filter); + return getUserCountByRole(roleContext); } /** @@ -944,51 +945,17 @@ public String[] getUserListOfJDBCRole(RoleContext ctx, String filter, int maxIte * Return the count of users belong to the given role for the given {@link RoleContext} and filter. * * @param ctx {@link RoleContext} corresponding to the role. - * @param filter String filter for the users. * @throws UserStoreException If an unexpected error occurs. */ - public int getUserCountByRole(RoleContext ctx, String filter) throws UserStoreException { + public int getUserCountByRole(RoleContext ctx) throws UserStoreException { String roleName = ctx.getRoleName(); - - if (StringUtils.isNotEmpty(filter)) { - filter = filter.trim(); - filter = filter.replace("*", "%"); - filter = filter.replace("?", "_"); - } else { - filter = "%"; - } - return getUserCountByRoleFromDatabase(roleName, filter); - } - - /** - * Return the count of users belong to the given role for the given {@link RoleContext} and filter. - * - * @param roleName Name of the role. - * @param filter String filter for the users. - * @return The count of users matching the provided constraints. - * @throws UserStoreException If an unexpected error occurs. - */ - private int getUserCountByRoleFromDatabase(String roleName, String filter) - throws UserStoreException { - Connection dbConnection = null; - PreparedStatement prepStmt = null; - ResultSet rs = null; - int count = 0 ; String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE); try { dbConnection = getDBConnection(); - prepStmt = dbConnection.prepareStatement(sqlStmt); - prepStmt.setString(1, roleName); - prepStmt.setInt(2, tenantId); - prepStmt.setInt(3, tenantId); - prepStmt.setInt(4, tenantId); - rs = prepStmt.executeQuery(); - while (rs.next()) { - count = rs.getInt(1); - } - return count; + return DatabaseUtil.getIntegerValueFromDatabase( + dbConnection, sqlStmt, roleName,tenantId, tenantId, tenantId); } catch (SQLException e) { String errorMessage = "Error occurred while getting the count of users in the role : " + roleName; @@ -997,7 +964,7 @@ private int getUserCountByRoleFromDatabase(String roleName, String filter) } throw new UserStoreException(errorMessage, e); } finally { - DatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt); + DatabaseUtil.closeAllConnections(dbConnection); } } 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 fd36d59ea8a..9b01a28d6ab 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 @@ -352,17 +352,17 @@ public List doGetUserListOfRoleWithID(String roleName, String filter) thro } @Override - public int doGetUserCountOfRole(String roleName, String filter) throws UserStoreException { + public int doGetUserCountOfRole(String roleName) throws UserStoreException { throw new UserStoreException("Operation is not supported."); } @Override - public int doGetUserCountOfRoleWithID(String roleName, String filter) + public int doGetUserCountOfRoleWithID(String roleName) throws UserStoreException { RoleContext roleContext = createRoleContext(roleName); - return getUserCountByRole(roleContext, filter); + return getUserCountByRole(roleContext); } public List getUserListOfJDBCRoleWithID(RoleContext ctx, String filter) throws UserStoreException { @@ -435,34 +435,12 @@ public List getUserListOfJDBCRoleWithID(RoleContext ctx, String filter, in * Return the count of users belong to the given role for the given {@link RoleContext} and filter. * * @param ctx {@link RoleContext} corresponding to the role. - * @param filter String filter for the users. + * @throws UserStoreException If an unexpected error occurs while accessing user store. */ - public int getUserCountByRole(RoleContext ctx, String filter) throws UserStoreException { + public int getUserCountByRole(RoleContext ctx) throws UserStoreException { String roleName = ctx.getRoleName(); - - if (StringUtils.isNotEmpty(filter)) { - filter = filter.trim(); - filter = filter.replace("*", "%"); - filter = filter.replace("?", "_"); - } else { - filter = "%"; - } - return getUserCountByRoleFromDatabase(roleName, filter); - } - - /** - * Return the count of users belong to the given role for the given {@link RoleContext} and filter. - * - * @param roleName Name of the role. - * @param filter String filter for the users. - * @return The count of users matching the provided constraints. - * @throws UserStoreException - */ - public int getUserCountByRoleFromDatabase(String roleName, String filter) - throws UserStoreException { - - String roleId = getRoleIdByName(roleName, tenantId); + String roleId = getRoleIdByName(ctx.getRoleName(), tenantId); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; From 0c5f520c32e28f41e9ac9f56ca509a3592d275f6 Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 26 Mar 2024 12:20:20 +0530 Subject: [PATCH 07/13] Add unit tests for methods related to get total user count for role. --- .../user/core/hybrid/HybridRoleManager.java | 5 ++--- .../user/core/hybrid/HybridRoleManagerTest.java | 6 ++++++ .../core/jdbc/JDBCRealmPrimaryUserStoreTest.java | 15 +++++++++++++++ .../jdbc/JDBCRealmSecondaryUserStoreTest.java | 15 +++++++++++++++ .../UniqueIDJDBCRealmPrimaryUserStoreTest.java | 15 +++++++++++++++ .../UniqueIDJDBCRealmSecondaryUserStoreTest.java | 15 +++++++++++++++ 6 files changed, 68 insertions(+), 3 deletions(-) diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java index 5b71fc7d428..dc2f2411fe4 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java @@ -1571,10 +1571,9 @@ public int getUserCountOfHybridRole(String roleName) throws UserStoreException { Connection dbConnection = null; try { dbConnection = DatabaseUtil.getDBConnection(dataSource); - return DatabaseUtil.getIntegerValueFromDatabase(dbConnection, sqlStmt, - roleName, tenantId, tenantId); + return DatabaseUtil.getIntegerValueFromDatabase(dbConnection, sqlStmt, roleName, tenantId, tenantId); } catch (SQLException e) { - String errorMessage = "Error occurred while getting user list from hybrid role : " + roleName; + String errorMessage = "Error occurred while getting user count from hybrid role : " + roleName; if (log.isDebugEnabled()) { log.debug(errorMessage, e); } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java index 595b124ec32..af311885378 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java @@ -105,6 +105,7 @@ private void doHybridRoleOperations() throws Exception { // Test add new internal role hybridRoleMan.addHybridRole("ThunderCats", null); assertTrue(hybridRoleMan.isExistingRole("ThunderCats")); + assertEquals(0, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); numberOfHybridRoles += 1; // Assign internal role to users @@ -125,15 +126,18 @@ private void doHybridRoleOperations() throws Exception { // Check whether users assigned to hybrid role assertEquals(3, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); + assertEquals(3, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Update users of hybrid role add/remove hybridRoleMan.updateUserListOfHybridRole("ThunderCats", new String[]{"Willykat", "Willykit"}, new String[]{"Snarf"}); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); + assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Update user with lower case remove user; entries should not delete as case sensitive hybridRoleMan.updateUserListOfHybridRole("ThunderCats", new String[]{"snarf"}, null); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); + assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Delete hybrid role hybridRoleMan.deleteHybridRole("ThunderCats"); @@ -142,6 +146,7 @@ private void doHybridRoleOperations() throws Exception { // Delete user with lower case; entries should not delete as case sensitive hybridRoleMan.deleteUser("lionel"); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("Friends").length); + assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("Friends")); // Change realm to pick CaseInSensitive User store configurations initRealmStuff(JDBC_TEST_CASE_INSENSITIVE_USERMGT_XML); @@ -149,5 +154,6 @@ private void doHybridRoleOperations() throws Exception { // Delete user with lower case; entries should not delete as case in-sensitive hybridRoleMan.deleteUser("lionel"); assertEquals(1, hybridRoleMan.getUserListOfHybridRole("Friends").length); + assertEquals(1, hybridRoleMan.getUserCountOfHybridRole("Friends")); } } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java index 5803bb9356d..45811c3c74d 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java @@ -644,4 +644,19 @@ public void test203DeleteUserWithID() throws UserStoreException { assertFalse(admin.getUserListOfRoleWithID(role).stream().map(User::getUserID).collect(Collectors.toList()).contains(userId1)); } } + + public void test204GetUserCountForRole() throws UserStoreException { + + // Add a new role + admin.addRole("userCountTestRole", null, null); + + // Add users more than max users per page (100) + for (int i=1; i <=150; i++) { + admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestRole"}, + null, null, false); + } + + // getUserCountForRole() method should return the total number of users of the given role + assertEquals(150, admin.getUserCountForRole("userCountTestRole")); + } } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java index 51bbdc5a2c6..c222cc693b2 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java @@ -436,6 +436,21 @@ public void test183AuthenticateWithID() throws UserStoreException { "pass2").getAuthenticationStatus()); } + public void test184GetUserCountForRole() throws UserStoreException { + + // Add a new role + admin.addRole("SECONDARYJDBC/userCountTestRole", null, null); + + // Add users more than max users per page (100) + for (int i=1; i <=150; i++) { + admin.addUser("SECONDARYJDBC/testUser" + i, "pass1", + new String[]{"SECONDARYJDBC/userCountTestRole"}, null, null, false); + } + + // getUserCountForRole() method should return the total number of users of the given role + assertEquals(150, admin.getUserCountForRole("SECONDARYJDBC/userCountTestRole")); + } + private void addSecondaryUserStoreManager(RealmConfiguration primaryRealm, AbstractUserStoreManager userStoreManager, UserRealm userRealm) throws Exception { diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java index ed5ce499f14..b884092b8c1 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java @@ -702,6 +702,21 @@ public void test205GetDisplayNameOfUser() throws UserStoreException { assertEquals("user6WithID$_USERNAME_SEPARATOR_$usergivenname2withId", username); } + public void test206GetUserCountForRole() throws UserStoreException { + + // Add a new role + admin.addRole("userCountTestRole", null, null); + + // Add users more than max users per page (100) + for (int i=1; i <=150; i++) { + admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestRole"}, + null, null, false); + } + + // getUserCountForRole() method should return the total number of users of the given role + assertEquals(150, admin.getUserCountForRole("userCountTestRole")); + } + private void clearUserIdResolverCache() { UserIdResolverCache.getInstance() diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java index 851b139799d..79ef048a2fe 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java @@ -727,6 +727,21 @@ public void test204GetDisplayNameOfUser() throws UserStoreException { assertEquals("SECONDARY/user6WithID$_USERNAME_SEPARATOR_$SECONDARY/usergivenname2withId", username); } + public void test205GetUserCountForRole() throws UserStoreException { + + // Add a new role + admin.addRole("SECONDARY/userCountTestRole", null, null); + + // Add users more than max users per page (100) + for (int i=1; i <=150; i++) { + admin.addUser("SECONDARY/testUser" + i, "pass1", + new String[]{"SECONDARY/userCountTestRole"}, null, null, false); + } + + // getUserCountForRole() method should return the total number of users of the given role + assertEquals(150, admin.getUserCountForRole("SECONDARY/userCountTestRole")); + } + private void addSecondaryUserStoreManager(RealmConfiguration primaryRealm, AbstractUserStoreManager userStoreManager, UserRealm userRealm, String dbUrl, String configFilePath, From 62e7020286dee7a9ab32af9680ca70d4d68856d0 Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 26 Mar 2024 12:29:04 +0530 Subject: [PATCH 08/13] Update Licenses. --- .../core/common/AbstractUserStoreManager.java | 12 ++++++------ .../user/core/jdbc/JDBCRealmConstants.java | 12 ++++++------ .../user/core/jdbc/JDBCUserStoreManager.java | 19 ++++++++++--------- .../jdbc/UniqueIDJDBCUserStoreManager.java | 6 +++--- .../carbon/user/core/util/JDBCRealmUtil.java | 18 ++++++++++-------- 5 files changed, 35 insertions(+), 32 deletions(-) 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 913ff077169..5dbd7ec2276 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 @@ -1,12 +1,12 @@ /* - * Copyright (c) (2005-2021), WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2005-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java index 159433eafab..c05a98ddbac 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/jdbc/JDBCRealmConstants.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2005-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an 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 b5c15155baa..fe89056fb46 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 @@ -1,18 +1,19 @@ /* -z * Copyright 2005-2007 WSO2, Inc. (http://wso2.com) + * Copyright (c) 2005-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS"//also need to clear role authorization - userRealm.getAuthorizationManager().cle BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.user.core.jdbc; 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 9b01a28d6ab..872abb12f49 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 @@ -1,7 +1,7 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at @@ -11,7 +11,7 @@ * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java index 15f18664765..148aae7931a 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/util/JDBCRealmUtil.java @@ -1,17 +1,19 @@ /* - * Copyright 2009-2010 WSO2, Inc. (http://wso2.com) + * Copyright (c) 2009-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.wso2.carbon.user.core.util; From a895fc6706f6bcb9da3b3770f75b4f275c7f6a8e Mon Sep 17 00:00:00 2001 From: Dhaura Pathirana <57411348+dhaura@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:24:00 +0530 Subject: [PATCH 09/13] Update core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/common/AbstractUserStoreManager.java Co-authored-by: Asha Sulaiman <165079T@uom.lk> --- .../wso2/carbon/user/core/common/AbstractUserStoreManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5dbd7ec2276..15dbe3af774 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 @@ -9495,7 +9495,7 @@ protected int doGetUserCountOfRole(String roleName) throws UserStoreException { } /** - * Return the count of users belong to the given role for the given filter. + * Return the count of users belong to the given role. * * @param roleName role name. * @return user count for the given role. From 5c6b7136bea283ca18a7f3b268774e6c702084b9 Mon Sep 17 00:00:00 2001 From: dhaura Date: Fri, 29 Mar 2024 14:32:22 +0530 Subject: [PATCH 10/13] Add getUserListOfGroupWithID method to retrieve user list only for groups. --- .../user/core/UniqueIDUserStoreManager.java | 19 +++ .../core/common/AbstractUserStoreManager.java | 108 +++++++++++++----- .../user/core/hybrid/HybridJDBCConstants.java | 3 - .../user/core/hybrid/HybridRoleManager.java | 31 ----- .../core/hybrid/HybridRoleManagerTest.java | 6 - .../jdbc/JDBCRealmPrimaryUserStoreTest.java | 38 +++++- .../jdbc/JDBCRealmSecondaryUserStoreTest.java | 38 +++++- ...UniqueIDJDBCRealmPrimaryUserStoreTest.java | 38 +++++- ...iqueIDJDBCRealmSecondaryUserStoreTest.java | 38 +++++- 9 files changed, 224 insertions(+), 95 deletions(-) diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java index 6a5afcdca21..2e58402714c 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java @@ -158,6 +158,25 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, */ List getUserListOfRoleWithID(String roleName, String filter, int maxItemLimit) throws UserStoreException; + + /** + * Get user list of group. + * + * @param groupName group name. + * @return An array of users that belongs to the given group. + * @throws UserStoreException Thrown by the underlying UserStoreManager. + */ + List getUserListOfGroupWithID(String groupName) throws UserStoreException; + + /** + * Get user list of group. + * + * @param groupName group name. + * @return An array of users that belongs to the given group. + * @throws UserStoreException Thrown by the underlying UserStoreManager. + */ + List getUserListOfGroupWithID(String groupName, String filter, int maxItemLimit) throws UserStoreException; + /** * Get user claim value in the profile. * 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 15dbe3af774..a3a60b0ea5d 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 @@ -12736,6 +12736,71 @@ public final List getUserListOfRoleWithID(String roleName, String filter, return users; } + @Override + public final List getUserListOfGroupWithID(String groupName) throws UserStoreException { + + if (!isSecureCall.get()) { + Class argTypes[] = new Class[] { String.class }; + Object object = callSecure("getUserListOfGroupWithID", new Object[] { groupName }, argTypes); + return (List) object; + } + + return getUserListOfGroupWithID(groupName, QUERY_FILTER_STRING_ANY, QUERY_MAX_ITEM_LIMIT_ANY); + } + + @Override + public final List getUserListOfGroupWithID(String groupName, String filter, int maxItemLimit) + throws UserStoreException { + + if (!isSecureCall.get()) { + Class argTypes[] = new Class[] { String.class, String.class, int.class }; + Object object = callSecure("getUserListOfGroupWithID", new Object[] { groupName, filter, maxItemLimit }, + argTypes); + return (List) object; + } + + List users = new ArrayList<>(); + + // If group does not exit, just return + if (!isExistingRole(groupName)) { + handleDoPostGetUserListOfRoleWithID(groupName, users); + return users; + } + + UserStore userStore = getUserStoreOfRoles(groupName); + + if (userStore.isRecurssive()) { + UserStoreManager resolvedUserStoreManager = userStore.getUserStoreManager(); + if (resolvedUserStoreManager instanceof AbstractUserStoreManager) { + return ((AbstractUserStoreManager) resolvedUserStoreManager) + .getUserListOfGroupWithID(userStore.getDomainFreeName(), filter, maxItemLimit); + } else { + return ((UniqueIDUserStoreManager) resolvedUserStoreManager) + .getUserListOfGroupWithID(userStore.getDomainFreeName()); + } + } + + // #################### Domain Name Free Zone Starts Here ################################ + + if (userStore.isSystemStore() || userStore.isHybridRole()) { + if (!isRoleAndGroupSeparationEnabled()) { + return getUserListOfRoleWithID(groupName, filter, maxItemLimit); + } + return users; + } + + if (readGroupsEnabled) { + // If unique id feature is not enabled, we have to call the legacy methods. + if (!isUniqueUserIdEnabledInUserStore(userStore)) { + users = userUniqueIDManger.listUsers(doGetUserListOfRole(groupName, filter, maxItemLimit), this); + } else { + users = doGetUserListOfRoleWithID(groupName, filter, maxItemLimit); + } + handleDoPostGetUserListOfRoleWithID(groupName, users); + } + return users; + } + @Override public final String getUserClaimValueWithID(String userID, String claim, String profileName) throws UserStoreException { @@ -19214,67 +19279,48 @@ public UserUniqueIDDomainResolver getUserUniqueIDDomainResolver() { } /** - * Retrieves the user count that belongs to a given role. + * Retrieves the user count that belongs to a given group. * - * @param roleName Name of the role. - * @return User count of the given role. + * @param groupName Name of the group. + * @return User count of the given group. * @throws UserStoreException If an unexpected error occurs while accessing user store. */ - public int getUserCountForRole(String roleName) throws UserStoreException { + public int getUserCountForGroup(String groupName) throws UserStoreException { int count = 0; if (!isSecureCall.get()) { Class argTypes[] = new Class[] { String.class }; - Object object = callSecure("getUserCountForRole", new Object[] { roleName }, argTypes); + Object object = callSecure("getUserCountForGroup", new Object[] { groupName }, argTypes); return (int) object; } - // If role does not exit, just return. - if (!isExistingRole(roleName)) { + // If group does not exit, just return. + if (!isExistingRole(groupName)) { return count; } - UserStore userStore = getUserStoreOfRoles(roleName); + UserStore userStore = getUserStoreOfRoles(groupName); if (userStore.isRecurssive()) { UserStoreManager resolvedUserStoreManager = userStore.getUserStoreManager(); if (resolvedUserStoreManager instanceof AbstractUserStoreManager) { return ((AbstractUserStoreManager) resolvedUserStoreManager) - .getUserCountForRole(userStore.getDomainFreeName()); + .getUserCountForGroup(userStore.getDomainFreeName()); } } // #################### Domain Name Free Zone Starts Here ################################ - if (userStore.isHybridRole()) { - if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { - count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainFreeName()); - } else { - count += hybridRoleManager.getUserCountOfHybridRole(userStore.getDomainAwareName()); - } - - // Get the user count of associated groups of the role. - if (isRoleAndGroupSeparationEnabled()) { - String[] groupsOfRole; - if (UserCoreConstants.INTERNAL_DOMAIN.equalsIgnoreCase(userStore.getDomainName())) { - groupsOfRole = hybridRoleManager.getGroupListOfHybridRole(userStore.getDomainFreeName()); - } else { - groupsOfRole = hybridRoleManager.getGroupListOfHybridRole(userStore.getDomainAwareName()); - } - for (String group : groupsOfRole) { - count += getUserCountForRole(group); - } - } - + if (userStore.isSystemStore() || userStore.isHybridRole()) { return count; } if (readGroupsEnabled) { // If unique id feature is not enabled, we have to call the legacy methods. if (!isUniqueUserIdEnabledInUserStore(userStore)) { - count += doGetUserCountOfRole(roleName); + count += doGetUserCountOfRole(groupName); } else { - count += doGetUserCountOfRoleWithID(roleName); + count += doGetUserCountOfRoleWithID(groupName); } } diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java index bf692cb38a4..510fdef2d29 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridJDBCConstants.java @@ -136,9 +136,6 @@ public class HybridJDBCConstants { public static final String GET_USER_LIST_OF_ROLE_SQL = "SELECT UM_USER_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_USER_ROLE, UM_DOMAIN WHERE " + "UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=? " + "AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID"; - public static final String GET_USER_COUNT_OF_ROLE_SQL = "SELECT COUNT(UM_ID) FROM UM_HYBRID_USER_ROLE, UM_DOMAIN " - + "WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=? AND UM_TENANT_ID=?) " - + "AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=? AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID"; public static final String GET_GROUP_LIST_OF_ROLE_SQL = "SELECT UM_GROUP_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_GROUP_ROLE, UM_DOMAIN WHERE " diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java index dc2f2411fe4..eac2341a08d 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/hybrid/HybridRoleManager.java @@ -1551,35 +1551,4 @@ private boolean isTableExists(String tableName) { } return false; } - - /** - * Retrieve the number of users assigned to a role. - * - * @param roleName Given role. - * @return Number of users assigned to the given role. - * @throws UserStoreException An unexpected exception has occurred. - */ - public int getUserCountOfHybridRole(String roleName) throws UserStoreException { - - if (UserCoreUtil.isEveryoneRole(roleName, realmConfig)) { - return userRealm.getUserStoreManager().listUsers("*", -1).length; - } - - // ########### Domain-less Roles and Domain-aware Users from here onwards ############# - - String sqlStmt = HybridJDBCConstants.GET_USER_COUNT_OF_ROLE_SQL; - Connection dbConnection = null; - try { - dbConnection = DatabaseUtil.getDBConnection(dataSource); - return DatabaseUtil.getIntegerValueFromDatabase(dbConnection, sqlStmt, roleName, tenantId, tenantId); - } catch (SQLException e) { - String errorMessage = "Error occurred while getting user count from hybrid role : " + roleName; - if (log.isDebugEnabled()) { - log.debug(errorMessage, e); - } - throw new UserStoreException(errorMessage, e); - } finally { - DatabaseUtil.closeAllConnections(dbConnection); - } - } } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java index af311885378..595b124ec32 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/hybrid/HybridRoleManagerTest.java @@ -105,7 +105,6 @@ private void doHybridRoleOperations() throws Exception { // Test add new internal role hybridRoleMan.addHybridRole("ThunderCats", null); assertTrue(hybridRoleMan.isExistingRole("ThunderCats")); - assertEquals(0, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); numberOfHybridRoles += 1; // Assign internal role to users @@ -126,18 +125,15 @@ private void doHybridRoleOperations() throws Exception { // Check whether users assigned to hybrid role assertEquals(3, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); - assertEquals(3, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Update users of hybrid role add/remove hybridRoleMan.updateUserListOfHybridRole("ThunderCats", new String[]{"Willykat", "Willykit"}, new String[]{"Snarf"}); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); - assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Update user with lower case remove user; entries should not delete as case sensitive hybridRoleMan.updateUserListOfHybridRole("ThunderCats", new String[]{"snarf"}, null); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("ThunderCats").length); - assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("ThunderCats")); // Delete hybrid role hybridRoleMan.deleteHybridRole("ThunderCats"); @@ -146,7 +142,6 @@ private void doHybridRoleOperations() throws Exception { // Delete user with lower case; entries should not delete as case sensitive hybridRoleMan.deleteUser("lionel"); assertEquals(2, hybridRoleMan.getUserListOfHybridRole("Friends").length); - assertEquals(2, hybridRoleMan.getUserCountOfHybridRole("Friends")); // Change realm to pick CaseInSensitive User store configurations initRealmStuff(JDBC_TEST_CASE_INSENSITIVE_USERMGT_XML); @@ -154,6 +149,5 @@ private void doHybridRoleOperations() throws Exception { // Delete user with lower case; entries should not delete as case in-sensitive hybridRoleMan.deleteUser("lionel"); assertEquals(1, hybridRoleMan.getUserListOfHybridRole("Friends").length); - assertEquals(1, hybridRoleMan.getUserCountOfHybridRole("Friends")); } } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java index 45811c3c74d..b8796429faa 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java @@ -645,18 +645,44 @@ public void test203DeleteUserWithID() throws UserStoreException { } } - public void test204GetUserCountForRole() throws UserStoreException { + public void test204GetUserListOfGroupWithID() throws UserStoreException { + + // Add new groups + admin.addRoleWithID("userListTestGroup1", null, null, false); + admin.addRoleWithID("userListTestGroup2", null, null, false); + admin.addRoleWithID("userListTestGroup3", null, null, false); + + // Add 10 users for "userListTestGroup1" group + for (int i=1; i <=10; i++) { + User user = admin.addUserWithID("testUser1WithID" + i, "pass1", + new String[]{"userListTestGroup1"}, null, null); + assertNotNull(user); + } + + // Add 20 users for "userListTestGroup2" group + for (int i=1; i <=20; i++) { + User user = admin.addUserWithID("testUser2WithID" + i, "pass1", + new String[]{"userListTestGroup2"}, null, null); + assertNotNull(user); + } + + // getUserListOfGroup() method should return users of the given group + assertEquals(10, admin.getUserListOfGroupWithID("userListTestGroup1").size()); + assertEquals(20, admin.getUserListOfGroupWithID("userListTestGroup2").size()); + } + + public void test205GetUserCountForGroup() throws UserStoreException { - // Add a new role - admin.addRole("userCountTestRole", null, null); + // Add a new group + admin.addRole("userCountTestGroup", null, null); // Add users more than max users per page (100) for (int i=1; i <=150; i++) { - admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestRole"}, + admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestGroup"}, null, null, false); } - // getUserCountForRole() method should return the total number of users of the given role - assertEquals(150, admin.getUserCountForRole("userCountTestRole")); + // getUserCountForGroup() method should return the total number of users of the given group + assertEquals(150, admin.getUserCountForGroup("userCountTestGroup")); } } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java index c222cc693b2..0865f162205 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java @@ -436,19 +436,45 @@ public void test183AuthenticateWithID() throws UserStoreException { "pass2").getAuthenticationStatus()); } - public void test184GetUserCountForRole() throws UserStoreException { + public void test184GetUserListOfGroupWithID() throws UserStoreException { + + // Add new groups + admin.addRoleWithID("SECONDARYJDBC/userListTestGroup1", null, null, false); + admin.addRoleWithID("SECONDARYJDBC/userListTestGroup2", null, null, false); + admin.addRoleWithID("SECONDARYJDBC/userListTestGroup3", null, null, false); + + // Add 10 users for "userListTestGroup1" group + for (int i=1; i <=10; i++) { + User user = admin.addUserWithID("SECONDARYJDBC/testUser1WithID" + i, "pass1", + new String[]{"SECONDARYJDBC/userListTestGroup1"}, null, null); + assertNotNull(user); + } + + // Add 20 users for "userListTestGroup2" group + for (int i=1; i <=20; i++) { + User user = admin.addUserWithID("SECONDARYJDBC/testUser2WithID" + i, "pass1", + new String[]{"SECONDARYJDBC/userListTestGroup2"}, null, null); + assertNotNull(user); + } + + // getUserListOfGroup() method should return users of the given group + assertEquals(10, admin.getUserListOfGroupWithID("SECONDARYJDBC/userListTestGroup1").size()); + assertEquals(20, admin.getUserListOfGroupWithID("SECONDARYJDBC/userListTestGroup2").size()); + } + + public void test185GetUserCountForGroup() throws UserStoreException { - // Add a new role - admin.addRole("SECONDARYJDBC/userCountTestRole", null, null); + // Add a new group + admin.addRole("SECONDARYJDBC/userCountTestGroup", null, null); // Add users more than max users per page (100) for (int i=1; i <=150; i++) { admin.addUser("SECONDARYJDBC/testUser" + i, "pass1", - new String[]{"SECONDARYJDBC/userCountTestRole"}, null, null, false); + new String[]{"SECONDARYJDBC/userCountTestGroup"}, null, null, false); } - // getUserCountForRole() method should return the total number of users of the given role - assertEquals(150, admin.getUserCountForRole("SECONDARYJDBC/userCountTestRole")); + // getUserCountForGroup() method should return the total number of users of the given group + assertEquals(150, admin.getUserCountForGroup("SECONDARYJDBC/userCountTestGroup")); } private void addSecondaryUserStoreManager(RealmConfiguration primaryRealm, diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java index b884092b8c1..f1cc4170d58 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java @@ -702,19 +702,45 @@ public void test205GetDisplayNameOfUser() throws UserStoreException { assertEquals("user6WithID$_USERNAME_SEPARATOR_$usergivenname2withId", username); } - public void test206GetUserCountForRole() throws UserStoreException { + public void test206GetUserListOfGroupWithID() throws UserStoreException { + + // Add new groups + admin.addRoleWithID("userListTestGroup1", null, null, false); + admin.addRoleWithID("userListTestGroup2", null, null, false); + admin.addRoleWithID("userListTestGroup3", null, null, false); + + // Add 10 users for "userListTestGroup1" group + for (int i=1; i <=10; i++) { + User user = admin.addUserWithID("testUser1WithID" + i, "pass1", + new String[]{"userListTestGroup1"}, null, null); + assertNotNull(user); + } + + // Add 20 users for "userListTestGroup2" group + for (int i=1; i <=20; i++) { + User user = admin.addUserWithID("testUser2WithID" + i, "pass1", + new String[]{"userListTestGroup2"}, null, null); + assertNotNull(user); + } + + // getUserListOfGroup() method should return users of the given group + assertEquals(10, admin.getUserListOfGroupWithID("userListTestGroup1").size()); + assertEquals(20, admin.getUserListOfGroupWithID("userListTestGroup2").size()); + } + + public void test207GetUserCountForGroup() throws UserStoreException { - // Add a new role - admin.addRole("userCountTestRole", null, null); + // Add a new group + admin.addRole("userCountTestGroup", null, null); // Add users more than max users per page (100) for (int i=1; i <=150; i++) { - admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestRole"}, + admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestGroup"}, null, null, false); } - // getUserCountForRole() method should return the total number of users of the given role - assertEquals(150, admin.getUserCountForRole("userCountTestRole")); + // getUserCountForGroup() method should return the total number of users of the given group + assertEquals(150, admin.getUserCountForGroup("userCountTestGroup")); } private void clearUserIdResolverCache() { diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java index 79ef048a2fe..75f23239910 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java @@ -727,19 +727,45 @@ public void test204GetDisplayNameOfUser() throws UserStoreException { assertEquals("SECONDARY/user6WithID$_USERNAME_SEPARATOR_$SECONDARY/usergivenname2withId", username); } - public void test205GetUserCountForRole() throws UserStoreException { + public void test205GetUserListOfGroupWithID() throws UserStoreException { + + // Add new groups + admin.addRoleWithID("SECONDARY/userListTestGroup1", null, null, false); + admin.addRoleWithID("SECONDARY/userListTestGroup2", null, null, false); + admin.addRoleWithID("SECONDARY/userListTestGroup3", null, null, false); + + // Add 10 users for "userListTestGroup1" group + for (int i=1; i <=10; i++) { + User user = admin.addUserWithID("SECONDARY/testUser1WithID" + i, "pass1", + new String[]{"SECONDARY/userListTestGroup1"}, null, null); + assertNotNull(user); + } + + // Add 20 users for "userListTestGroup2" group + for (int i=1; i <=20; i++) { + User user = admin.addUserWithID("SECONDARY/testUser2WithID" + i, "pass1", + new String[]{"SECONDARY/userListTestGroup2"}, null, null); + assertNotNull(user); + } + + // getUserListOfGroup() method should return users of the given group + assertEquals(10, admin.getUserListOfGroupWithID("SECONDARY/userListTestGroup1").size()); + assertEquals(20, admin.getUserListOfGroupWithID("SECONDARY/userListTestGroup2").size()); + } + + public void test206GetUserCountForGroup() throws UserStoreException { - // Add a new role - admin.addRole("SECONDARY/userCountTestRole", null, null); + // Add a new group + admin.addRole("SECONDARY/userCountTestGroup", null, null); // Add users more than max users per page (100) for (int i=1; i <=150; i++) { admin.addUser("SECONDARY/testUser" + i, "pass1", - new String[]{"SECONDARY/userCountTestRole"}, null, null, false); + new String[]{"SECONDARY/userCountTestGroup"}, null, null, false); } - // getUserCountForRole() method should return the total number of users of the given role - assertEquals(150, admin.getUserCountForRole("SECONDARY/userCountTestRole")); + // getUserCountForGroup() method should return the total number of users of the given group + assertEquals(150, admin.getUserCountForGroup("SECONDARY/userCountTestGroup")); } private void addSecondaryUserStoreManager(RealmConfiguration primaryRealm, From 0f69e2cc9a0270ca3f7cb1b0e2ba9a8316d15f88 Mon Sep 17 00:00:00 2001 From: dhaura Date: Mon, 1 Apr 2024 12:16:16 +0530 Subject: [PATCH 11/13] Add missing comments. --- .../carbon/user/core/UniqueIDUserStoreManager.java | 10 +++++----- .../user/core/common/AbstractUserStoreManager.java | 13 +++++++++++-- .../carbon/user/core/jdbc/JDBCUserStoreManager.java | 6 +++--- .../core/jdbc/UniqueIDJDBCUserStoreManager.java | 6 +++--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java index 2e58402714c..c4eee177266 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache License, + * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at @@ -11,7 +11,7 @@ * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -162,7 +162,7 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, /** * Get user list of group. * - * @param groupName group name. + * @param groupName Name of the group. * @return An array of users that belongs to the given group. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ @@ -171,7 +171,7 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, /** * Get user list of group. * - * @param groupName group name. + * @param groupName Name of the group. * @return An array of users that belongs to the given group. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ 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 a3a60b0ea5d..b9174c8282f 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 @@ -9497,8 +9497,8 @@ protected int doGetUserCountOfRole(String roleName) throws UserStoreException { /** * Return the count of users belong to the given role. * - * @param roleName role name. - * @return user count for the given role. + * @param roleName Name of the role. + * @return User count for the given role. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ protected int doGetUserCountOfRoleWithID(String roleName) throws UserStoreException { @@ -12783,9 +12783,12 @@ public final List getUserListOfGroupWithID(String groupName, String filter // #################### Domain Name Free Zone Starts Here ################################ if (userStore.isSystemStore() || userStore.isHybridRole()) { + // If the passed group is a role and if role, group separation is not enabled, + // call the user listing method for roles. if (!isRoleAndGroupSeparationEnabled()) { return getUserListOfRoleWithID(groupName, filter, maxItemLimit); } + // If the passed group is a role and if role, group separation is enabled, just return. return users; } @@ -19312,6 +19315,12 @@ public int getUserCountForGroup(String groupName) throws UserStoreException { // #################### Domain Name Free Zone Starts Here ################################ if (userStore.isSystemStore() || userStore.isHybridRole()) { + // If the passed group is a role and if role, group separation is not enabled, + // call the user listing method for roles. + if (!isRoleAndGroupSeparationEnabled()) { + return getUserListOfRoleWithID(groupName).size(); + } + // If the passed group is a role and if role, group separation is enabled, just return. return count; } 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 fe89056fb46..c774c41d984 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 @@ -943,10 +943,10 @@ public String[] getUserListOfJDBCRole(RoleContext ctx, String filter, int maxIte } /** - * Return the count of users belong to the given role for the given {@link RoleContext} and filter. + * Return the count of users belong to the given role for the given {@link RoleContext}. * - * @param ctx {@link RoleContext} corresponding to the role. - * @throws UserStoreException If an unexpected error occurs. + * @param ctx {@link RoleContext} corresponding to the role. + * @throws UserStoreException If an unexpected error occurs in user store. */ public int getUserCountByRole(RoleContext ctx) throws UserStoreException { 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 872abb12f49..c9f5cbf9ec4 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 @@ -432,10 +432,10 @@ public List getUserListOfJDBCRoleWithID(RoleContext ctx, String filter, in } /** - * Return the count of users belong to the given role for the given {@link RoleContext} and filter. + * Return the count of users belong to the given role for the given {@link RoleContext}. * - * @param ctx {@link RoleContext} corresponding to the role. - * @throws UserStoreException If an unexpected error occurs while accessing user store. + * @param ctx {@link RoleContext} corresponding to the role. + * @throws UserStoreException If an unexpected error occurs while accessing user store. */ public int getUserCountByRole(RoleContext ctx) throws UserStoreException { From d9ab31ab25d4af10cbfc123f81cf6cfa4499734f Mon Sep 17 00:00:00 2001 From: dhaura Date: Tue, 2 Apr 2024 13:11:20 +0530 Subject: [PATCH 12/13] Add default implementations to getUserListOfGroupWithID methods. --- .../carbon/user/core/UniqueIDUserStoreManager.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java index c4eee177266..9cdab21c6e9 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java @@ -166,7 +166,11 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, * @return An array of users that belongs to the given group. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ - List getUserListOfGroupWithID(String groupName) throws UserStoreException; + default List getUserListOfGroupWithID(String groupName) throws UserStoreException { + + throw new NotImplementedException( + "getUserListOfGroupWithID operation is not implemented in: " + this.getClass()); + } /** * Get user list of group. @@ -175,7 +179,12 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, * @return An array of users that belongs to the given group. * @throws UserStoreException Thrown by the underlying UserStoreManager. */ - List getUserListOfGroupWithID(String groupName, String filter, int maxItemLimit) throws UserStoreException; + default List getUserListOfGroupWithID(String groupName, String filter, int maxItemLimit) + throws UserStoreException { + + throw new NotImplementedException( + "getUserListOfGroupWithID operation is not implemented in: " + this.getClass()); + } /** * Get user claim value in the profile. From 986c45a1036b9b5a3bc2b3698e27d2f54650e3c7 Mon Sep 17 00:00:00 2001 From: dhaura Date: Wed, 3 Apr 2024 13:42:31 +0530 Subject: [PATCH 13/13] Fix formatting issues. --- .../user/core/UniqueIDUserStoreManager.java | 1 - .../core/common/AbstractUserStoreManager.java | 15 +++++++-------- .../user/core/jdbc/JDBCUserStoreManager.java | 2 +- .../core/jdbc/UniqueIDJDBCUserStoreManager.java | 8 ++++---- .../core/jdbc/JDBCRealmPrimaryUserStoreTest.java | 6 +++--- .../jdbc/JDBCRealmSecondaryUserStoreTest.java | 6 +++--- .../UniqueIDJDBCRealmPrimaryUserStoreTest.java | 6 +++--- .../UniqueIDJDBCRealmSecondaryUserStoreTest.java | 6 +++--- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java index 9cdab21c6e9..623af706e3e 100644 --- a/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java +++ b/core/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/UniqueIDUserStoreManager.java @@ -158,7 +158,6 @@ AuthenticationResult authenticateWithID(List loginIdentifiers, */ List getUserListOfRoleWithID(String roleName, String filter, int maxItemLimit) throws UserStoreException; - /** * Get user list of group. * 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 b9174c8282f..b788f3505af 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 @@ -9490,8 +9490,7 @@ protected int doGetUserCountOfRole(String roleName) throws UserStoreException { if (log.isDebugEnabled()) { log.debug("doGetUserCountOfRole operation is not implemented in: " + this.getClass()); } - throw new NotImplementedException( - "doGetUserCountOfRole operation is not implemented in: " + this.getClass()); + throw new NotImplementedException("doGetUserCountOfRole operation is not implemented in: " + this.getClass()); } /** @@ -12740,8 +12739,8 @@ public final List getUserListOfRoleWithID(String roleName, String filter, public final List getUserListOfGroupWithID(String groupName) throws UserStoreException { if (!isSecureCall.get()) { - Class argTypes[] = new Class[] { String.class }; - Object object = callSecure("getUserListOfGroupWithID", new Object[] { groupName }, argTypes); + Class argTypes[] = new Class[]{String.class}; + Object object = callSecure("getUserListOfGroupWithID", new Object[]{groupName}, argTypes); return (List) object; } @@ -12753,8 +12752,8 @@ public final List getUserListOfGroupWithID(String groupName, String filter throws UserStoreException { if (!isSecureCall.get()) { - Class argTypes[] = new Class[] { String.class, String.class, int.class }; - Object object = callSecure("getUserListOfGroupWithID", new Object[] { groupName, filter, maxItemLimit }, + Class argTypes[] = new Class[]{String.class, String.class, int.class}; + Object object = callSecure("getUserListOfGroupWithID", new Object[]{groupName, filter, maxItemLimit}, argTypes); return (List) object; } @@ -19292,8 +19291,8 @@ public int getUserCountForGroup(String groupName) throws UserStoreException { int count = 0; if (!isSecureCall.get()) { - Class argTypes[] = new Class[] { String.class }; - Object object = callSecure("getUserCountForGroup", new Object[] { groupName }, argTypes); + Class argTypes[] = new Class[]{String.class}; + Object object = callSecure("getUserCountForGroup", new Object[]{groupName}, argTypes); return (int) object; } 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 c774c41d984..9515e090b2f 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 @@ -956,7 +956,7 @@ public int getUserCountByRole(RoleContext ctx) throws UserStoreException { try { dbConnection = getDBConnection(); return DatabaseUtil.getIntegerValueFromDatabase( - dbConnection, sqlStmt, roleName,tenantId, tenantId, tenantId); + dbConnection, sqlStmt, roleName, tenantId, tenantId, tenantId); } catch (SQLException e) { String errorMessage = "Error occurred while getting the count of users in the role : " + roleName; 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 c9f5cbf9ec4..f3155e6a394 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 @@ -359,10 +359,10 @@ public int doGetUserCountOfRole(String roleName) throws UserStoreException { @Override public int doGetUserCountOfRoleWithID(String roleName) - throws UserStoreException { + throws UserStoreException { - RoleContext roleContext = createRoleContext(roleName); - return getUserCountByRole(roleContext); + RoleContext roleContext = createRoleContext(roleName); + return getUserCountByRole(roleContext); } public List getUserListOfJDBCRoleWithID(RoleContext ctx, String filter) throws UserStoreException { @@ -444,7 +444,7 @@ public int getUserCountByRole(RoleContext ctx) throws UserStoreException { Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; - int count = 0 ; + int count = 0; String sqlStmt = realmConfig.getUserStoreProperty(JDBCRealmConstants.GET_USERS_COUNT_WITH_FILTER_ROLE_WITH_ID); try { dbConnection = getDBConnection(); diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java index b8796429faa..9a0d608769e 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmPrimaryUserStoreTest.java @@ -653,14 +653,14 @@ public void test204GetUserListOfGroupWithID() throws UserStoreException { admin.addRoleWithID("userListTestGroup3", null, null, false); // Add 10 users for "userListTestGroup1" group - for (int i=1; i <=10; i++) { + for (int i = 1; i <= 10; i++) { User user = admin.addUserWithID("testUser1WithID" + i, "pass1", new String[]{"userListTestGroup1"}, null, null); assertNotNull(user); } // Add 20 users for "userListTestGroup2" group - for (int i=1; i <=20; i++) { + for (int i = 1; i <= 20; i++) { User user = admin.addUserWithID("testUser2WithID" + i, "pass1", new String[]{"userListTestGroup2"}, null, null); assertNotNull(user); @@ -677,7 +677,7 @@ public void test205GetUserCountForGroup() throws UserStoreException { admin.addRole("userCountTestGroup", null, null); // Add users more than max users per page (100) - for (int i=1; i <=150; i++) { + for (int i = 1; i <= 150; i++) { admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestGroup"}, null, null, false); } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java index 0865f162205..a9b0ebe003f 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/JDBCRealmSecondaryUserStoreTest.java @@ -444,14 +444,14 @@ public void test184GetUserListOfGroupWithID() throws UserStoreException { admin.addRoleWithID("SECONDARYJDBC/userListTestGroup3", null, null, false); // Add 10 users for "userListTestGroup1" group - for (int i=1; i <=10; i++) { + for (int i = 1; i <= 10; i++) { User user = admin.addUserWithID("SECONDARYJDBC/testUser1WithID" + i, "pass1", new String[]{"SECONDARYJDBC/userListTestGroup1"}, null, null); assertNotNull(user); } // Add 20 users for "userListTestGroup2" group - for (int i=1; i <=20; i++) { + for (int i = 1; i <= 20; i++) { User user = admin.addUserWithID("SECONDARYJDBC/testUser2WithID" + i, "pass1", new String[]{"SECONDARYJDBC/userListTestGroup2"}, null, null); assertNotNull(user); @@ -468,7 +468,7 @@ public void test185GetUserCountForGroup() throws UserStoreException { admin.addRole("SECONDARYJDBC/userCountTestGroup", null, null); // Add users more than max users per page (100) - for (int i=1; i <=150; i++) { + for (int i = 1; i <= 150; i++) { admin.addUser("SECONDARYJDBC/testUser" + i, "pass1", new String[]{"SECONDARYJDBC/userCountTestGroup"}, null, null, false); } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java index f1cc4170d58..c7338466b23 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmPrimaryUserStoreTest.java @@ -710,14 +710,14 @@ public void test206GetUserListOfGroupWithID() throws UserStoreException { admin.addRoleWithID("userListTestGroup3", null, null, false); // Add 10 users for "userListTestGroup1" group - for (int i=1; i <=10; i++) { + for (int i = 1; i <= 10; i++) { User user = admin.addUserWithID("testUser1WithID" + i, "pass1", new String[]{"userListTestGroup1"}, null, null); assertNotNull(user); } // Add 20 users for "userListTestGroup2" group - for (int i=1; i <=20; i++) { + for (int i = 1; i <= 20; i++) { User user = admin.addUserWithID("testUser2WithID" + i, "pass1", new String[]{"userListTestGroup2"}, null, null); assertNotNull(user); @@ -734,7 +734,7 @@ public void test207GetUserCountForGroup() throws UserStoreException { admin.addRole("userCountTestGroup", null, null); // Add users more than max users per page (100) - for (int i=1; i <=150; i++) { + for (int i = 1; i <= 150; i++) { admin.addUser("testUser" + i, "pass1", new String[]{"userCountTestGroup"}, null, null, false); } diff --git a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java index 75f23239910..8697ee61521 100644 --- a/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java +++ b/core/org.wso2.carbon.user.core/src/test/java/org/wso2/carbon/user/core/jdbc/UniqueIDJDBCRealmSecondaryUserStoreTest.java @@ -735,14 +735,14 @@ public void test205GetUserListOfGroupWithID() throws UserStoreException { admin.addRoleWithID("SECONDARY/userListTestGroup3", null, null, false); // Add 10 users for "userListTestGroup1" group - for (int i=1; i <=10; i++) { + for (int i = 1; i <= 10; i++) { User user = admin.addUserWithID("SECONDARY/testUser1WithID" + i, "pass1", new String[]{"SECONDARY/userListTestGroup1"}, null, null); assertNotNull(user); } // Add 20 users for "userListTestGroup2" group - for (int i=1; i <=20; i++) { + for (int i = 1; i <= 20; i++) { User user = admin.addUserWithID("SECONDARY/testUser2WithID" + i, "pass1", new String[]{"SECONDARY/userListTestGroup2"}, null, null); assertNotNull(user); @@ -759,7 +759,7 @@ public void test206GetUserCountForGroup() throws UserStoreException { admin.addRole("SECONDARY/userCountTestGroup", null, null); // Add users more than max users per page (100) - for (int i=1; i <=150; i++) { + for (int i = 1; i <= 150; i++) { admin.addUser("SECONDARY/testUser" + i, "pass1", new String[]{"SECONDARY/userCountTestGroup"}, null, null, false); }