Search in sources :

Example 6 with UserDetail

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

the class UserManagementServiceImplTest method testUpdatePassword.

@Test
public void testUpdatePassword() {
    String credentials = "encryptedPassword";
    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_ADMINISTRATOR");
    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);
    boolean success = service.updateUser(userDetail);
    assertTrue("User's password updated successfully", success);
    verify(passwordEncoder).encodePassword("password", "admin");
    verify(authoritiesService, times(0)).getAdministratorRole();
    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 7 with UserDetail

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

the class ManageUsersAction method activateUser.

public String activateUser() {
    UserDetail userDetail = gsonTool.readJson(new StringReader(userData), UserDetail.class);
    boolean success = userManagementService.activateUser(userDetail);
    if (success) {
        updateUserMessage = "User activated successfully";
    } else {
        updateUserMessage = "Error activating user : '" + username + "'";
    }
    return "updateUser";
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) StringReader(java.io.StringReader)

Example 8 with UserDetail

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

the class ManageUsersAction method inactivateUser.

public String inactivateUser() {
    UserDetail userDetail = gsonTool.readJson(new StringReader(userData), UserDetail.class);
    boolean success = userManagementService.inactivateUser(userDetail);
    if (success) {
        updateUserMessage = "User inactivated successfully";
    } else {
        updateUserMessage = "Error inactivating user : '" + username + "'";
    }
    return "updateUser";
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) StringReader(java.io.StringReader)

Example 9 with UserDetail

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

the class ManageUsersAction method deleteUser.

public String deleteUser() {
    UserDetail userDetail = gsonTool.readJson(new StringReader(userData), UserDetail.class);
    boolean success = userManagementService.deactivateUser(userDetail);
    if (success) {
        updateUserMessage = "User deleted successfully";
    } else {
        updateUserMessage = "Error deleting user : '" + username + "'";
    }
    return "updateUser";
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) StringReader(java.io.StringReader)

Example 10 with UserDetail

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

the class ManageUsersAction method editUser.

/**
 * Edits a user in the system
 * @return
 */
public String editUser() {
    UserDetail userDetail = gsonTool.readJson(new StringReader(userData), UserDetail.class);
    boolean success = userManagementService.updateUser(userDetail);
    if (success) {
        updateUserMessage = "User '" + userDetail.getUsername() + "' edited successfully";
    } else {
        updateUserMessage = "Error editing user : '" + userDetail.getUsername() + "'";
    }
    return "updateUser";
}
Also used : UserDetail(org.onebusaway.admin.model.ui.UserDetail) StringReader(java.io.StringReader)

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