Search in sources :

Example 11 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UpdatePasswordAction method updatePassword.

public void updatePassword() throws Exception {
    HttpServletResponse response = ServletActionContext.getResponse();
    response.setContentType("text/plain");
    if (!confirmPassword.equals(newPassword)) {
        _log.info("passwords do not match");
        response.getWriter().print(ERROR);
    }
    String username = _currentUserService.getCurrentUserAsUserIndex().getId().getValue();
    UserDetail detail = _userManagementService.getUserDetail(username);
    detail.setPassword(newPassword);
    _userManagementService.updateUser(detail);
    _temporaryPasswordService.setTemporaryPassword(username, false);
    response.getWriter().print(SUCCESS);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 12 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserResource method getDetail.

@Path("/getUserDetails")
@GET
@Produces("application/json")
public Response getDetail(@QueryParam("user") String userName) {
    if (!isAuthorized()) {
        return Response.noContent().build();
    }
    log.info("Getting user detail for user : {}", userName);
    UserDetail userDetail = userManagementService.getUserDetail(userName);
    Response response = constructResponse(userDetail);
    log.info("Returning response from getUserDetail");
    return response;
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) Response(javax.ws.rs.core.Response) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testUpdateUserRole.

@Test
public void testUpdateUserRole() {
    Integer userId = 1;
    UserDetail userDetail = mock(UserDetail.class);
    UserIndex userIndex = mock(UserIndex.class);
    UserRole userRole = mock(UserRole.class);
    Set<UserIndex> userIndices = new HashSet<UserIndex>();
    userIndices.add(userIndex);
    Set<UserRole> userRoles = new HashSet<UserRole>();
    userRoles.add(userRole);
    when(userRole.getName()).thenReturn("ROLE_USER");
    buildUserDetail(userId, userDetail, "");
    when(userService.getUserForId(userId)).thenReturn(user);
    when(user.getUserIndices()).thenReturn(userIndices);
    when(user.getRoles()).thenReturn(userRoles);
    boolean success = service.updateUser(userDetail);
    assertTrue("User's password updated successfully", success);
    verify(passwordEncoder, times(0)).encodePassword("", "admin");
    verify(authoritiesService).getUserRoleForName("ROLE_ADMINISTRATOR");
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) UserRole(org.onebusaway.users.model.UserRole) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testDeactivateUser.

@Test
public void testDeactivateUser() {
    Integer userId = 1;
    UserDetail userDetail = mock(UserDetail.class);
    buildUserDetail(userId, userDetail, "password");
    UserIndex userIndex = mock(UserIndex.class);
    Set<UserIndex> userIndices = new HashSet<UserIndex>();
    userIndices.add(userIndex);
    when(userService.getUserForId(userId)).thenReturn(user);
    when(user.getUserIndices()).thenReturn(userIndices);
    boolean success = service.deactivateUser(userDetail);
    assertTrue("User deactivated successfully", success);
    verify(userDao).deleteUserIndex(isA(UserIndex.class));
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with UserDetail

use of org.onebusaway.admin.model.ui.UserDetail in project onebusaway-application-modules by camsys.

the class UserManagementServiceImplTest method testUpdateUser.

@Test
public void testUpdateUser() {
    String credentials = "encryptedPassword";
    Integer userId = 1;
    UserDetail userDetail = mock(UserDetail.class);
    UserIndex userIndex = mock(UserIndex.class);
    UserRole userRole = mock(UserRole.class);
    UserRole adminRole = mock(UserRole.class);
    Set<UserIndex> userIndices = new HashSet<UserIndex>();
    userIndices.add(userIndex);
    Set<UserRole> userRoles = new HashSet<UserRole>();
    userRoles.add(userRole);
    when(userRole.getName()).thenReturn("ROLE_USER");
    buildUserDetail(userId, userDetail, "password");
    when(userService.getUserForId(userId)).thenReturn(user);
    when(passwordEncoder.encodePassword("password", "admin")).thenReturn(credentials);
    when(user.getUserIndices()).thenReturn(userIndices);
    when(user.getRoles()).thenReturn(userRoles);
    when(authoritiesService.getUserRoleForName("ROLE_ADMINISTRATOR")).thenReturn(adminRole);
    boolean success = service.updateUser(userDetail);
    assertTrue("User updated successfully", success);
    verify(passwordEncoder).encodePassword("password", "admin");
    verify(authoritiesService).getUserRoleForName("ROLE_ADMINISTRATOR");
    verify(userDao).saveOrUpdateUser(user);
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) UserIndex(org.onebusaway.users.model.UserIndex) UserRole(org.onebusaway.users.model.UserRole) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UserDetail (org.onebusaway.admin.model.ui.UserDetail)18 Test (org.junit.Test)6 UserIndex (org.onebusaway.users.model.UserIndex)6 StringReader (java.io.StringReader)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Criteria (org.hibernate.Criteria)4 HibernateException (org.hibernate.HibernateException)4 Session (org.hibernate.Session)4 User (org.onebusaway.users.model.User)4 UserRole (org.onebusaway.users.model.UserRole)4 UserBean (org.onebusaway.users.client.model.UserBean)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1