use of org.onebusaway.users.model.UserRole 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.UserRole 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.UserRole in project onebusaway-application-modules by camsys.
the class AccessControlServiceImpl method userHasPrivilege.
@Override
public boolean userHasPrivilege(User user, Privilege privilege) {
if (user == null) {
// anonymous user
Role role = roleByName.get(StandardAuthoritiesService.ANONYMOUS);
return roleHasPrivilege(role, privilege);
}
Set<UserRole> roles = user.getRoles();
for (UserRole userRole : roles) {
Role role = roleByName.get(userRole.getName());
if (role == null)
_log.info("No privileges found for role " + userRole.getName());
else if (role.hasAllPrivileges() || (privilege != null && roleHasPrivilege(role, privilege))) {
_log.debug(userRole.getName() + " has privileges for " + privilege.getName());
return true;
}
}
_log.warn("Auth failed for " + user + ", " + privilege);
return false;
}
Aggregations