use of org.openlmis.stockmanagement.exception.PermissionMessageException in project openlmis-stockmanagement by OpenLMIS.
the class PermissionService method checkUserToken.
private ResultDto<Boolean> checkUserToken(String rightName, UUID program, UUID facility, UUID warehouse) {
UserDto user = authenticationHelper.getCurrentUser();
RightDto right = authenticationHelper.getRight(rightName);
try {
return userReferenceDataService.hasRight(user.getId(), right.getId(), program, facility, warehouse);
} catch (HttpClientErrorException httpException) {
throw new PermissionMessageException(new Message(ERROR_PERMISSION_CHECK_FAILED, httpException.getMessage()), httpException);
}
}
use of org.openlmis.stockmanagement.exception.PermissionMessageException in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesV2ControllerIntegrationTest method shouldReturnForbiddenIfNoPermission.
@Test
public void shouldReturnForbiddenIfNoPermission() throws Exception {
doThrow(new PermissionMessageException(new Message("no permission"))).when(stockCardSummariesService).findStockCards(any(StockCardSummariesV2SearchParams.class));
ResultActions resultActions = mvc.perform(get(API_STOCK_CARD_SUMMARIES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param(PAGE, String.valueOf(pageable.getPageNumber())).param(SIZE, String.valueOf(pageable.getPageSize())).param(PROGRAM_ID, params.getProgramId().toString()).param(FACILITY_ID, params.getFacilityId().toString()));
resultActions.andExpect(status().isForbidden());
}
use of org.openlmis.stockmanagement.exception.PermissionMessageException in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageOrganizations.
@Test
public void shouldReturn403WhenUserHasNoPermissionToManageOrganizations() throws Exception {
// given
doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageOrganizations();
Organization organization = createOrganization("Would Get 403");
// 1. try to create organization
ResultActions postResult = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
postResult.andExpect(status().isForbidden());
// 2. try to update organization
ResultActions putResult = mvc.perform(put(ORGANIZATION_API + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
putResult.andExpect(status().isForbidden());
// 3. try to retrieve organizations
ResultActions getResult = mvc.perform(get(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON));
getResult.andExpect(status().isForbidden());
}
Aggregations