|
|
@ -22,7 +22,10 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.CarbonConstants;
|
|
|
|
import org.wso2.carbon.base.MultitenantConstants;
|
|
|
|
import org.wso2.carbon.base.MultitenantConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer;
|
|
|
@ -57,12 +60,14 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
filteredRoles = getRolesFromUserStore();
|
|
|
|
filteredRoles = getRolesFromUserStore();
|
|
|
|
if (filteredRoles == null || filteredRoles.size() == 0) {
|
|
|
|
if (filteredRoles == null || filteredRoles.size() == 0) {
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("No roles found.").build();
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No roles found.").build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving roles from the underlying user stores";
|
|
|
|
String msg = "ErrorResponse occurred while retrieving roles from the underlying user stores";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(filteredRoles).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(filteredRoles).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,6 +78,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
public Response getPermissionsOfRole(
|
|
|
|
public Response getPermissionsOfRole(
|
|
|
|
@PathParam("roleName") String roleName,
|
|
|
|
@PathParam("roleName") String roleName,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleName);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
|
|
|
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
|
|
|
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
|
|
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
|
|
|
@ -83,19 +89,22 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
|
|
|
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
|
|
|
|
rolePermissions = this.getUIPermissionNode(roleName, userRealmProxy);
|
|
|
|
rolePermissions = this.getUIPermissionNode(roleName, userRealmProxy);
|
|
|
|
if (rolePermissions == null) {
|
|
|
|
if (rolePermissions == null) {
|
|
|
|
return Response.status(Response.Status.NOT_FOUND).entity("No permissions found for the role '" +
|
|
|
|
throw new NotFoundException(
|
|
|
|
roleName + "'").build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No permissions found" +
|
|
|
|
|
|
|
|
" for the role '" + roleName + "'").build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(rolePermissions).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(rolePermissions).build();
|
|
|
|
} catch (UserAdminException e) {
|
|
|
|
} catch (UserAdminException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the permissions of role '" + roleName + "'";
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the permissions of role '" + roleName + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the underlying user realm attached to the " +
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the underlying user realm attached to the " +
|
|
|
|
"current logged in user";
|
|
|
|
"current logged in user";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,6 +134,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getRole(@PathParam("roleName") String roleName,
|
|
|
|
public Response getRole(@PathParam("roleName") String roleName,
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleName);
|
|
|
|
RoleWrapper roleWrapper = new RoleWrapper();
|
|
|
|
RoleWrapper roleWrapper = new RoleWrapper();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
@ -148,11 +158,16 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
roleWrapper.setPermissionList(rolePermissions);
|
|
|
|
roleWrapper.setPermissionList(rolePermissions);
|
|
|
|
String[] permListAr = new String[permList.size()];
|
|
|
|
String[] permListAr = new String[permList.size()];
|
|
|
|
roleWrapper.setPermissions(permList.toArray(permListAr));
|
|
|
|
roleWrapper.setPermissions(permList.toArray(permListAr));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new NotFoundException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Role name doesn't exist.")
|
|
|
|
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UserStoreException | UserAdminException e) {
|
|
|
|
} catch (UserStoreException | UserAdminException e) {
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the user role '" + roleName + "'";
|
|
|
|
String msg = "ErrorResponse occurred while retrieving the user role '" + roleName + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).entity(roleWrapper).build();
|
|
|
|
return Response.status(Response.Status.OK).entity(roleWrapper).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -170,6 +185,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response addRole(RoleWrapper roleWrapper) {
|
|
|
|
public Response addRole(RoleWrapper roleWrapper) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleWrapper.getRoleName());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -188,7 +204,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while adding role '" + roleWrapper.getRoleName() + "'";
|
|
|
|
String msg = "ErrorResponse occurred while adding role '" + roleWrapper.getRoleName() + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -197,6 +214,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@Path("/{roleName}")
|
|
|
|
@Path("/{roleName}")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) {
|
|
|
|
public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleName);
|
|
|
|
String newRoleName = roleWrapper.getRoleName();
|
|
|
|
String newRoleName = roleWrapper.getRoleName();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
@ -230,7 +248,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while updating role '" + roleName + "'";
|
|
|
|
String msg = "ErrorResponse occurred while updating role '" + roleName + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -239,6 +258,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@Path("/{roleName}")
|
|
|
|
@Path("/{roleName}")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response deleteRole(@PathParam("roleName") String roleName) {
|
|
|
|
public Response deleteRole(@PathParam("roleName") String roleName) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleName);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
|
|
|
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
|
|
|
@ -251,7 +271,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while deleting the role '" + roleName + "'";
|
|
|
|
String msg = "ErrorResponse occurred while deleting the role '" + roleName + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -260,6 +281,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
@Path("/{roleName}/users")
|
|
|
|
@Path("/{roleName}/users")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) {
|
|
|
|
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateRoleName(roleName);
|
|
|
|
|
|
|
|
RequestValidationUtil.validateUsers(users);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -277,7 +300,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "ErrorResponse occurred while updating the users of the role '" + roleName + "'";
|
|
|
|
String msg = "ErrorResponse occurred while updating the users of the role '" + roleName + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
throw new UnexpectedServerErrorException(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
return Response.status(Response.Status.OK).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|