From 7af8ecc68650fe0213190d6e3046bdae2fffc8d3 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 26 Jul 2016 11:59:10 +0530 Subject: [PATCH] Added userstore for role listing --- .../impl/RoleManagementServiceImpl.java | 20 +++++++++++++------ .../device/mgt/common/DeviceIdentifier.java | 2 +- ...ApplicationManagerProviderServiceImpl.java | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 4e788411e3..e0a832a77c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; import org.wso2.carbon.user.api.*; +import org.wso2.carbon.user.core.common.AbstractUserStoreManager; import org.wso2.carbon.user.mgt.UserRealmProxy; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UserAdminException; @@ -51,22 +52,29 @@ public class RoleManagementServiceImpl implements RoleManagementService { private static final String API_BASE_PATH = "/roles"; private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class); + private static final String PRIMARY_USER_STORE = "PRIMARY"; @GET @Override public Response getRoles( @QueryParam("filter") String filter, - @QueryParam("user-store") String userStoreName, + @QueryParam("user-store") String userStore, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { List filteredRoles; RoleList targetRoles = new RoleList(); + + //if user store is null set it to primary + if(userStore == null || "".equals(userStore)){ + userStore = PRIMARY_USER_STORE; + } + try { //Get the total role count that matches the given filter - filteredRoles = getRolesFromUserStore(filter); + filteredRoles = getRolesFromUserStore(filter, userStore); targetRoles.setCount(filteredRoles.size()); - filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter), offset, limit); + filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit); targetRoles.setList(filteredRoles); return Response.ok().entity(targetRoles).build(); @@ -343,14 +351,14 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } - private List getRolesFromUserStore(String filter) throws UserStoreException { - UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + private List getRolesFromUserStore(String filter, String userStore) throws UserStoreException { + AbstractUserStoreManager userStoreManager = (AbstractUserStoreManager) DeviceMgtAPIUtils.getUserStoreManager(); String[] roles; boolean filterRolesByName = (!((filter == null) || filter.isEmpty())); if (log.isDebugEnabled()) { log.debug("Getting the list of user roles"); } - roles = userStoreManager.getRoleNames(); + roles = userStoreManager.getRoleNames(userStore+"/*", -1, false, true, true); // removing all internal roles, roles created for Service-providers and application related roles. List filteredRoles = new ArrayList<>(); for (String role : roles) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 44219d31df..3a7f39b6e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -48,7 +48,7 @@ public class DeviceIdentifier implements Serializable{ } public void setType(String type) { - this.type = type; + this.type = type.toLowerCase(); } public String getId() { return id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index a33df19a41..18f61261f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -95,7 +95,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem //TODO: Fix this properly later adding device type to be passed in when the task manage executes "addOperations()" String type = null; if (deviceIds.size() > 0) { - type = deviceIds.get(0).getType(); + type = deviceIds.get(0).getType().toLowerCase(); } Activity activity = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). addOperation(type, operation, deviceIds);