use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method disableOperatorRole.
@Override
public void disableOperatorRole(User user) {
UserRole operatorRole = authoritiesService.getUserRoleForName(StandardAuthoritiesService.USER);
Set<UserRole> roles = user.getRoles();
if (roles.remove(operatorRole)) {
userDao.saveOrUpdateUser(user);
}
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserManagementServiceImpl method updateRole.
private void updateRole(String role, User user) {
boolean updateRole = false;
UserRole currentRole = null;
Set<UserRole> userRoles = user.getRoles();
for (UserRole userRole : userRoles) {
// There should be only one role
if (!(userRole.getName().equals(role))) {
updateRole = true;
currentRole = userRole;
}
}
if (updateRole) {
// Remove current role and add the new role
userRoles.remove(currentRole);
UserRole newRole = authoritiesService.getUserRoleForName(role);
userRoles.add(newRole);
}
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class IndexAction method getName.
public String getName() {
// use first
UserRole user = getCurrentUserValue().getRoles().iterator().next();
String name = user.getName().split("_")[1];
return StringUtils.capitalize(name.toLowerCase());
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserServiceImpl method getOrCreateUserForIndexKey.
@Override
public UserIndex getOrCreateUserForIndexKey(UserIndexKey key, String credentials, boolean isAnonymous) {
UserIndex userIndex = _userDao.getUserIndexForId(key);
if (userIndex == null) {
User user = new User();
user.setCreationTime(new Date());
user.setTemporary(true);
user.setProperties(new UserPropertiesV4());
Set<UserRole> roles = new HashSet<UserRole>();
if (isAnonymous)
roles.add(_authoritiesService.getAnonymousRole());
else
roles.add(_authoritiesService.getUserRole());
user.setRoles(roles);
userIndex = new UserIndex();
userIndex.setId(key);
userIndex.setCredentials(credentials);
userIndex.setUser(user);
user.getUserIndices().add(userIndex);
_userDao.saveOrUpdateUser(user);
}
return userIndex;
}
use of org.onebusaway.users.model.UserRole in project onebusaway-application-modules by camsys.
the class UserServiceImpl method enableAdminRoleForUser.
@Override
public void enableAdminRoleForUser(User user, boolean onlyIfNoOtherAdmins) {
UserRole adminRole = _authoritiesService.getUserRoleForName(StandardAuthoritiesService.ADMINISTRATOR);
if (onlyIfNoOtherAdmins) {
int count = _userDao.getNumberOfUsersWithRole(adminRole);
if (count > 0)
return;
}
Set<UserRole> roles = user.getRoles();
if (roles.add(adminRole))
_userDao.saveOrUpdateUser(user);
}
Aggregations