Improve user application count logic
@@ -50,6 +50,7 @@ import java.util.regex.Pattern;
public class ApplicationManagementAdminService extends AbstractAdmin {
private static Log log = LogFactory.getLog(ApplicationManagementAdminService.class);
+ private static final String APPLICATION_ROLE_PREFIX = "Application/";
private ApplicationManagementService applicationMgtService;
private List<InboundAuthenticationRequestConfig> customInboundAuthenticatorConfigs;
@@ -323,7 +324,7 @@ public class ApplicationManagementAdminService extends AbstractAdmin {
@SuppressWarnings("ValidExternallyBoundObject")
public int getCountOfAllApplications() throws IdentityApplicationManagementException {
- int applicationCount = 0;
+ int applicationCount;
boolean validateRoles = ApplicationMgtUtil.validateRoles();
if (!validateRoles) {
if (log.isDebugEnabled()) {
@@ -336,15 +337,8 @@ public class ApplicationManagementAdminService extends AbstractAdmin {
/* Application role validation is enabled. Checking the
number of applications the user has access to, based
on the application role. */
- String applicationRolePrefix = "Application/";
List<String> applicationRoles = getApplicationRolesOfUser(getUsername());
- ApplicationBasicInfo[] applications = getAllApplicationBasicInfo();
-
- for (ApplicationBasicInfo applicationBasicInfo : applications) {
- if (applicationRoles.contains(applicationRolePrefix + applicationBasicInfo.getApplicationName())) {
- applicationCount += 1;
- }
- }
+ applicationCount = getSynchronizedApplicationCount(applicationRoles, null);
}
return applicationCount;
@@ -381,12 +375,41 @@ public class ApplicationManagementAdminService extends AbstractAdmin {
filteredApplicationRoles.add(applicationRole);
}
}
- applicationCount = filteredApplicationRoles.size();
+ applicationCount = getSynchronizedApplicationCount(filteredApplicationRoles, filter);
}
return applicationCount;
}
+ /**
+ * Retrieves the proper application count by considering both the application roles and the service providers/
+ * applications currently available.
+ *
+ * @param applicationRoles Filtered/unfiltered application roles assigned for the user.
+ * @param filter Filter provided to isolate service providers.
+ * @return Synchronized application count according to the user roles and the available service providers.
+ * @throws IdentityApplicationManagementException if there is an error while retrieving the basic info of all the
+ * applications/service providers.
+ */
+ private int getSynchronizedApplicationCount(List<String> applicationRoles, String filter)
+ throws IdentityApplicationManagementException {
+
+ int synchronizedApplicationCount = 0;
+ ApplicationBasicInfo[] applications;
+ if (filter == null) {
+ applications = getAllApplicationBasicInfo();
+ } else {
+ applications = getApplicationBasicInfo(filter);
+ }
+ for (ApplicationBasicInfo applicationBasicInfo : applications) {
+ if (applicationRoles.contains(APPLICATION_ROLE_PREFIX + applicationBasicInfo.getApplicationName())) {
+ synchronizedApplicationCount += 1;
+ }
+ }
+
+ return synchronizedApplicationCount;
+ }
+
/**
* Update application
*
