Search in sources :

Example 1 with UserRole

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);
    }
}
Also used : UserRole(org.onebusaway.users.model.UserRole)

Example 2 with UserRole

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);
    }
}
Also used : UserRole(org.onebusaway.users.model.UserRole)

Example 3 with UserRole

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());
}
Also used : UserRole(org.onebusaway.users.model.UserRole)

Example 4 with UserRole

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;
}
Also used : UserIndex(org.onebusaway.users.model.UserIndex) User(org.onebusaway.users.model.User) UserRole(org.onebusaway.users.model.UserRole) Date(java.util.Date) UserPropertiesV4(org.onebusaway.users.model.properties.UserPropertiesV4) HashSet(java.util.HashSet)

Example 5 with UserRole

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);
}
Also used : UserRole(org.onebusaway.users.model.UserRole)

Aggregations

UserRole (org.onebusaway.users.model.UserRole)18 UserIndex (org.onebusaway.users.model.UserIndex)8 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 UserDetail (org.onebusaway.admin.model.ui.UserDetail)4 Date (java.util.Date)3 User (org.onebusaway.users.model.User)3 UserBean (org.onebusaway.users.client.model.UserBean)2 UserIndexKey (org.onebusaway.users.model.UserIndexKey)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 ArrayList (java.util.ArrayList)1 Role (org.onebusaway.admin.model.role.Role)1 UserIndexBean (org.onebusaway.users.client.model.UserIndexBean)1 UserPropertiesV1 (org.onebusaway.users.model.UserPropertiesV1)1 UserPropertiesV2 (org.onebusaway.users.model.properties.UserPropertiesV2)1 UserPropertiesV4 (org.onebusaway.users.model.properties.UserPropertiesV4)1 GrantedAuthorityImpl (org.springframework.security.core.authority.GrantedAuthorityImpl)1