Search in sources :

Example 1 with UncategorizedUserRoleDaoException

use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testGetRolesError.

@Test
public void testGetRolesError() throws Exception {
    try {
        when(userRoleService.getRoles()).thenThrow(new UncategorizedUserRoleDaoException("expected"));
        userRoleResource.getRoles();
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Test(org.junit.Test)

Example 2 with UncategorizedUserRoleDaoException

use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testGetRoleMembersUncategorizedUserRoleDaoException.

@Test
public void testGetRoleMembersUncategorizedUserRoleDaoException() throws Exception {
    String role = "Report Author";
    when(userRoleService.getRoleMembers(role)).thenThrow(new UncategorizedUserRoleDaoException("expectedException"));
    try {
        userRoleResource.getRoleMembers(role);
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with UncategorizedUserRoleDaoException

use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.

the class UserRoleDaoResourceTest method testGetRolesForUserError.

@Test
public void testGetRolesForUserError() throws Exception {
    String user = "admin";
    RoleListWrapper roleListWrapper = new RoleListWrapper(new ArrayList<IPentahoRole>());
    when(userRoleService.getRolesForUser(user)).thenReturn(roleListWrapper);
    assertEquals(roleListWrapper, userRoleResource.getRolesForUser(user));
    try {
        when(userRoleService.getRolesForUser(user)).thenThrow(new UncategorizedUserRoleDaoException("testException"));
    } catch (WebApplicationException e) {
        assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) IPentahoRole(org.pentaho.platform.api.engine.security.userroledao.IPentahoRole) Test(org.junit.Test)

Example 4 with UncategorizedUserRoleDaoException

use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.

the class UserRoleDaoResource method deleteRoles.

/**
 * Delete role(s) from the platform. This endpoint is only available to users with administrative privileges.
 *
 * <p><b>Example Request:</b><br />
 *  PUT  pentaho/api/userroledao/deleteRoles?roleNames=role1%09
 * </p>
 *
 * @param roleNames List of tab (\t) separated role names, must be valid roles.
 * @return Response containing the result of the operation.
 */
@PUT
@Path("/deleteRoles")
@Consumes({ MediaType.WILDCARD })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully deleted the list of roles."), @ResponseCode(code = 403, condition = "Only users with administrative privileges can access this method."), @ResponseCode(code = 500, condition = "The system was unable to delete the roles passed in.") })
public Response deleteRoles(@QueryParam("roleNames") String roleNames) {
    try {
        userRoleDaoService.deleteRoles(roleNames);
        updateRolesForCurrentSession();
        return Response.ok().build();
    } catch (SecurityException e) {
        throw new WebApplicationException(Response.Status.FORBIDDEN);
    } catch (UncategorizedUserRoleDaoException e) {
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) PUT(javax.ws.rs.PUT)

Example 5 with UncategorizedUserRoleDaoException

use of org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException in project pentaho-platform by pentaho.

the class UserRoleDaoServiceTest method testAssignRoleToUserUncategorizedUserRoleDaoException.

@Test(expected = UncategorizedUserRoleDaoException.class)
public void testAssignRoleToUserUncategorizedUserRoleDaoException() throws UserRoleListService.UnauthorizedException {
    String userName = "testUser";
    String roleNames = "Power User\tBusiness User\t";
    setupMockSessionUser(SESSION_USER_NAME, true);
    // Create session that will generate tenant
    IPentahoSession session = mock(IPentahoSession.class);
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
    PentahoSessionHolder.setSession(session);
    IUserRoleDao roleDao = mock(IUserRoleDao.class);
    when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
    PentahoSystem.registerObject(roleDao);
    userRoleService.assignRolesToUser(userName, roleNames);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UncategorizedUserRoleDaoException(org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException) Matchers.anyString(org.mockito.Matchers.anyString) IUserRoleDao(org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao) Test(org.junit.Test)

Aggregations

UncategorizedUserRoleDaoException (org.pentaho.platform.api.engine.security.userroledao.UncategorizedUserRoleDaoException)13 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)5 ITenant (org.pentaho.platform.api.mt.ITenant)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 IPentahoRole (org.pentaho.platform.api.engine.security.userroledao.IPentahoRole)2 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)2 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Response (javax.ws.rs.core.Response)1 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 User (org.springframework.security.core.userdetails.User)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1