|
|
@ -19,7 +19,6 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
|
|
import org.apache.axis2.databinding.types.xsd._boolean;
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
import org.json.simple.JSONObject;
|
|
|
|
import org.json.simple.parser.JSONParser;
|
|
|
|
import org.json.simple.parser.JSONParser;
|
|
|
@ -110,8 +109,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@QueryParam("filter") String filter,
|
|
|
|
@QueryParam("filter") String filter,
|
|
|
|
@QueryParam("user-store") String userStore,
|
|
|
|
@QueryParam("user-store") String userStore,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
|
|
|
@QueryParam("offset") int offset, @QueryParam("limit") int limit,
|
|
|
|
@QueryParam("offset") int offset,
|
|
|
|
@QueryParam("username") String username, @QueryParam("domain") String domain,
|
|
|
|
@QueryParam("limit") int limit,
|
|
|
|
|
|
|
|
@QueryParam("username") String username,
|
|
|
|
|
|
|
|
@QueryParam("domain") String domain,
|
|
|
|
@PathParam("metaKey") String metaKey) {
|
|
|
|
@PathParam("metaKey") String metaKey) {
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
RequestValidationUtil.validatePaginationParameters(offset, limit);
|
|
|
|
if (limit == 0){
|
|
|
|
if (limit == 0){
|
|
|
@ -128,13 +129,13 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
String metaValue = metadata.getMetaValue();
|
|
|
|
String metaValue = metadata.getMetaValue();
|
|
|
|
JSONParser parser = new JSONParser();
|
|
|
|
JSONParser parser = new JSONParser();
|
|
|
|
JSONObject jsonObject = (JSONObject) parser.parse(metaValue);
|
|
|
|
JSONObject jsonObject = (JSONObject) parser.parse(metaValue);
|
|
|
|
boolean decision = (boolean) jsonObject.get("isUserAbleToViewAllRoles");
|
|
|
|
boolean decision = (boolean) jsonObject.get(Constants.IS_USER_ABLE_TO_VIEW_ALL_ROLES);
|
|
|
|
if (decision) {
|
|
|
|
if (decision) {
|
|
|
|
if(userStore == null || "".equals(userStore)){
|
|
|
|
if (userStore == null || "".equals(userStore)){
|
|
|
|
userStore = PRIMARY_USER_STORE;
|
|
|
|
userStore = PRIMARY_USER_STORE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
visibleRoles =getRolesFromUserStore(filter, userStore);
|
|
|
|
visibleRoles = getRolesFromUserStore(filter, userStore);
|
|
|
|
visibleRoleList.setList(visibleRoles);
|
|
|
|
visibleRoleList.setList(visibleRoles);
|
|
|
|
|
|
|
|
|
|
|
|
visibleRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit);
|
|
|
|
visibleRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit);
|
|
|
@ -148,7 +149,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try{UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
try {
|
|
|
|
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("User by username: " + username + " does not exist for role retrieval.");
|
|
|
|
log.debug("User by username: " + username + " does not exist for role retrieval.");
|
|
|
@ -159,7 +161,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
visibleRoleList.setList(getFilteredVisibleRoles(userStoreManager, username));
|
|
|
|
visibleRoleList.setList(getFilteredVisibleRoles(userStoreManager, username));
|
|
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(visibleRoleList).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(visibleRoleList).build();
|
|
|
|
}catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Error occurred while trying to retrieve roles of the user '" + username + "'";
|
|
|
|
String msg = "Error occurred while trying to retrieve roles of the user '" + username + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.serverError().entity(
|
|
|
|
return Response.serverError().entity(
|
|
|
@ -171,7 +173,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
} catch (ParseException e) {
|
|
|
|
} catch (ParseException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
String msg = "Error occurred while parsing JSON metadata: " + e.getMessage();
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|