Search in sources :

Example 1 with UserProfileDto

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);
}
Also used : User(org.camunda.bpm.engine.identity.User) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with UserProfileDto

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;
}
Also used : User(org.camunda.bpm.engine.identity.User) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 3 with UserProfileDto

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);
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) User(org.camunda.bpm.engine.identity.User) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException)

Example 4 with UserProfileDto

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();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebApplicationException(javax.ws.rs.WebApplicationException) UserDto(org.camunda.bpm.engine.rest.dto.identity.UserDto) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) WebResource(com.sun.jersey.api.client.WebResource)

Example 5 with UserProfileDto

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));
}
Also used : User(org.camunda.bpm.engine.identity.User) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserProfileDto(org.camunda.bpm.engine.rest.dto.identity.UserProfileDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Aggregations

UserProfileDto (org.camunda.bpm.engine.rest.dto.identity.UserProfileDto)6 User (org.camunda.bpm.engine.identity.User)5 UserQuery (org.camunda.bpm.engine.identity.UserQuery)3 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)3 Test (org.junit.Test)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 UserCredentialsDto (org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto)1 UserDto (org.camunda.bpm.engine.rest.dto.identity.UserDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1