Search in sources :

Example 1 with UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.

the class UserRestServiceInteractionTest method testChangeCredentialsWithWrongAuthenticatedUserPassword.

@Test
public void testChangeCredentialsWithWrongAuthenticatedUserPassword() {
    User initialUser = MockProvider.createMockUser();
    UserQuery sampleUserQuery = mock(UserQuery.class);
    when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
    when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
    when(sampleUserQuery.singleResult()).thenReturn(initialUser);
    Authentication authentication = MockProvider.createMockAuthentication();
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
    when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(false);
    UserCredentialsDto dto = new UserCredentialsDto();
    dto.setPassword("new-password");
    dto.setAuthenticatedUserPassword(MockProvider.EXAMPLE_USER_PASSWORD);
    given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.BAD_REQUEST.getStatusCode()).contentType(ContentType.JSON).body("type", equalTo("InvalidRequestException")).body("message", equalTo("The given authenticated user password is not valid.")).when().put(USER_CREDENTIALS_URL);
}
Also used : User(org.camunda.bpm.engine.identity.User) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) Test(org.junit.Test)

Example 2 with UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.

the class UserRestServiceInteractionTest method testPutCredentialsNonExistingUserFails.

@Test
public void testPutCredentialsNonExistingUserFails() {
    UserQuery sampleUserQuery = mock(UserQuery.class);
    when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
    when(sampleUserQuery.userId("aNonExistingUser")).thenReturn(sampleUserQuery);
    when(sampleUserQuery.singleResult()).thenReturn(null);
    UserCredentialsDto dto = new UserCredentialsDto();
    dto.setPassword("new-password");
    given().pathParam("id", "aNonExistingUser").body(dto).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_CREDENTIALS_URL);
    // user was not updated
    verify(identityServiceMock, never()).saveUser(any(User.class));
}
Also used : User(org.camunda.bpm.engine.identity.User) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Test(org.junit.Test)

Example 3 with UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.

the class UserRestServiceInteractionTest method testChangeCredentials.

@Test
public void testChangeCredentials() {
    User initialUser = MockProvider.createMockUser();
    UserQuery sampleUserQuery = mock(UserQuery.class);
    when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
    when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
    when(sampleUserQuery.singleResult()).thenReturn(initialUser);
    Authentication authentication = MockProvider.createMockAuthentication();
    when(identityServiceMock.getCurrentAuthentication()).thenReturn(authentication);
    when(identityServiceMock.checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD)).thenReturn(true);
    UserCredentialsDto dto = new UserCredentialsDto();
    dto.setPassword("new-password");
    dto.setAuthenticatedUserPassword(MockProvider.EXAMPLE_USER_PASSWORD);
    given().pathParam("id", MockProvider.EXAMPLE_USER_ID).contentType(ContentType.JSON).body(dto).then().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(USER_CREDENTIALS_URL);
    verify(identityServiceMock).getCurrentAuthentication();
    verify(identityServiceMock).checkPassword(MockProvider.EXAMPLE_USER_ID, MockProvider.EXAMPLE_USER_PASSWORD);
    // password was updated
    verify(initialUser).setPassword(dto.getPassword());
    // and then saved
    verify(identityServiceMock).saveUser(initialUser);
}
Also used : User(org.camunda.bpm.engine.identity.User) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) Test(org.junit.Test)

Example 4 with UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto 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 UserCredentialsDto

use of org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto in project camunda-bpm-platform by camunda.

the class UserRestServiceInteractionTest method testPutCredentials.

@Test
public void testPutCredentials() {
    User initialUser = MockProvider.createMockUser();
    UserQuery sampleUserQuery = mock(UserQuery.class);
    when(identityServiceMock.createUserQuery()).thenReturn(sampleUserQuery);
    when(sampleUserQuery.userId(MockProvider.EXAMPLE_USER_ID)).thenReturn(sampleUserQuery);
    when(sampleUserQuery.singleResult()).thenReturn(initialUser);
    UserCredentialsDto dto = new UserCredentialsDto();
    dto.setPassword("new-password");
    given().pathParam("id", MockProvider.EXAMPLE_USER_ID).body(dto).contentType(ContentType.JSON).then().statusCode(Status.NO_CONTENT.getStatusCode()).when().put(USER_CREDENTIALS_URL);
    // password was updated
    verify(initialUser).setPassword(dto.getPassword());
    // and then saved
    verify(identityServiceMock).saveUser(initialUser);
}
Also used : User(org.camunda.bpm.engine.identity.User) UserQuery(org.camunda.bpm.engine.identity.UserQuery) UserCredentialsDto(org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto) Test(org.junit.Test)

Aggregations

UserCredentialsDto (org.camunda.bpm.engine.rest.dto.identity.UserCredentialsDto)6 User (org.camunda.bpm.engine.identity.User)5 UserQuery (org.camunda.bpm.engine.identity.UserQuery)5 Test (org.junit.Test)5 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)2 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 UserDto (org.camunda.bpm.engine.rest.dto.identity.UserDto)1 UserProfileDto (org.camunda.bpm.engine.rest.dto.identity.UserProfileDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 Matchers.anyString (org.mockito.Matchers.anyString)1