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());
}
}
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());
}
}
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());
}
}
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);
}
}
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);
}
Aggregations