Search in sources :

Example 1 with Role

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

the class UsersListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) {
    Map<String, String> usersList = new HashMap<String, String>();
    int offset = 0;
    int limit = 0;
    if (query != null) {
        if (query.getLimit().isSome())
            limit = query.getLimit().get();
        if (query.getOffset().isSome())
            offset = query.getOffset().get();
    }
    Iterator<User> users = userDirectoryService.findUsers("%", offset, limit);
    while (users.hasNext()) {
        User u = users.next();
        if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) {
            usersList.put(u.getEmail(), u.getEmail());
        } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) {
            usersList.put(u.getUsername(), u.getUsername());
        } else if (USERDIRECTORY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) {
            usersList.put(u.getProvider(), u.getProvider());
        } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) {
            usersList.put(u.getName(), u.getName());
        } else if (INVERSE.equals(listName) || INVERSE_WITH_EMAIL.equals(listName) || INVERSE_WITH_USERNAME.equals(listName)) {
            usersList.put(createDisplayName(u, listName), u.getUsername());
        } else if (DEFAULT.equals(listName) || DEFAULT_WITH_EMAIL.equals(listName) || DEFAULT_WITH_USERNAME.equals(listName)) {
            usersList.put(u.getUsername(), createDisplayName(u, listName));
        } else if (ROLE.equals(listName) && u.getRoles().size() > 0) {
            for (Role role : u.getRoles()) {
                usersList.put(role.getName(), role.getName());
            }
        }
    }
    return usersList;
}
Also used : Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) HashMap(java.util.HashMap)

Example 2 with Role

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

the class RolesListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) {
    // Preserve the ordering of roles from the providers
    Map<String, String> rolesList = new LinkedHashMap<String, String>();
    int offset = 0;
    int limit = 0;
    if (query != null) {
        if (query.getLimit().isSome())
            limit = query.getLimit().get();
        if (query.getOffset().isSome())
            offset = query.getOffset().get();
    }
    String queryString = "%";
    if (query.hasFilter(ROLE_QUERY_KEY)) {
        queryString = query.getFilter(ROLE_QUERY_KEY).getValue().get() + "%";
    }
    Role.Target target = Role.Target.ALL;
    if (query.hasFilter(ROLE_TARGET_KEY)) {
        String targetString = (String) query.getFilter(ROLE_TARGET_KEY).getValue().get();
        try {
            target = Role.Target.valueOf(targetString);
        } catch (Exception e) {
            logger.warn("Invalid target filter value {}", targetString);
        }
    }
    Iterator<Role> roles = roleDirectoryService.findRoles(queryString, target, offset, limit);
    while (roles.hasNext()) {
        Role r = roles.next();
        rolesList.put(r.getName(), r.getType().toString());
    }
    return rolesList;
}
Also used : Role(org.opencastproject.security.api.Role) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Role

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

the class ConfigurableLoginHandler method getRoles.

/**
 * @see org.opencastproject.security.api.RoleProvider#getRoles()
 */
@Override
public Iterator<Role> getRoles() {
    JaxbOrganization organization = JaxbOrganization.fromOrganization(securityService.getOrganization());
    HashSet<Role> roles = new HashSet<Role>();
    roles.add(new JaxbRole(roleFederationMember, organization));
    roles.add(new JaxbRole(organization.getAnonymousRole(), organization));
    return roles.iterator();
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) HashSet(java.util.HashSet)

Example 4 with Role

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

the class JpaUserReferenceProvider method getRolesForUser.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.security.api.RoleProvider#getRolesForUser(String)
 */
@Override
public List<Role> getRolesForUser(String userName) {
    ArrayList<Role> roles = new ArrayList<Role>();
    User user = loadUser(userName);
    if (user != null)
        roles.addAll(user.getRoles());
    return roles;
}
Also used : JpaRole(org.opencastproject.security.impl.jpa.JpaRole) Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList)

Example 5 with Role

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

the class UserIdRoleProvider 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");
    // These roles are not meaningful for users/groups
    if (target == Role.Target.USER) {
        return Collections.emptyIterator();
    }
    logger.debug("findRoles(query={} offset={} limit={})", query, offset, limit);
    HashSet<Role> foundRoles = new HashSet<Role>();
    Organization organization = securityService.getOrganization();
    // Return authenticated user role if it matches the query pattern
    if (like(ROLE_USER, query)) {
        foundRoles.add(new JaxbRole(ROLE_USER, JaxbOrganization.fromOrganization(organization), "The authenticated user role", Role.Type.SYSTEM));
    }
    // (iterating through users may be slow)
    if (!"%".equals(query) && !query.startsWith(userRolePrefix)) {
        return foundRoles.iterator();
    }
    String userQuery = "%";
    if (query.startsWith(userRolePrefix)) {
        userQuery = query.substring(userRolePrefix.length());
    }
    Iterator<User> users = userDirectoryService.findUsers(userQuery, offset, limit);
    while (users.hasNext()) {
        User u = users.next();
        // We exclude the digest user, but then add the global ROLE_USER above
        if (!"system".equals(u.getProvider())) {
            foundRoles.add(new JaxbRole(getUserIdRole(u.getUsername()), JaxbOrganization.fromOrganization(u.getOrganization()), "User id role", Role.Type.SYSTEM));
        }
    }
    return 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) JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) 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