use of org.camunda.bpm.engine.AuthorizationException in project camunda-bpm-platform by camunda.
the class ProcessDefinitionResourceImpl method submitForm.
@Override
public ProcessInstanceDto submitForm(UriInfo context, StartProcessInstanceDto parameters) {
FormService formService = engine.getFormService();
ProcessInstance instance = null;
try {
Map<String, Object> variables = VariableValueDto.toMap(parameters.getVariables(), engine, objectMapper);
String businessKey = parameters.getBusinessKey();
if (businessKey != null) {
instance = formService.submitStartForm(processDefinitionId, businessKey, variables);
} else {
instance = formService.submitStartForm(processDefinitionId, variables);
}
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
} catch (RestException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
}
ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);
URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
result.addReflexiveLink(uri, HttpMethod.GET, "self");
return result;
}
use of org.camunda.bpm.engine.AuthorizationException in project camunda-bpm-platform by camunda.
the class ProcessDefinitionResourceImpl method getStartForm.
@Override
public FormDto getStartForm() {
final FormService formService = engine.getFormService();
final StartFormData formData;
try {
formData = formService.getStartFormData(processDefinitionId);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e, "Cannot get start form data for process definition " + processDefinitionId);
}
FormDto dto = FormDto.fromFormData(formData);
if (dto.getKey() == null || dto.getKey().isEmpty()) {
if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
dto.setKey("embedded:engine://engine/:engine/process-definition/" + processDefinitionId + "/rendered-form");
}
}
dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
return dto;
}
use of org.camunda.bpm.engine.AuthorizationException in project camunda-bpm-platform by camunda.
the class ProcessDefinitionResourceImpl method startProcessInstance.
@Override
public ProcessInstanceDto startProcessInstance(UriInfo context, StartProcessInstanceDto parameters) {
ProcessInstanceWithVariables instance = null;
try {
instance = startProcessInstanceAtActivities(parameters);
} catch (AuthorizationException e) {
throw e;
} catch (ProcessEngineException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
} catch (RestException e) {
String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
throw new InvalidRequestException(e.getStatus(), e, errorMessage);
}
ProcessInstanceDto result;
if (parameters.isWithVariablesInReturn()) {
result = ProcessInstanceWithVariablesDto.fromProcessInstance(instance);
} else {
result = ProcessInstanceDto.fromProcessInstance(instance);
}
URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
result.addReflexiveLink(uri, HttpMethod.GET, "self");
return result;
}
use of org.camunda.bpm.engine.AuthorizationException in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testCreateAuthorizationThrowsAuthorizationException.
@Test
public void testCreateAuthorizationThrowsAuthorizationException() {
String message = "expected authorization exception";
when(authorizationServiceMock.createNewAuthorization(Authorization.AUTH_TYPE_GRANT)).thenThrow(new AuthorizationException(message));
Authorization authorization = MockProvider.createMockGrantAuthorization();
AuthorizationDto dto = AuthorizationDto.fromAuthorization(authorization);
given().body(dto).contentType(ContentType.JSON).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().post(AUTH_CREATE_PATH);
}
use of org.camunda.bpm.engine.AuthorizationException in project camunda-bpm-platform by camunda.
the class AuthorizationRestServiceInteractionTest method testDeleteAuthorizationThrowsAuthorizationException.
@Test
public void testDeleteAuthorizationThrowsAuthorizationException() {
Authorization authorization = MockProvider.createMockGlobalAuthorization();
AuthorizationQuery authorizationQuery = mock(AuthorizationQuery.class);
when(authorizationServiceMock.createAuthorizationQuery()).thenReturn(authorizationQuery);
when(authorizationQuery.authorizationId(MockProvider.EXAMPLE_AUTHORIZATION_ID)).thenReturn(authorizationQuery);
when(authorizationQuery.singleResult()).thenReturn(authorization);
String message = "expected authorization exception";
doThrow(new AuthorizationException(message)).when(authorizationServiceMock).deleteAuthorization(MockProvider.EXAMPLE_AUTHORIZATION_ID);
given().pathParam("id", MockProvider.EXAMPLE_AUTHORIZATION_ID).then().expect().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().delete(AUTH_RESOURCE_PATH);
}
Aggregations