UserRoleDaoResource extends AbstractJaxRSResource { @GET @Path ( "/roleMembers" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of Users." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "The system was not able to return the list of users." ) } ) public UserListWrapper getRoleMembers( @QueryParam ( "roleName" ) String roleName ) throws Exception { try { return userRoleDaoService.getRoleMembers( roleName ); } catch ( UncategorizedUserRoleDaoException e ) { throw new WebApplicationException( Response.Status.INTERNAL_SERVER_ERROR ); } catch ( SecurityException e ) { throw new WebApplicationException( Response.Status.FORBIDDEN ); } } UserRoleDaoResource();  UserRoleDaoResource( final IRoleAuthorizationPolicyRoleBindingDao roleBindingDao,
                              final ITenantManager tenantMgr, final ArrayList<String> systemRoles, final String adminRole );  UserRoleDaoResource( final IRoleAuthorizationPolicyRoleBindingDao roleBindingDao,
                              final ITenantManager tenantMgr, final ArrayList<String> systemRoles, final String adminRole, UserRoleDaoService  service ); @PUT @Path( "/createUser" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully created new user." ), @ResponseCode( code = 400, condition = "Provided data has invalid format." ), @ResponseCode( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode( code = 412, condition = "Unable to create user." ) } ) Response createUser( User user ); @PUT @Path ( "/deleteUsers" ) @Consumes ( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully deleted the list of users." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "Internal server error prevented the system from properly retrieving either the user or roles." ) } ) Response deleteUsers( @QueryParam( "userNames" ) String userNames ); @PUT @Path( "/user" ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully changed password." ), @ResponseCode( code = 400, condition = "Provided data has invalid format." ), @ResponseCode( code = 403, condition = "Provided user name or password is incorrect." ), @ResponseCode( code = 412, condition = "An error occurred in the platform." ) } ) Response changeUserPassword( ChangePasswordUser user ); @GET @Path ( "/users" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes( { @ResponseCode ( code = 200, condition = "Successfully returned the list of users." ), @ResponseCode ( code = 500, condition = "An error occurred in the platform while trying to access the list of users." ) } ) UserListWrapper getUsers(); @GET @Path ( "/userRoles" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of roles." ), @ResponseCode ( code = 500, condition = "Invalid user parameter." ) } ) RoleListWrapper getRolesForUser( @QueryParam( "userName" ) String user ); @PUT @Path( "/assignRoleToUser" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully append the roles to the user." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "Internal server error prevented the system from properly retrieving either the user or roles." ) } ) Response assignRolesToUser( @QueryParam( "userName" ) String userName,
                                     @QueryParam( "roleNames" ) String roleNames ); @PUT @Path( "/removeRoleFromUser" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully removed the roles from the user." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "Internal server error prevented the system from properly retrieving either the user or roles." ) } ) Response removeRolesFromUser( @QueryParam( "userName" ) String userName,
                                       @QueryParam( "roleNames" ) String roleNames ); @PUT @Path( "/createRole" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes( { @ResponseCode( code = 200, condition = "Successfully created new role." ), @ResponseCode( code = 400, condition = "Provided data has invalid format." ), @ResponseCode( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode( code = 412, condition = "Unable to create role objects." ) } ) Response createRole( @QueryParam( "roleName" ) String roleName ); @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." ) } ) Response deleteRoles( @QueryParam( "roleNames" ) String roleNames ); @GET @Path( "/roles" ) @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of roles." ), @ResponseCode ( code = 500, condition = "The system was not able to return the list of roles." ) } ) RoleListWrapper getRoles(); @GET @Path ( "/roleMembers" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully retrieved the list of Users." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "The system was not able to return the list of users." ) } ) UserListWrapper getRoleMembers( @QueryParam ( "roleName" ) String roleName ); @PUT @Consumes ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @Path ( "/roleAssignments" ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully applied the logical role assignment." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ) } ) Response setLogicalRoles( LogicalRoleAssignments roleAssignments ); @GET @Path ( "/logicalRoleMap" ) @Produces ( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) @StatusCodes ( { @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ) } ) SystemRolesMap getRoleBindingStruct( @QueryParam ( "locale" ) String locale ); @PUT @Path ( "/assignAllRolesToUser" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response assignAllRolesToUser( @QueryParam ( "tenant" ) String tenantPath,
                                        @QueryParam ( "userName" ) String userName ); @PUT @Path ( "/removeAllRolesFromUser" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response removeAllRolesFromUser( @QueryParam ( "tenant" ) String tenantPath,
                                          @QueryParam ( "userName" ) String userName ); @PUT @Path ( "/assignUserToRole" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response assignUserToRole( @QueryParam ( "tenant" ) String tenantPath,
                                    @QueryParam ( "userNames" ) String userNames, @QueryParam ( "roleName" ) String roleName ); @PUT @Path ( "/removeUserFromRole" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response removeUserFromRole( @QueryParam ( "tenant" ) String tenantPath,
                                      @QueryParam ( "userNames" ) String userNames, @QueryParam ( "roleName" ) String roleName ); @PUT @Path ( "/assignAllUsersToRole" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response assignAllUsersToRole( @QueryParam ( "tenant" ) String tenantPath,
                                        @QueryParam( "roleName" ) String roleName ); @PUT @Path ( "/removeAllUsersFromRole" ) @Consumes ( { MediaType.WILDCARD } ) @Facet ( name = "Unsupported" ) Response removeAllUsersFromRole( @QueryParam ( "tenant" ) String tenantPath,
                                          @QueryParam ( "roleName" ) String roleName ); @PUT @Path( "/updatePassword" ) @Consumes( { MediaType.WILDCARD } ) @StatusCodes ( { @ResponseCode ( code = 200, condition = "Successfully deleted the list of users." ), @ResponseCode ( code = 403, condition = "Only users with administrative privileges can access this method." ), @ResponseCode ( code = 500, condition = "Internal server error prevented the system from properly retrieving either the user or roles." ) } ) Response updatePassword( UserChangePasswordDTO user );  }
@Test public void testGetRoleMembers() throws Exception { String role = "Report Author"; UserListWrapper userListWrapper = new UserListWrapper( new ArrayList<IPentahoUser>() ); when( userRoleService.getRoleMembers( role ) ).thenReturn( userListWrapper ); assertEquals( userListWrapper, userRoleResource.getRoleMembers( role ) ); }
@Test public void testGetRoleMembersSecurityException() throws Exception { String role = "Report Author"; when( userRoleService.getRoleMembers( role ) ).thenThrow( new SecurityException() ); try { userRoleResource.getRoleMembers( role ); } catch ( WebApplicationException e ) { assertEquals( Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus() ); } }
@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() ); } }