Improve the implementation of isGroupsVsRolesSeparationImprovementsEnabled method
@@ -138,6 +138,7 @@ public class IdentityUtil {
public static final String PEM_END_CERTIFICATE = "-----END CERTIFICATE-----";
private static final String APPLICATION_DOMAIN = "Application";
private static final String WORKFLOW_DOMAIN = "Workflow";
+ private static Map<Integer, Boolean> groupsVsRolesSeparationImprovementsEnabled = new HashMap<>();
// System Property for trust managers.
public static final String PROP_TRUST_STORE_UPDATE_REQUIRED =
@@ -1434,21 +1435,47 @@ public class IdentityUtil {
public static boolean isGroupsVsRolesSeparationImprovementsEnabled() {
try {
- if (AdminServicesUtil.getUserRealm() == null) {
+ UserRealm userRealm = AdminServicesUtil.getUserRealm();
+ if (userRealm == null) {
log.warn("Unable to find the user realm, thus GroupAndRoleSeparationEnabled is set as FALSE.");
return Boolean.FALSE;
}
- diagnosticLog.info("'GroupAndRoleSeparationEnabled' property is set to: " +
- UserCoreUtil.isGroupsVsRolesSeparationImprovementsEnabled(AdminServicesUtil.getUserRealm()
- .getRealmConfiguration()));
- return UserCoreUtil.isGroupsVsRolesSeparationImprovementsEnabled(AdminServicesUtil.getUserRealm()
- .getRealmConfiguration());
- } catch (org.wso2.carbon.user.core.UserStoreException | CarbonException e) {
+ return getGroupsVsRolesSeparationImprovementsEnabled(userRealm.getRealmConfiguration());
+
+ } catch (CarbonException | UserStoreException e) {
log.warn("Property value parsing error: GroupAndRoleSeparationEnabled, thus considered as FALSE");
return Boolean.FALSE;
}
}
+ /**
+ * Get the groups vs roles separation config from groupsVsRolesSeparationImprovementsEnabled variable.
+ *
+ * @param realmConfig realmConfiguration.
+ * @return Where groups vs separation enabled or not.
+ */
+ private static boolean getGroupsVsRolesSeparationImprovementsEnabled(RealmConfiguration realmConfig) {
+
+ Boolean isEnabled = groupsVsRolesSeparationImprovementsEnabled.get(realmConfig.getTenantId());
+ if (isEnabled == null) {
+ isEnabled = setGroupsVsRolesSeparationImprovementsEnabled(realmConfig);
+ }
+ return isEnabled;
+ }
+
+ /**
+ * set the groups vs roles separation config to groupsVsRolesSeparationImprovementsEnabled variable.
+ *
+ * @param realmConfig realmConfiguration.
+ * @return Where groups vs separation enabled or not.
+ */
+ private static boolean setGroupsVsRolesSeparationImprovementsEnabled(RealmConfiguration realmConfig) {
+
+ boolean isEnabled = UserCoreUtil.isGroupsVsRolesSeparationImprovementsEnabled(realmConfig);
+ groupsVsRolesSeparationImprovementsEnabled.put(realmConfig.getTenantId(), isEnabled);
+ return isEnabled;
+ }
+
/**
* With group role separation, user roles are separated into groups and internal roles and, to support backward
* compatibility, the legacy wso2.role claim still returns both groups and internal roles. This method provides
