Search in sources :

Example 6 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testUpdatePasswordNotAdmin.

@Test
public void testUpdatePasswordNotAdmin() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new SecurityException()).when(mockService).updatePassword(any(User.class));
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.updatePassword(new UserChangePasswordDTO("name", "newPassword", "bogusPassword"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 7 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testCreateUserDuplicate.

@Test
public void testCreateUserDuplicate() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new AlreadyExistsException("message")).when(mockService).createUser(any(User.class));
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.createUser(new User("user", "duplicate"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.PRECONDITION_FAILED.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 8 with UserRoleDaoService

use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testCreateRoleSecurityException.

@Test
public void testCreateRoleSecurityException() throws Exception {
    UserRoleDaoService mockService = mock(UserRoleDaoService.class);
    doThrow(new SecurityException()).when(mockService).createRole(anyString());
    UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
    try {
        resource.createRole("anyRoleName");
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : UserRoleDaoService(org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

UserRoleDaoService (org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService)8 WebApplicationException (javax.ws.rs.WebApplicationException)7 Test (org.junit.Test)6 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)4 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)1 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)1 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1