From bf821b23c809b9664f98a9e58b8ee4b7c21321d7 Mon Sep 17 00:00:00 2001 From: ChanikaRuchini Date: Tue, 5 Dec 2023 15:48:53 +0530 Subject: [PATCH] Improve getRoles of Role v2 management service --- .../DefaultRoleManagementListener.java | 20 +++--- .../v2/mgt/core/RoleManagementService.java | 33 +++++----- .../mgt/core/RoleManagementServiceImpl.java | 22 +++---- .../role/v2/mgt/core/dao/RoleDAO.java | 31 +++++----- .../role/v2/mgt/core/dao/RoleDAOImpl.java | 61 ++++++++++++++++--- .../AbstractRoleManagementListener.java | 4 +- .../core/listener/RoleManagementListener.java | 30 ++++----- .../role/v2/mgt/core/dao/RoleDAOTest.java | 16 ++--- 8 files changed, 135 insertions(+), 82 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/DefaultRoleManagementListener.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/DefaultRoleManagementListener.java index 53054659f8d8..6d981f2794f0 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/DefaultRoleManagementListener.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/DefaultRoleManagementListener.java @@ -108,19 +108,19 @@ public void preGetRoles(Integer limit, Integer offset, String sortBy, String sor } @Override - public void postGetRoles(List roleBasicInfoList, Integer limit, Integer offset, + public void postGetRoles(List roleInfoList, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException { - Iterator iterator = roleBasicInfoList.iterator(); + Iterator iterator = roleInfoList.iterator(); while (iterator.hasNext()) { - RoleBasicInfo roleBasicInfo = iterator.next(); - if (APPLICATION.equalsIgnoreCase(roleBasicInfo.getAudience())) { - String applicationName = getApplicationName(roleBasicInfo.getAudienceId(), tenantDomain); + Role roleInfo = iterator.next(); + if (APPLICATION.equalsIgnoreCase(roleInfo.getAudience())) { + String applicationName = getApplicationName(roleInfo.getAudienceId(), tenantDomain); if (applicationName == null) { iterator.remove(); } - roleBasicInfo.setAudienceName(applicationName); + roleInfo.setAudienceName(applicationName); } } } @@ -132,13 +132,13 @@ public void preGetRoles(String filter, Integer limit, Integer offset, String sor } @Override - public void postGetRoles(List roleBasicInfoList, String filter, Integer limit, Integer offset, + public void postGetRoles(List roleInfoList, String filter, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException { - for (RoleBasicInfo roleBasicInfo : roleBasicInfoList) { - if (APPLICATION.equalsIgnoreCase(roleBasicInfo.getAudience())) { - roleBasicInfo.setAudienceName(getApplicationName(roleBasicInfo.getAudienceId(), tenantDomain)); + for (Role roleInfo : roleInfoList) { + if (APPLICATION.equalsIgnoreCase(roleInfo.getAudience())) { + roleInfo.setAudienceName(getApplicationName(roleInfo.getAudienceId(), tenantDomain)); } } } diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementService.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementService.java index d5353030ce38..2497c78cba44 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementService.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementService.java @@ -55,32 +55,33 @@ RoleBasicInfo addRole(String roleName, List userList, List group /** * Retrieve available roles. * - * @param limit Limit value. - * @param offset Offset value. - * @param sortBy SortBy value. - * @param sortOrder Sort order value. - * @param tenantDomain Tenant domain. + * @param limit Limit value. + * @param offset Offset value. + * @param sortBy SortBy value. + * @param sortOrder Sort order value. + * @param tenantDomain Tenant domain. + * @param requiredAttributes Required attributes. * @return List of roles. * @throws IdentityRoleManagementException IdentityRoleManagementException. */ - List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) - throws IdentityRoleManagementException; + List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain, + List requiredAttributes) throws IdentityRoleManagementException; /** * Retrieve available roles. * - * @param filter Filter for the Role ID. - * @param limit Limit value. - * @param offset Offset value. - * @param sortBy SortBy value. - * @param sortOrder Sort order value. - * @param tenantDomain Tenant domain. + * @param filter Filter for the Role ID. + * @param limit Limit value. + * @param offset Offset value. + * @param sortBy SortBy value. + * @param sortOrder Sort order value. + * @param tenantDomain Tenant domain. + * @param requiredAttributes Required attributes. * @return List of roles. * @throws IdentityRoleManagementException IdentityRoleManagementException. */ - List getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, - String tenantDomain) - throws IdentityRoleManagementException; + List getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, + String tenantDomain, List requiredAttributes) throws IdentityRoleManagementException; /** * Retrieve the given role. diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java index 931fa1c3ea82..030e3505c08a 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java @@ -137,8 +137,8 @@ public RoleBasicInfo addRole(String roleName, List userList, List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, - String tenantDomain) throws IdentityRoleManagementException { + public List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain, + List requiredAttributes) throws IdentityRoleManagementException { List roleManagementListenerList = RoleManagementServiceComponentHolder.getInstance() .getRoleManagementListenerList(); @@ -151,23 +151,23 @@ public List getRoles(Integer limit, Integer offset, String sortBy .getInstance(); roleManagementEventPublisherProxy.publishPreGetRolesWithException(limit, offset, sortBy, sortOrder, tenantDomain); - List roleBasicInfoList = roleDAO.getRoles(limit, offset, sortBy, sortOrder, tenantDomain); + List roleList = roleDAO.getRoles(limit, offset, sortBy, sortOrder, tenantDomain, requiredAttributes); roleManagementEventPublisherProxy.publishPostGetRoles(limit, offset, sortBy, sortOrder, tenantDomain); for (RoleManagementListener roleManagementListener : roleManagementListenerList) { if (roleManagementListener.isEnable()) { - roleManagementListener.postGetRoles(roleBasicInfoList, limit, offset, sortBy, sortOrder, + roleManagementListener.postGetRoles(roleList, limit, offset, sortBy, sortOrder, tenantDomain); } } if (log.isDebugEnabled()) { log.debug(String.format("%s get roles successfully.", getUser(tenantDomain))); } - return roleBasicInfoList; + return roleList; } @Override - public List getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, - String tenantDomain) + public List getRoles(String filter, Integer limit, Integer offset, String sortBy, String sortOrder, + String tenantDomain, List requiredAttributes) throws IdentityRoleManagementException { List roleManagementListenerList = RoleManagementServiceComponentHolder.getInstance() @@ -182,19 +182,19 @@ public List getRoles(String filter, Integer limit, Integer offset roleManagementEventPublisherProxy.publishPreGetRolesWithException(filter, limit, offset, sortBy, sortOrder, tenantDomain); List expressionNodes = getExpressionNodes(filter); - List roleBasicInfoList = roleDAO.getRoles(expressionNodes, limit, offset, sortBy, - sortOrder, tenantDomain); + List roleInfoList = roleDAO.getRoles(expressionNodes, limit, offset, sortBy, + sortOrder, tenantDomain, requiredAttributes); roleManagementEventPublisherProxy.publishPostGetRoles(filter, limit, offset, sortBy, sortOrder, tenantDomain); for (RoleManagementListener roleManagementListener : roleManagementListenerList) { if (roleManagementListener.isEnable()) { - roleManagementListener.postGetRoles(roleBasicInfoList, filter, limit, offset, sortBy, sortOrder, + roleManagementListener.postGetRoles(roleInfoList, filter, limit, offset, sortBy, sortOrder, tenantDomain); } } if (log.isDebugEnabled()) { log.debug(String.format("%s get filtered roles successfully.", getUser(tenantDomain))); } - return roleBasicInfoList; + return roleInfoList; } @Override diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAO.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAO.java index ccb3bf9823d9..2eced18230d3 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAO.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAO.java @@ -56,31 +56,34 @@ RoleBasicInfo addRole(String roleName, List userList, List group /** * Retrieve available roles. * - * @param limit Limit value. - * @param offset Offset value. - * @param sortBy SortBy value. - * @param sortOrder Sort order value. - * @param tenantDomain Tenant domain. + * @param limit Limit value. + * @param offset Offset value. + * @param sortBy SortBy value. + * @param sortOrder Sort order value. + * @param tenantDomain Tenant domain. + * @param requiredAttributes Required attributes. * @return List of roles. * @throws IdentityRoleManagementException IdentityRoleManagementException. */ - List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) + List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain, + List requiredAttributes) throws IdentityRoleManagementException; /** * Retrieve available roles matching the provided filter. * - * @param expressionNodes List of expressionNodes. - * @param limit Limit value. - * @param offset Offset value. - * @param sortBy SortBy value. - * @param sortOrder Sort order value. - * @param tenantDomain Tenant domain. + * @param expressionNodes List of expressionNodes. + * @param limit Limit value. + * @param offset Offset value. + * @param sortBy SortBy value. + * @param sortOrder Sort order value. + * @param tenantDomain Tenant domain. + * @param requiredAttributes Required attributes. * @return List of roles. * @throws IdentityRoleManagementException IdentityRoleManagementException. */ - List getRoles(List expressionNodes, Integer limit, Integer offset, String sortBy, - String sortOrder, String tenantDomain) + List getRoles(List expressionNodes, Integer limit, Integer offset, String sortBy, + String sortOrder, String tenantDomain, List requiredAttributes) throws IdentityRoleManagementException; /** diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOImpl.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOImpl.java index 750a2cf9c7dd..764870a94e4f 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOImpl.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOImpl.java @@ -194,6 +194,10 @@ public class RoleDAOImpl implements RoleDAO { private final GroupIDResolver groupIDResolver = new GroupIDResolver(); private final UserIDResolver userIDResolver = new UserIDResolver(); private final Set systemRoles = getSystemRoles(); + private final String USERS = "users"; + private final String GROUPS = "groups"; + private final String PERMISSIONS = "permissions"; + private final String ASSOCIATED_APPLICATIONS = "associatedApplications"; @Override public RoleBasicInfo addRole(String roleName, List userList, List groupList, @@ -280,8 +284,8 @@ public RoleBasicInfo addRole(String roleName, List userList, List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, - String tenantDomain) throws IdentityRoleManagementException { + public List getRoles(Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain, + List requiredAttributes) throws IdentityRoleManagementException { int tenantId = IdentityTenantUtil.getTenantId(tenantDomain); limit = validateLimit(limit); @@ -300,12 +304,12 @@ public List getRoles(Integer limit, Integer offset, String sortBy throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), "Error while listing roles in tenantDomain: " + tenantDomain, e); } - return roles; + return getRolesRequestedAttributes(roles, requiredAttributes, tenantDomain); } @Override - public List getRoles(List expressionNodes, Integer limit, Integer offset, - String sortBy, String sortOrder, String tenantDomain) + public List getRoles(List expressionNodes, Integer limit, Integer offset, String sortBy, + String sortOrder, String tenantDomain, List requiredAttributes) throws IdentityRoleManagementException { int tenantId = IdentityTenantUtil.getTenantId(tenantDomain); @@ -335,7 +339,50 @@ public List getRoles(List expressionNodes, Intege throw new IdentityRoleManagementServerException(RoleConstants.Error.UNEXPECTED_SERVER_ERROR.getCode(), "Error while listing roles in tenantDomain: " + tenantDomain, e); } - return roles; + return getRolesRequestedAttributes(roles, requiredAttributes, tenantDomain); + } + + private List getRolesRequestedAttributes(List roles, List requiredAttributes, + String tenantDomain) + throws IdentityRoleManagementException { + + List rolesList = new ArrayList(); + for (RoleBasicInfo roleBasicInfo : roles) { + Role role = new Role(); + role.setId(roleBasicInfo.getId()); + role.setName(roleBasicInfo.getName()); + role.setAudienceId(roleBasicInfo.getAudienceId()); + role.setAudienceName(roleBasicInfo.getAudienceName()); + role.setAudience(roleBasicInfo.getAudience()); + if (requiredAttributes != null && !requiredAttributes.isEmpty()) { + if (requiredAttributes.contains(USERS)) { + role.setUsers(getUserListOfRole(roleBasicInfo.getId(), tenantDomain)); + } + if (requiredAttributes.contains(GROUPS)) { + role.setGroups(getGroupListOfRole(roleBasicInfo.getId(), tenantDomain)); + role.setIdpGroups(getIdpGroupListOfRole(roleBasicInfo.getId(), tenantDomain)); + } + if (requiredAttributes.contains(PERMISSIONS)) { + if (isSharedRole(roleBasicInfo.getId(), tenantDomain)) { + role.setPermissions(getPermissionsOfSharedRole(roleBasicInfo.getId(), tenantDomain)); + } else { + role.setPermissions(getPermissions(roleBasicInfo.getId(), tenantDomain)); + } + } + if (requiredAttributes.contains(ASSOCIATED_APPLICATIONS)) { + if (ORGANIZATION.equals(roleBasicInfo.getAudience())) { + role.setAssociatedApplications(getAssociatedAppsById(roleBasicInfo.getId(), tenantDomain)); + } else if (APPLICATION.equals(roleBasicInfo.getAudience())) { + List associatedApplications = new ArrayList<>(); + associatedApplications.add(new AssociatedApplication(roleBasicInfo.getAudienceId(), + roleBasicInfo.getAudienceName())); + role.setAssociatedApplications(associatedApplications); + } + } + } + rolesList.add(role); + } + return rolesList; } @Override @@ -3169,7 +3216,7 @@ private void deleteSharedHybridRoles(String roleId, int mainTenantId, Connection try (ResultSet resultSet = selectStatement.executeQuery()) { while (resultSet.next()) { idsToDelete.add(new AbstractMap.SimpleEntry<>( - resultSet.getInt(1), resultSet.getInt(2))); + resultSet.getInt(1), resultSet.getInt(2))); } } try (NamedPreparedStatement deleteStatement = new NamedPreparedStatement(connection, DELETE_SHARED_ROLE)) { diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/AbstractRoleManagementListener.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/AbstractRoleManagementListener.java index 6ec3a028214a..ee85e832f4f5 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/AbstractRoleManagementListener.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/AbstractRoleManagementListener.java @@ -54,7 +54,7 @@ public void preGetRoles(Integer limit, Integer offset, String sortBy, String sor } @Override - public void postGetRoles(List roleBasicInfoList, Integer limit, Integer offset, String sortBy, + public void postGetRoles(List roleBasicInfoList, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException { } @@ -66,7 +66,7 @@ public void preGetRoles(String filter, Integer limit, Integer offset, String sor } @Override - public void postGetRoles(List roleBasicInfoList, String filter, Integer limit, Integer offset, + public void postGetRoles(List roleInfoList, String filter, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException { diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/RoleManagementListener.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/RoleManagementListener.java index 65b3cf725955..27d138ce606f 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/RoleManagementListener.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/listener/RoleManagementListener.java @@ -105,15 +105,15 @@ void preGetRoles(Integer limit, Integer offset, String sortBy, String sortOrder, /** * Invoked after retrieving a list of roles based on specified criteria. * - * @param roleBasicInfoList The list of role basic info. - * @param limit The maximum number of roles to retrieve. - * @param offset The starting index from which to retrieve roles. - * @param sortBy The attribute by which the roles should be sorted (e.g., "name", "creationDate"). - * @param sortOrder The order in which to sort the roles. - * @param tenantDomain The domain in which the operation is being performed. + * @param roleInfoList The list of role basic info. + * @param limit The maximum number of roles to retrieve. + * @param offset The starting index from which to retrieve roles. + * @param sortBy The attribute by which the roles should be sorted (e.g., "name", "creationDate"). + * @param sortOrder The order in which to sort the roles. + * @param tenantDomain The domain in which the operation is being performed. * @throws IdentityRoleManagementException If an error occurs during the pre-retrieval phase. */ - void postGetRoles(List roleBasicInfoList, Integer limit, Integer offset, String sortBy, + void postGetRoles(List roleInfoList, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException; /** @@ -133,16 +133,16 @@ void preGetRoles(String filter, Integer limit, Integer offset, String sortBy, St /** * Invoked after retrieving a list of roles based on specified criteria. * - * @param roleBasicInfoList The list of role basic info. - * @param filter The filter value. - * @param limit The maximum number of roles to retrieve. - * @param offset The starting index from which to retrieve roles. - * @param sortBy The attribute by which the roles should be sorted (e.g., "name", "creationDate"). - * @param sortOrder The order in which to sort the roles. - * @param tenantDomain The domain in which the operation is being performed. + * @param roleInfoList The list of role basic info. + * @param filter The filter value. + * @param limit The maximum number of roles to retrieve. + * @param offset The starting index from which to retrieve roles. + * @param sortBy The attribute by which the roles should be sorted (e.g., "name", "creationDate"). + * @param sortOrder The order in which to sort the roles. + * @param tenantDomain The domain in which the operation is being performed. * @throws IdentityRoleManagementException If an error occurs during the pre-retrieval phase. */ - void postGetRoles(List roleBasicInfoList, String filter, Integer limit, Integer offset, + void postGetRoles(List roleInfoList, String filter, Integer limit, Integer offset, String sortBy, String sortOrder, String tenantDomain) throws IdentityRoleManagementException; /** diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/test/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOTest.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/test/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOTest.java index 4ceac6372c5b..8349c1978db6 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/test/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOTest.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/test/java/org/wso2/carbon/identity/role/v2/mgt/core/dao/RoleDAOTest.java @@ -43,6 +43,7 @@ import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; import org.wso2.carbon.identity.role.v2.mgt.core.model.IdpGroup; import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission; +import org.wso2.carbon.identity.role.v2.mgt.core.model.Role; import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleAudience; import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo; import org.wso2.carbon.user.api.AuthorizationManager; @@ -280,8 +281,8 @@ public void testGetRoles() throws Exception { when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection8); doCallRealMethod().when(IdentityUtil.class, "extractDomainFromName", anyString()); doCallRealMethod().when(UserCoreUtil.class, "removeDomainFromName", anyString()); - List roles = roleDAO.getRoles(2, 1, null, null, - SAMPLE_TENANT_DOMAIN); + List roles = roleDAO.getRoles(2, 1, null, null, + SAMPLE_TENANT_DOMAIN, null); Assert.assertEquals(getRoleNamesList(roles), expectedRoles); } } @@ -317,15 +318,16 @@ public void testGetRolesWithFilter() throws Exception { when(UserCoreUtil.isEveryoneRole(anyString(), any(RealmConfiguration.class))).thenReturn(false); when(IdentityUtil.getDefaultItemsPerPage()).thenReturn(IdentityCoreConstants.DEFAULT_ITEMS_PRE_PAGE); - when(IdentityUtil.getMaximumItemPerPage()).thenReturn(IdentityCoreConstants.DEFAULT_MAXIMUM_ITEMS_PRE_PAGE); + when(IdentityUtil.getMaximumItemPerPage()). + thenReturn(IdentityCoreConstants.DEFAULT_MAXIMUM_ITEMS_PRE_PAGE); when(IdentityDatabaseUtil.getUserDBConnection(anyBoolean())).thenReturn(connection7); when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection8); doCallRealMethod().when(IdentityUtil.class, "extractDomainFromName", anyString()); doCallRealMethod().when(UserCoreUtil.class, "removeDomainFromName", anyString()); List expressionNodes = getExpressionNodes("name co roleA and audience co application and audienceId co test-app-id"); - List roles = roleDAO.getRoles(expressionNodes, 2, 1, null, null, - SAMPLE_TENANT_DOMAIN); + List roles = roleDAO.getRoles(expressionNodes, 2, 1, null, null, + SAMPLE_TENANT_DOMAIN, null); Assert.assertEquals(getRoleNamesList(roles), expectedRoles); } } @@ -801,10 +803,10 @@ private void mockRealmConfiguration() throws UserStoreException { when(mockUserRealm.getRealmConfiguration()).thenReturn(realmConfiguration); } - private List getRoleNamesList(List roles) { + private List getRoleNamesList(List roles) { List roleNames = new ArrayList<>(); - for (RoleBasicInfo role : roles) { + for (Role role : roles) { roleNames.add(role.getName()); } return roleNames.stream().sorted().collect(Collectors.toList());