Search in sources :

Example 6 with Role

use of org.opencastproject.security.api.Role in project opencast by opencast.

the class UserIdRoleProvider method getRolesForUser.

/**
 * @see org.opencastproject.security.api.RoleProvider#getRolesForUser(String)
 */
@Override
public List<Role> getRolesForUser(String userName) {
    Organization organization = securityService.getOrganization();
    List<Role> roles = new ArrayList<Role>();
    roles.add(new JaxbRole(getUserIdRole(userName), JaxbOrganization.fromOrganization(organization), "The user id role", Role.Type.SYSTEM));
    roles.add(new JaxbRole(ROLE_USER, JaxbOrganization.fromOrganization(organization), "The authenticated user role", Role.Type.SYSTEM));
    return Collections.unmodifiableList(roles);
}
Also used : Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) JaxbRole(org.opencastproject.security.api.JaxbRole) ArrayList(java.util.ArrayList)

Example 7 with Role

use of org.opencastproject.security.api.Role in project opencast by opencast.

the class SakaiUserProviderInstance method getRolesForUser.

@Override
public List<Role> getRolesForUser(String userName) {
    List<Role> roles = new LinkedList<Role>();
    // Don't answer for admin, anonymous or empty user
    if ("admin".equals(userName) || "".equals(userName) || "anonymous".equals(userName)) {
        logger.debug("we don't answer for: " + userName);
        return roles;
    }
    logger.debug("getRolesForUser(" + userName + ")");
    User user = loadUser(userName);
    if (user != null) {
        logger.debug("Returning cached roleset for {}", userName);
        return new ArrayList<Role>(user.getRoles());
    }
    // Not found
    logger.debug("Return empty roleset for {} - not found on Sakai");
    return new LinkedList<Role>();
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 8 with Role

use of org.opencastproject.security.api.Role in project opencast by opencast.

the class JpaUserAndRoleProvider method updateGroupMembership.

/**
 * Updates a user's groups based on assigned roles
 *
 * @param user
 *          the user for whom groups should be updated
 * @throws NotFoundException
 */
private void updateGroupMembership(JpaUser user) {
    logger.debug("updateGroupMembership({}, roles={})", user.getUsername(), user.getRoles().size());
    List<String> internalGroupRoles = new ArrayList<String>();
    for (Role role : user.getRoles()) {
        if (Role.Type.GROUP.equals(role.getType()) || (Role.Type.INTERNAL.equals(role.getType()) && role.getName().startsWith(Group.ROLE_PREFIX))) {
            internalGroupRoles.add(role.getName());
        }
    }
    groupRoleProvider.updateGroupMembershipFromRoles(user.getUsername(), user.getOrganization().getId(), internalGroupRoles);
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) Role(org.opencastproject.security.api.Role) ArrayList(java.util.ArrayList)

Example 9 with Role

use of org.opencastproject.security.api.Role in project opencast by opencast.

the class JpaUserAndRoleProvider method filterRoles.

/**
 * Select only internal roles
 *
 * @param userRoles
 *          the user's full set of roles
 */
private Set<JpaRole> filterRoles(Set<Role> userRoles) {
    Set<JpaRole> roles = new HashSet<JpaRole>();
    for (Role role : userRoles) {
        if (Role.Type.INTERNAL.equals(role.getType()) && !role.getName().startsWith(Group.ROLE_PREFIX)) {
            JpaRole jpaRole = (JpaRole) role;
            roles.add(jpaRole);
        }
    }
    return roles;
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) Role(org.opencastproject.security.api.Role) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) HashSet(java.util.HashSet)

Example 10 with Role

use of org.opencastproject.security.api.Role in project opencast by opencast.

the class OrganizationRoleProvider method findRoles.

/**
 * @see org.opencastproject.security.api.RoleProvider#findRoles(String, Role.Target, int, int)
 */
@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    Organization organization = securityService.getOrganization();
    HashSet<Role> foundRoles = new HashSet<Role>();
    for (Iterator<Role> it = getRoles(); it.hasNext(); ) {
        Role role = it.next();
        // Anonymous roles are not relevant for adding to users or groups
        if ((target == Role.Target.USER) && role.getName().equals(organization.getAnonymousRole()))
            continue;
        if (like(role.getName(), query) || like(role.getDescription(), query))
            foundRoles.add(role);
    }
    return offsetLimitCollection(offset, limit, foundRoles).iterator();
}
Also used : Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) HashSet(java.util.HashSet)

Aggregations

Role (org.opencastproject.security.api.Role)48 JaxbRole (org.opencastproject.security.api.JaxbRole)21 User (org.opencastproject.security.api.User)21 HashSet (java.util.HashSet)17 JpaRole (org.opencastproject.security.impl.jpa.JpaRole)16 ArrayList (java.util.ArrayList)14 Organization (org.opencastproject.security.api.Organization)13 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)12 JaxbUser (org.opencastproject.security.api.JaxbUser)7 Test (org.junit.Test)6 JpaGroup (org.opencastproject.security.impl.jpa.JpaGroup)6 LinkedList (java.util.LinkedList)5 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)5 Path (javax.ws.rs.Path)4 RoleProvider (org.opencastproject.security.api.RoleProvider)4 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 JSONArray (org.json.simple.JSONArray)3 JSONObject (org.json.simple.JSONObject)3 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)3