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