use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserManagementServiceImplTest method testCreateUser.
@Test
public void testCreateUser() {
UserIndex userIndex = mock(UserIndex.class);
when(userService.getOrCreateUserForUsernameAndPassword("operator", "password")).thenReturn(userIndex);
boolean success = service.createUser("operator", "password", false);
assertTrue("Expecting user to be created successfully", success);
verify(userService).getOrCreateUserForUsernameAndPassword("operator", "password");
verify(userService, times(0)).enableAdminRoleForUser(isA(User.class), isA(Boolean.class));
}
use of org.onebusaway.users.model.UserIndex 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);
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method buildUserDetail.
private UserDetail buildUserDetail(User user) {
UserDetail userDetail = new UserDetail();
userDetail.setId(user.getId());
for (UserIndex userIndex : user.getUserIndices()) {
userDetail.setUsername(userIndex.getId().getValue());
}
for (UserRole role : user.getRoles()) {
// There should be only one role
userDetail.setRole(role.getName());
}
UserBean bean = userService.getUserAsBean(user);
userDetail.setDisabled(bean.isDisabled());
return userDetail;
}
use of org.onebusaway.users.model.UserIndex in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method updateUser.
@Override
public boolean updateUser(UserDetail userDetail) {
User user = userService.getUserForId(userDetail.getId());
if (user == null) {
log.info("User '{}' does not exist in the system", userDetail.getUsername());
return false;
}
// Update user password
if (StringUtils.isNotBlank(userDetail.getPassword())) {
String credentials = passwordEncoder.encodePassword(userDetail.getPassword(), userDetail.getUsername());
for (UserIndex userIndex : user.getUserIndices()) {
userIndex.setCredentials(credentials);
}
}
// Update user role
updateRole(userDetail.getRole(), user);
userDao.saveOrUpdateUser(user);
log.info("User '{}' updated successfully", userDetail.getUsername());
return true;
}
Aggregations