Merge branch 'rest-api-improvements' of https://github.com/wso2/carbon-device-mgt into rest-api-improvements

merge-requests/7/head
hasuniea 9 years ago
commit dc72fd1553

@ -76,9 +76,13 @@ public interface ActivityInfoProviderService {
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = ". \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n No activity is found under the provided id."),
message = "Not Found. \n No activity is found under the provided id.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ -131,6 +135,10 @@ public interface ActivityInfoProviderService {
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n No activities found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),

@ -78,13 +78,24 @@ public interface DeviceManagementService {
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 400,
message = "The incoming request has more than one selection criteria defined through query" +
" parameters.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "No device is currently enrolled with the server.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class)
})
@Permission(scope = "device-list", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevices(
@ -170,10 +181,12 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id."),
message = "Not Found. \n No device is found under the provided type and id.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ -243,14 +256,20 @@ public interface DeviceManagementService {
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device information is available for the device list submitted.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while retrieving information of the list of the devices submitted.")
message = "Internal Server ErrorResponse. Server error occurred while retrieving " +
"information of the list of the devices submitted.",
response = ErrorResponse.class)
})
@Permission(scope = "device-info", permissions = {"/permission/admin/device-mgt/admin/devices/list"})
Response getDevicesInfo(
@ -294,11 +313,16 @@ public interface DeviceManagementService {
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
message = "Not Modified. Empty body because the client already has the latest " +
"version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id."),
message = "Not Found. \n No device is found under the provided type and id.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
@ -345,9 +369,14 @@ public interface DeviceManagementService {
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No device is found under the provided type and id."),
message = "Not Found. \n No device is found under the provided type and id.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse occurred while getting the device location.",
@ -393,9 +422,14 @@ public interface DeviceManagementService {
code = 304,
message = "Not Modified. \n " +
"Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Location details are not available for the given devices."),
message = "Location details are not available for the given devices.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse occurred while getting the device location.",
@ -461,7 +495,8 @@ public interface DeviceManagementService {
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the feature list is requested, is not found."),
message = "Not Found. \n Device of which the feature list is requested, is not found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ -527,6 +562,11 @@ public interface DeviceManagementService {
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Acceptable.\n TIt is likely that no device is found upon the " +
"provided filters",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ -602,7 +642,8 @@ public interface DeviceManagementService {
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the application list is requested, is not found."),
message = "Not Found. \n Device of which the application list is requested, is not found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ -690,7 +731,8 @@ public interface DeviceManagementService {
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the operation list is requested, is not found."),
message = "Not Found. \n Device of which the operation list is requested, is not found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),
@ -777,7 +819,8 @@ public interface DeviceManagementService {
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Device of which the effective policy is requested, is not found."),
message = "Not Found. \n Device of which the effective policy is requested, is not found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable. \n The requested media type is not supported."),

@ -71,6 +71,15 @@ public interface NotificationManagementService {
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid notification status type " +
"received. Valid status types are NEW | CHECKED",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n No notification is available to be retrieved.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.policy.mgt.common.Policy;
@ -66,7 +67,8 @@ public interface PolicyManagementService {
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
"Used by caches, or in conditional requests.")
}),
@ApiResponse(
code = 303,
message = "See Other. \n Source can be retrieved from the URL specified at the Location header.",
@ -76,14 +78,21 @@ public interface PolicyManagementService {
description = "The Source URL of the document.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 401,
message = "Not Found. \n Current logged in user is not authorized to add policies.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new policy.")})
"Server error occurred while adding a new policy.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/add"})
Response addPolicy(
@ApiParam(
@ -123,12 +132,18 @@ public interface PolicyManagementService {
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching policies.")
message = ("Internal Server ErrorResponse. \n Server error occurred while fetching " +
"policies."),
response = ErrorResponse.class)
})
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicies(
@ -181,13 +196,17 @@ public interface PolicyManagementService {
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n No policy is found with the given id."),
message = "Not Found. \n No policy is found with the given id.",
response = ErrorResponse.class
),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the policy.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the " +
"policy.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-view", permissions = {"/permission/admin/device-mgt/admin/policies/list"})
Response getPolicy(
@ -234,17 +253,20 @@ public interface PolicyManagementService {
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource to be deleted does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the policy.")
"Server error occurred while updating the policy.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/update"})
Response updatePolicy(
@ -273,17 +295,20 @@ public interface PolicyManagementService {
message = "OK. \n Policies have successfully been removed"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource to be deleted does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while bulk removing policies.")
"Server error occurred while bulk removing policies.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {"/permission/admin/device-mgt/admin/policies/remove"})
Response removePolicies(
@ -304,8 +329,21 @@ public interface PolicyManagementService {
tags = "Device Policy Management")
@ApiResponses(
value = {
@ApiResponse(code = 200, message = "Policies have been successfully activated."),
@ApiResponse(code = 500, message = "ErrorResponse in activating policies.")
@ApiResponse(
code = 200,
message = "Policies have been successfully activated."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse in activating policies.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update",
@ -325,8 +363,21 @@ public interface PolicyManagementService {
"is in the active state to the inactive state.",
tags = "Device Policy Management")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Policies have been successfully deactivated."),
@ApiResponse(code = 500, message = "ErrorResponse in deactivating policies.")
@ApiResponse(
code = 200,
message = "Policies have been successfully deactivated."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "ErrorResponse in deactivating policies.",
response = ErrorResponse.class)
})
@Permission(scope = "policy-modify", permissions = {
"/permission/admin/device-mgt/admin/policies/update",

@ -70,6 +70,10 @@ public interface RoleManagementService {
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ -147,9 +151,14 @@ public interface RoleManagementService {
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ -201,16 +210,23 @@ public interface RoleManagementService {
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
message = "Not Modified. \n Empty body because the client has already the latest version of" +
" the requested resource."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the requested role.",
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the " +
"requested role.",
response = ErrorResponse.class)
})
@Permission(scope = "roles-view", permissions = {"/permission/admin/device-mgt/admin/roles/list"})
@ -349,6 +365,10 @@ public interface RoleManagementService {
@ApiResponse(
code = 200,
message = "OK. \n Role has successfully been removed"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
@ -76,13 +77,18 @@ public interface UserManagementService {
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 409,
message = "Conflict. \n User already exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while adding a new user.")
"Server error occurred while adding a new user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/add"})
Response addUser(
@ -124,13 +130,16 @@ public interface UserManagementService {
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the requested user.")
message = "Internal Server ErrorResponse. \n Server error occurred while" +
" fetching the requested user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getUser(
@ -179,14 +188,16 @@ public interface UserManagementService {
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating the user.")
"Server error occurred while updating the user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/update"})
Response updateUser(
@ -214,11 +225,14 @@ public interface UserManagementService {
message = "OK. \n User has successfully been removed"),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource to be deleted does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while removing the user.")
"Server error occurred while removing the user.",
response = ErrorResponse.class
)
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/device-mgt/admin/user/remove"})
Response removeUser(
@ -260,13 +274,16 @@ public interface UserManagementService {
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
message = "Not Found. \n Resource to be deleted does not exist.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the role list assigned to the user.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the role list" +
" assigned to the user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/view"})
Response getRolesOfUser(
@ -310,7 +327,8 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the user list.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the user list.",
response = ErrorResponse.class)
})
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUsers(
@ -376,7 +394,9 @@ public interface UserManagementService {
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the username list that matches the given filter.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the username " +
"list that matches the given filter.",
response = ErrorResponse.class)
})
@Permission(scope = "user-view", permissions = {"/permission/admin/device-mgt/admin/user/list"})
Response getUserNames(
@ -416,7 +436,8 @@ public interface UserManagementService {
message = "OK. \n Credentials of the user have been updated successfully"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ -426,7 +447,8 @@ public interface UserManagementService {
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.")
"Server error occurred while updating credentials of the user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetPassword(

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -64,16 +65,23 @@ public interface DeviceManagementAdminService {
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 401,
message = "Unauthorized.\n The requested resource access is unauthorized"),
message = "Unauthorized.\n The requested resource access is unauthorized",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found.\n No device found that matches the given name.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.")
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the device list.",
response = ErrorResponse.class)
})
Response getDevicesByName(
@ApiParam(

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper;
import javax.ws.rs.*;
@ -49,7 +50,8 @@ public interface UserManagementAdminService {
message = "OK. \n Credentials of the user have been updated successfully"),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ -59,7 +61,8 @@ public interface UserManagementAdminService {
@ApiResponse(
code = 500,
message = "Internal Server ErrorResponse. \n " +
"Server error occurred while updating credentials of the user.")
"Server error occurred while updating credentials of the user.",
response = ErrorResponse.class)
})
@Permission(scope = "user-modify", permissions = {"/permission/admin/login"})
Response resetUserPassword(

@ -25,8 +25,8 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementExcept
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.ActivityInfoProviderService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
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 javax.ws.rs.*;
@ -55,8 +55,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activity = dmService.getOperationByActivityId(id);
if (activity == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No activity can be found upon the provided " +
"activity id '" + id + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activity can be " +
"found upon the provided activity id '" + id + "'").build());
}
} catch (OperationManagementException e) {
String msg = "ErrorResponse occurred while fetching the activity for the supplied id.";
@ -78,6 +79,11 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(timestamp);
if (activities == null || activities.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No activities " +
"found.").build());
}
} catch (OperationManagementException e) {
String msg = "ErrorResponse occurred while fetching the activities updated after given time stamp.";

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManageme
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.ConfigurationManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.MDMAppConstants;
@ -74,6 +75,7 @@ public class ConfigurationServiceImpl implements ConfigurationManagementService
@Override
public Response updateConfiguration(PlatformConfiguration config) {
try {
RequestValidationUtil.validateUpdateConfiguration(config);
DeviceMgtAPIUtils.getPlatformConfigurationManagementService().saveConfiguration(config,
MDMAppConstants.RegistryConstants.GENERAL_CONFIG_RESOURCE_PATH);
//Schedule the task service

@ -38,8 +38,8 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
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.policy.mgt.common.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
@ -94,8 +94,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
result = dms.getAllDevices(request);
}
if (result == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device is currently enrolled " +
"with the server").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device is currently" +
" enrolled with the server").build());
}
DeviceList devices = new DeviceList();
devices.setList((List<Device>) result.getData());
@ -124,8 +125,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDeviceInfo(deviceIdentifier);
if (deviceInfo == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is " +
"found upon the give type '" + type + "' and id '" + id + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that no " +
"device is found upon the give type '" + type + "' and id '" + id + "'").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
@ -148,8 +150,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceInfo = informationManager.getDevicesInfo(deviceIds);
if (deviceInfo == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No device information is available for the " +
"device list submitted").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device information " +
"is available for the device list submitted").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device information.";
@ -179,8 +182,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
if (device == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Requested device of type '" + type +
"', which carries id '" + id + "' does not exist").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Requested device of type '" +
type + "', which carries id '" + id + "' does not exist").build());
}
return Response.status(Response.Status.OK).entity(device).build();
}
@ -201,8 +205,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
deviceLocation = informationManager.getDeviceLocation(new DeviceIdentifier(id, type));
if (deviceLocation == null || deviceLocation.getLatitude() == null ||
deviceLocation.getLongitude() == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Location details are not available for the " +
"given device id '" + id + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Location details " +
"are not available for the given device id '" + id + "'").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the last updated location of the '" + type + "' device, " +
@ -220,9 +225,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
DeviceInformationManager informationManager;
List<DeviceLocation> deviceLocations;
RequestValidationUtil.validateDeviceIdentifiers(deviceIdentifiers);
try {
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocations = informationManager.getDeviceLocations(deviceIdentifiers);
if (deviceLocations == null || deviceLocations.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No location related " +
"details were found.").build());
}
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);
@ -247,8 +258,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
dms = DeviceMgtAPIUtils.getDeviceManagementService();
FeatureManager fm = dms.getFeatureManager(type);
if (fm == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No feature manager is registered with " +
"the given type '" + type + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No feature manager is " +
"registered with the given type '" + type + "'").build());
}
features = fm.getFeatures();
} catch (DeviceManagementException e) {
@ -278,10 +290,10 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
if (devices == null || devices.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided search filters").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that no device is found upon " +
"the provided search filters").build());
}
return Response.status(Response.Status.OK).entity(devices).build();
}
@ -302,8 +314,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
amc = DeviceMgtAPIUtils.getAppManagementService();
applications = amc.getApplicationListForDevice(new DeviceIdentifier(id, type));
if (applications == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon" +
" the provided type and id").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that " +
"no applications is found upon the provided type and id").build());
}
} catch (ApplicationManagementException e) {
String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " +
@ -332,8 +345,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
dms = DeviceMgtAPIUtils.getDeviceManagementService();
operations = dms.getOperations(new DeviceIdentifier(id, type));
if (operations == null) {
return Response.status(Response.Status.NOT_FOUND).entity("It is likely that no device is found upon " +
"the provided type and id").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("It is likely that" +
" no operation is found upon the provided type and id").build());
}
} catch (OperationManagementException e) {
String msg = "Error occurred while fetching the operations for the '" + type + "' device, which " +
@ -357,8 +371,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
Policy policy = policyManagementService.getAppliedPolicyToDevice(new DeviceIdentifier(id, type));
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No policy has been found for the '" +
type + "' device, which carries the id '" + id + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policy has " +
"been found for the '" + type + "' device, which carries the id '" + id + "'").build());
}
return Response.status(Response.Status.OK).entity(policy).build();
} catch (PolicyManagementException e) {

@ -25,8 +25,8 @@ import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagement
import org.wso2.carbon.device.mgt.jaxrs.NotificationContext;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.NotificationManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
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 javax.ws.rs.*;
@ -59,9 +59,10 @@ public class NotificationManagementServiceImpl implements NotificationManagement
notifications = DeviceMgtAPIUtils.getNotificationManagementService().getAllNotifications();
}
if (notifications == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No notification is available to be " +
"retrieved").build();
if (notifications == null || notifications.size() == 0) {
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No notification is " +
"available to be retrieved.").build());
}
return Response.status(Response.Status.OK).entity(notifications).build();
} catch (NotificationManagementException e) {

@ -27,9 +27,12 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.PolicyManagementService;
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.beans.PolicyList;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil;
@ -53,7 +56,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@POST
@Override
public Response addPolicy(PolicyWrapper policyWrapper) {
RequestValidationUtil.validatePolicyDetails(policyWrapper);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
try {
Policy policy = this.getPolicyFromWrapper(policyWrapper);
@ -67,13 +72,15 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
String username = threadLocalCarbonContext.getUsername();
try {
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, username)) {
return Response.status(Response.Status.UNAUTHORIZED).entity("Current logged in user is " +
"not authorized to add policies").build();
throw new UnauthorizedAccessException(
new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage
("Current logged in user is not authorized to add policies").build());
}
} catch (DeviceAccessAuthorizationException e) {
String msg = "ErrorResponse occurred while checking if the current user is authorized to add a policy";
log.error(msg, e);
return javax.ws.rs.core.Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
}
@ -83,11 +90,13 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while adding policy";
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 (DeviceManagementException e) {
String msg = "ErrorResponse occurred while retrieving device list.";
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());
}
}
@ -127,7 +136,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicies();
if (policies == null || policies.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No policies found.").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policies found.").build());
}
targetPolicies.setCount(policies.size());
filteredPolicies = FilteringUtil.getFilteredList(policies, offset, limit);
@ -138,7 +148,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while retrieving all available policies";
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(targetPolicies).build();
@ -154,12 +165,14 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policy = policyAdministratorPoint.getPolicy(id);
if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No policy found.").build());
}
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while retrieving policy corresponding to the id '" + id + "'";
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(policy).build();
}
@ -168,6 +181,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/{id}")
@Override
public Response updatePolicy(@PathParam("id") int id, PolicyWrapper policyWrapper) {
RequestValidationUtil.validatePolicyDetails(policyWrapper);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
try {
Policy policy = this.getPolicyFromWrapper(policyWrapper);
@ -178,15 +192,17 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
return Response.status(Response.Status.NOT_FOUND).entity("Policy not found.").build();
}
pap.updatePolicy(policy);
return Response.status(Response.Status.OK).entity("Policy has successfully been updated").build();
return Response.status(Response.Status.OK).entity("Policy has successfully been updated.").build();
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while updating the policy";
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 (DeviceManagementException e) {
String msg = "ErrorResponse occurred while retrieving the device list.";
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());
}
}
@ -194,6 +210,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/remove-policy")
@Override
public Response removePolicies(List<Integer> policyIds) {
RequestValidationUtil.validatePolicyIds(policyIds);
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
boolean policyDeleted = true;
try {
@ -207,13 +224,15 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while removing policies";
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());
}
if (policyDeleted) {
return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build();
} else {
//TODO:Check of this logic is correct
return Response.status(Response.Status.NOT_FOUND).entity("Policy doesn't exist").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Policy doesn't exist").build());
}
}
@ -221,6 +240,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/activate-policy")
@Override
public Response activatePolicies(List<Integer> policyIds) {
RequestValidationUtil.validatePolicyIds(policyIds);
boolean isPolicyActivated = false;
try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
@ -235,14 +255,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} catch (PolicyManagementException e) {
String msg = "ErrorResponse occurred while activating policies";
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());
}
if (isPolicyActivated) {
return Response.status(Response.Status.OK).entity("Selected policies have been successfully activated")
.build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Selected policies have not been activated")
.build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Selected policies have " +
"not been activated").build());
}
}
@ -250,6 +272,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@Path("/deactivate-policy")
@Override
public Response deactivatePolicies(List<Integer> policyIds) {
RequestValidationUtil.validatePolicyIds(policyIds);
boolean isPolicyDeActivated = false;
try {
PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService();
@ -264,14 +287,16 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
} catch (PolicyManagementException e) {
String msg = "Exception in inactivating policies.";
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());
}
if (isPolicyDeActivated) {
return Response.status(Response.Status.OK).entity("Selected policies have been successfully " +
"deactivated").build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Selected policies have not been deactivated")
.build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("Selected policies have " +
"not been deactivated").build());
}
}

@ -23,15 +23,16 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
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.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
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.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;
@ -62,12 +63,14 @@ public class RoleManagementServiceImpl implements RoleManagementService {
try {
filteredRoles = getRolesFromUserStore();
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());
}
targetRoles.setCount(filteredRoles.size());
filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(), offset, limit);
if (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());
}
targetRoles.setList(filteredRoles);
} catch (UserStoreException e) {
@ -85,6 +88,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
public Response getPermissionsOfRole(
@PathParam("roleName") String roleName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
RequestValidationUtil.validateRoleName(roleName);
try {
final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm();
org.wso2.carbon.user.core.UserRealm userRealmCore = null;
@ -95,8 +99,9 @@ public class RoleManagementServiceImpl implements RoleManagementService {
final UserRealmProxy userRealmProxy = new UserRealmProxy(userRealmCore);
rolePermissions = this.getUIPermissionNode(roleName, userRealmProxy);
if (rolePermissions == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No permissions found for the role '" +
roleName + "'").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No permissions found" +
" for the role '" + roleName + "'").build());
}
return Response.status(Response.Status.OK).entity(rolePermissions).build();
} catch (UserAdminException e) {
@ -139,6 +144,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Override
public Response getRole(@PathParam("roleName") String roleName,
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
RequestValidationUtil.validateRoleName(roleName);
RoleWrapper roleWrapper = new RoleWrapper();
try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
@ -162,6 +168,10 @@ public class RoleManagementServiceImpl implements RoleManagementService {
roleWrapper.setPermissionList(rolePermissions);
String[] permListAr = new String[permList.size()];
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) {
String msg = "Error occurred while retrieving the user role '" + roleName + "'";
@ -185,10 +195,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@POST
@Override
public Response addRole(RoleWrapper roleWrapper) {
if (roleWrapper == null) {
log.error("Request body is incorrect or empty");
return Response.status(Response.Status.BAD_REQUEST).build();
}
RequestValidationUtil.validateRoleDetails(roleWrapper);
RequestValidationUtil.validateRoleName(roleWrapper.getRoleName());
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (log.isDebugEnabled()) {
@ -218,9 +226,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Path("/{roleName}")
@Override
public Response updateRole(@PathParam("roleName") String roleName, RoleWrapper roleWrapper) {
if (roleWrapper == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Request body is incorrect or empty").build();
}
RequestValidationUtil.validateRoleName(roleName);
RequestValidationUtil.validateRoleDetails(roleWrapper);
String newRoleName = roleWrapper.getRoleName();
try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
@ -265,6 +272,7 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Path("/{roleName}")
@Override
public Response deleteRole(@PathParam("roleName") String roleName) {
RequestValidationUtil.validateRoleName(roleName);
try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
final AuthorizationManager authorizationManager = DeviceMgtAPIUtils.getAuthorizationManager();
@ -288,9 +296,8 @@ public class RoleManagementServiceImpl implements RoleManagementService {
@Path("/{roleName}/users")
@Override
public Response updateUsersOfRole(@PathParam("roleName") String roleName, List<String> users) {
if (users == null || users.size() == 0) {
return Response.status(Response.Status.BAD_REQUEST).entity("No users are found in the request").build();
}
RequestValidationUtil.validateRoleName(roleName);
RequestValidationUtil.validateUsers(users);
try {
final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
if (log.isDebugEnabled()) {

@ -27,11 +27,12 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.*;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.NotFoundException;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
@ -42,7 +43,6 @@ import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.util.*;
@Path("/users")
@ -65,8 +65,10 @@ public class UserManagementServiceImpl implements UserManagementService {
" already exists. Therefore, request made to add user was refused.");
}
// returning response with bad request state
return Response.status(Response.Status.CONFLICT).entity("User by username: " + userWrapper.getUsername() +
" already exists. Therefore, request made to add user was refused.").build();
throw new ConflictException(
new ErrorResponse.ErrorResponseBuilder().setCode(409l).setMessage("User by username: " +
userWrapper.getUsername() + " already exists. Therefore, request made to add user " +
"was refused.").build());
} else {
String initialUserPassword = this.generateInitialUserPassword();
Map<String, String> defaultUserClaims =
@ -186,8 +188,9 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + username + " does not exist.");
}
// returning response with bad request state
return Response.status(Response.Status.NOT_FOUND).entity(
"User by username: " + username + " does not exist").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("User doesn't exist.")
.build());
}
} catch (UserStoreException e) {
String msg = "ErrorResponse occurred while retrieving information of the user '" + username + "'";
@ -243,9 +246,10 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + userWrapper.getUsername() +
" doesn't exists. Therefore, request made to update user was refused.");
}
return Response.status(Response.Status.CONFLICT).entity("User by username: " +
userWrapper.getUsername() + " doesn't exists. Therefore, request made to update user was " +
"refused.").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("User by username: " +
userWrapper.getUsername() + " doesn't exists. Therefore, request made to update user" +
" was refused.").build());
}
} catch (UserStoreException e) {
String msg = "Exception in trying to update user by username: " + userWrapper.getUsername();
@ -293,8 +297,9 @@ public class UserManagementServiceImpl implements UserManagementService {
log.debug("User by username: " + username + " does not exist for removal.");
}
// returning response with bad request state
return Response.status(Response.Status.NOT_FOUND).entity("User by username: " + username +
" does not exist for removal.").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("User by username: " +
username + " does not exist for removal.").build());
}
} catch (UserStoreException e) {
String msg = "Exception in trying to remove user by username: " + username;
@ -318,8 +323,9 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("User by username: " + username + " does not exist for role retrieval.");
}
return Response.status(Response.Status.NOT_FOUND).entity("User by username: " + username +
" does not exist for role retrieval.").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("User by username: " + username +
" does not exist for role retrieval.").build());
}
} catch (UserStoreException e) {
String msg = "Exception in trying to retrieve roles for user by username: " + username;

@ -28,8 +28,8 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnauthorizedAccessException;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.UnexpectedServerErrorException;
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 javax.ws.rs.*;
@ -66,8 +66,9 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService().
getDevicesByNameAndType(name, type, offset, limit);
if (devices == null || devices.size() == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No device, which carries the name '" +
name + "', is currently enrolled in the system").build();
throw new NotFoundException(
new ErrorResponse.ErrorResponseBuilder().setCode(404l).setMessage("No device, which carries" +
" the name '" + name + "', is currently enrolled in the system").build());
}
// setting up paginated result

@ -0,0 +1,34 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class ConflictException extends WebApplicationException {
private static final long serialVersionUID = 14234272342342340L;
public ConflictException(ErrorResponse error) {
super(Response.status(Response.Status.CONFLICT).entity(error).build());
}
}

@ -0,0 +1,34 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class NotFoundException extends WebApplicationException {
private static final long serialVersionUID = 147943572342342340L;
public NotFoundException(ErrorResponse error) {
super(Response.status(Response.Status.NOT_FOUND).entity(error).build());
}
}

@ -18,12 +18,10 @@
*/
package org.wso2.carbon.device.mgt.jaxrs.service.impl.util;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import javax.ws.rs.core.Response;
import org.wso2.carbon.device.mgt.jaxrs.beans.*;
import java.util.ArrayList;
import java.util.List;
@ -247,6 +245,57 @@ public class RequestValidationUtil {
}
}
public static void validateUpdateConfiguration(PlatformConfiguration config) {
if (config == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Configurations are not defined.")
.build());
} else if (config.getConfiguration() == null || config.getConfiguration().size() == 0) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Does not contain any " +
"configuration entries.").build());
}
}
public static void validateDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
if (deviceIdentifiers == null || deviceIdentifiers.size() == 0) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Device identifier list is " +
"empty.").build());
}
}
public static void validatePolicyDetails(PolicyWrapper policyWrapper) {
if (policyWrapper == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy is empty.").build());
}
}
public static void validatePolicyIds(List<Integer> policyIds) {
if (policyIds == null || policyIds.size() == 0) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Policy Id list is empty.").build
());
}
}
public static void validateRoleName(String roleName) {
if (roleName == null || roleName.isEmpty()) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Role name isn't valid.").build
());
}
}
public static void validateUsers(List<String> users) {
if (users == null || users.size() == 0) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("User list isn't valid.").build
());
}
}
public static void validateCredentials(OldPasswordResetWrapper credentials) {
if (credentials == null || credentials.getNewPassword() == null || credentials.getOldPassword() == null) {
throw new InputValidationException(
@ -255,4 +304,12 @@ public class RequestValidationUtil {
}
}
public static void validateRoleDetails(RoleWrapper roleWrapper) {
if (roleWrapper == null) {
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request body is incorrect or" +
" empty").build());
}
}
}

Loading…
Cancel
Save