Search in sources :

Example 6 with UserRole

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

Example 7 with UserRole

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

Example 8 with UserRole

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

Example 9 with UserRole

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;
}
Also used : GrantedAuthorityImpl(org.springframework.security.core.authority.GrantedAuthorityImpl) UserRole(org.onebusaway.users.model.UserRole) GrantedAuthority(org.springframework.security.core.GrantedAuthority)

Example 10 with UserRole

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

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