Skip to content

Commit

Permalink
Merge pull request #3036 from bhagyasakalanka/4.7.x-bhagya
Browse files Browse the repository at this point in the history
Add methods to get userstore type is local or not
  • Loading branch information
ashensw committed Aug 6, 2021
2 parents 9326193 + bd36188 commit df1bcd0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,14 @@ void deleteUserClaimValues(String userName, String[] claims, String profileName)
*/
Properties getDefaultUserStoreProperties();

}
/**
* Get if the user store is a local user store or not. By default, this returns true.
*
* @return boolean - Is user store local or not.
*/
default boolean isLocalUserStore() {

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
*/
package org.wso2.carbon.user.core.tracker;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import org.wso2.carbon.user.api.Properties;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import org.wso2.carbon.user.core.internal.UserStoreMgtDSComponent;

Expand Down Expand Up @@ -111,4 +113,39 @@ public static Properties getUserStoreProperties(String className) {
properties = getUserStoreManagers().get(className);
return properties;
}

/**
* Get if the user store is local or not.
*
* @param className User store name.
* @return boolean true if user store is a local.
*/
public static boolean isLocalUserStore(String className) throws UserStoreException {

Object[] userStoreManagers = userStoreManagerTracker.getServices();
for (Object userStoreManagerObj : userStoreManagers) {
UserStoreManager userStoreManager = (UserStoreManager) userStoreManagerObj;
if (StringUtils.equals(className, userStoreManager.getClass().getName())) {
return userStoreManager.isLocalUserStore();
}
}
throw new UserStoreException(String.format("User store manager is not found for the given className: %s",
className));
}

/**
* Get all the available user store manager names and their type (local user store or not).
*
* @return Map<String, Boolean> Map of user store manager name and boolean indicating local or not.
*/
public static Map<String, Boolean> getUserStoreManagersType() {

Map<String, Boolean> userStoreManagersType = new HashMap<>();
Object[] userStoreManagers = userStoreManagerTracker.getServices();
for (Object userStoreManagerObj : userStoreManagers) {
boolean isLocalUserStore = ((UserStoreManager) userStoreManagerObj).isLocalUserStore();
userStoreManagersType.put(userStoreManagerObj.getClass().getName(), isLocalUserStore);
}
return userStoreManagersType;
}
}

0 comments on commit df1bcd0

Please sign in to comment.