use of org.camunda.bpm.engine.rest.dto.identity.UserProfileDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutProfileThrowsAuthorizationException.
@Test
public void testPutProfileThrowsAuthorizationException() {
User initialUser = MockProvider.createMockUser();
User userUpdate = MockProvider.createMockUserUpdate();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(initialUser);
String message = "exception expected";
doThrow(new AuthorizationException(message)).when(identityServiceMock).saveUser(any(User.class));
UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);
given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(updateDto).contentType(ContentType.JSON).then().statusCode(Status.FORBIDDEN.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(AuthorizationException.class.getSimpleName())).body("message", equalTo(message)).when().put(USER_PROFILE_URL);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserProfileDto in project camunda-bpm-platform by camunda.
the class UserResourceImpl method getUserProfile.
public UserProfileDto getUserProfile(UriInfo context) {
User dbUser = findUserObject();
if (dbUser == null) {
throw new InvalidRequestException(Status.NOT_FOUND, "User with id " + resourceId + " does not exist");
}
UserProfileDto user = UserProfileDto.fromUser(dbUser);
return user;
}
use of org.camunda.bpm.engine.rest.dto.identity.UserProfileDto in project camunda-bpm-platform by camunda.
the class UserRestServiceImpl method createUser.
public void createUser(UserDto userDto) {
final IdentityService identityService = getIdentityService();
if (identityService.isReadOnly()) {
throw new InvalidRequestException(Status.FORBIDDEN, "Identity service implementation is read-only.");
}
UserProfileDto profile = userDto.getProfile();
if (profile == null || profile.getId() == null) {
throw new InvalidRequestException(Status.BAD_REQUEST, "request object must provide profile information with valid id.");
}
User newUser = identityService.newUser(profile.getId());
profile.update(newUser);
if (userDto.getCredentials() != null) {
newUser.setPassword(userDto.getCredentials().getPassword());
}
identityService.saveUser(newUser);
}
use of org.camunda.bpm.engine.rest.dto.identity.UserProfileDto in project camunda-bpm-platform by camunda.
the class TestUtil method createInitialUser.
public void createInitialUser(String id, String password, String firstName, String lastName) {
UserDto user = new UserDto();
UserCredentialsDto credentials = new UserCredentialsDto();
credentials.setPassword(password);
user.setCredentials(credentials);
UserProfileDto profile = new UserProfileDto();
profile.setId(id);
profile.setFirstName(firstName);
profile.setLastName(lastName);
user.setProfile(profile);
WebResource webResource = client.resource(testProperties.getApplicationPath("/camunda/api/admin/setup/default/user/create"));
ClientResponse clientResponse = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, user);
try {
if (clientResponse.getResponseStatus() != Response.Status.NO_CONTENT) {
throw new WebApplicationException(clientResponse.getResponseStatus());
}
} finally {
clientResponse.close();
}
}
use of org.camunda.bpm.engine.rest.dto.identity.UserProfileDto in project camunda-bpm-platform by camunda.
the class UserRestServiceInteractionTest method testPutProfileNonexistingFails.
@Test
public void testPutProfileNonexistingFails() {
User userUpdate = MockProvider.createMockUserUpdate();
UserQuery sampleUserQuery = mock(UserQuery.class);
when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
when(sampleUserQuery.singleResult()).thenReturn(null);
UserProfileDto updateDto = UserProfileDto.fromUser(userUpdate);
given().pathParam("id", "aNonExistingUser").body(updateDto).contentType(ContentType.JSON).then().then().expect().statusCode(Status.NOT_FOUND.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo(InvalidRequestException.class.getSimpleName())).body("message", equalTo("User with id aNonExistingUser does not exist")).when().put(USER_PROFILE_URL);
// nothing was saved
verify(identityServiceMock, never()).saveUser(any(User.class));
}
Aggregations