use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserServiceImpl method mergeRoles.
/**
**
* Private Methods
***
*/
private void mergeRoles(User sourceUser, User targetUser) {
Set<UserRole> roles = new HashSet<UserRole>();
roles.addAll(sourceUser.getRoles());
roles.addAll(targetUser.getRoles());
UserRole anon = _authoritiesService.getAnonymousRole();
UserRole user = _authoritiesService.getUserRole();
if (roles.contains(user))
roles.remove(anon);
targetUser.setRoles(roles);
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserServiceImpl method disableAdminRoleForUser.
public void disableAdminRoleForUser(User user, boolean onlyIfOtherAdmins) {
UserRole adminRole = _authoritiesService.getUserRoleForName(StandardAuthoritiesService.ADMINISTRATOR);
if (onlyIfOtherAdmins) {
int count = _userDao.getNumberOfUsersWithRole(adminRole);
if (count < 2)
return;
}
Set<UserRole> roles = user.getRoles();
if (roles.remove(adminRole))
_userDao.saveOrUpdateUser(user);
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class IndexedUserDetailsImpl method getGrantedAuthoritiesForUser.
private static GrantedAuthority[] getGrantedAuthoritiesForUser(StandardAuthoritiesService authoritiesService, User user) {
Set<UserRole> roles = user.getRoles();
GrantedAuthority[] authorities = new GrantedAuthority[roles.size()];
int index = 0;
for (UserRole role : roles) authorities[index++] = authoritiesService.getNameBasedAuthority(role.getName());
return authorities;
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class StandardAuthoritiesServiceImpl method createStandardAuthority.
private GrantedAuthority createStandardAuthority(final String name) {
assert !_standardAuthoritiesMap.containsKey(name);
assert !_userRoles.containsKey(name);
UserRole role = _userDao.getUserRoleForName(name);
if (role == null) {
role = new UserRole(name);
_userDao.saveOrUpdateUserRole(role);
}
_userRoles.put(name, role);
final GrantedAuthority auth = new GrantedAuthorityImpl(name);
_standardAuthoritiesMap.put(name, auth);
return auth;
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserManagementServiceImplTest method testCreateAdmin.
@Test
public void testCreateAdmin() {
UserIndex userIndex = mock(UserIndex.class);
UserRole role = mock(UserRole.class);
Set<UserRole> roles = new HashSet<UserRole>();
roles.add(role);
when(userService.getOrCreateUserForUsernameAndPassword("admin", "password")).thenReturn(userIndex);
when(userIndex.getUser()).thenReturn(user);
when(authoritiesService.getUserRoleForName(StandardAuthoritiesService.USER)).thenReturn(role);
when(user.getRoles()).thenReturn(roles);
boolean success = service.createUser("admin", "password", true);
assertTrue("Expecting user to be created successfully", success);
verify(userService).getOrCreateUserForUsernameAndPassword("admin", "password");
verify(userService).enableAdminRoleForUser(user, false);
verify(userDao).saveOrUpdateUser(user);
}
Aggregations