Search in sources :

Example 26 with Organization

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

the class UserAndRoleDirectoryServiceImpl method loadUser.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.security.api.UserDirectoryService#loadUser(java.lang.String)
 */
@Override
public User loadUser(String userName) throws IllegalStateException {
    Organization org = securityService.getOrganization();
    if (org == null) {
        throw new IllegalStateException("No organization is set");
    }
    Object user = cache.getUnchecked(tuple(org.getId(), userName));
    if (user == nullToken) {
        cache.invalidate(tuple(org.getId(), userName));
        return null;
    } else {
        return (User) user;
    }
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser)

Example 27 with Organization

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

the class UserAndRoleDirectoryServiceImpl method findRoles.

@Override
@SuppressWarnings("unchecked")
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    Organization org = securityService.getOrganization();
    if (org == null)
        throw new IllegalStateException("No organization is set");
    // Find all roles from the role providers
    Stream<Role> roles = Stream.empty();
    for (RoleProvider roleProvider : roleProviders) {
        String providerOrgId = roleProvider.getOrganization();
        if (!ALL_ORGANIZATIONS.equals(providerOrgId) && !org.getId().equals(providerOrgId))
            continue;
        roles = roles.append(IteratorUtils.toList(roleProvider.findRoles(query, target, 0, 0))).sort(roleComparator);
    }
    return roles.drop(offset).apply(limit > 0 ? StreamOp.<Role>id().take(limit) : StreamOp.<Role>id()).iterator();
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) RoleProvider(org.opencastproject.security.api.RoleProvider)

Example 28 with Organization

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

the class UserAndRoleDirectoryServiceImpl method findUsers.

@Override
@SuppressWarnings("unchecked")
public Iterator<User> findUsers(String query, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    Organization org = securityService.getOrganization();
    if (org == null)
        throw new IllegalStateException("No organization is set");
    // Find all users from the user providers
    Stream<User> users = Stream.empty();
    for (final UserProvider userProvider : userProviders) {
        String providerOrgId = userProvider.getOrganization();
        if (!ALL_ORGANIZATIONS.equals(providerOrgId) && !org.getId().equals(providerOrgId))
            continue;
        users = users.append(IteratorUtils.toList(userProvider.findUsers(query, 0, 0))).sort(userComparator);
    }
    return users.drop(offset).apply(limit > 0 ? StreamOp.<User>id().take(limit) : StreamOp.<User>id()).iterator();
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) UserProvider(org.opencastproject.security.api.UserProvider)

Example 29 with Organization

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

the class UserAndRoleDirectoryServiceImpl method invalidate.

@Override
public void invalidate(String userName) {
    for (UserProvider userProvider : userProviders) {
        userProvider.invalidate(userName);
    }
    Organization org = securityService.getOrganization();
    if (org == null)
        throw new IllegalStateException("No organization is set");
    cache.invalidate(tuple(org.getId(), userName));
    logger.trace("Invalidated user {} from user directories", userName);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserProvider(org.opencastproject.security.api.UserProvider)

Example 30 with Organization

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

the class OpencastLdapAuthoritiesPopulator method addAuthorities.

/**
 * Add the specified authorities to the provided set
 *
 * @param authorities
 *          a set containing the authorities
 * @param values
 *          the values to add to the set
 */
private void addAuthorities(Set<GrantedAuthority> authorities, String[] values) {
    if (values != null) {
        Organization org = securityService.getOrganization();
        if (!organization.equals(org)) {
            throw new SecurityException(String.format("Current request belongs to the organization \"%s\". Expected \"%s\"", org.getId(), organization.getId()));
        }
        for (String value : values) {
            /*
         * Please note the prefix logic for roles:
         *
         * - Roles that start with any of the "exclude prefixes" are left intact
         * - In any other case, the "role prefix" is prepended to the roles read from LDAP
         *
         * This only applies to the prefix addition. The conversion to uppercase is independent from these
         * considerations
         */
            String authority;
            if (uppercase)
                authority = StringUtils.trimToEmpty(value).replaceAll(ROLE_CLEAN_REGEXP, ROLE_CLEAN_REPLACEMENT).toUpperCase();
            else
                authority = StringUtils.trimToEmpty(value).replaceAll(ROLE_CLEAN_REGEXP, ROLE_CLEAN_REPLACEMENT);
            // Ignore the empty parts
            if (!authority.isEmpty()) {
                // Check if this role is a group role and assign the groups appropriately
                List<Role> groupRoles;
                if (groupRoleProvider != null)
                    groupRoles = groupRoleProvider.getRolesForGroup(authority);
                else
                    groupRoles = Collections.emptyList();
                // Try to add the prefix if appropriate
                String prefix = this.prefix;
                if (!prefix.isEmpty()) {
                    boolean hasExcludePrefix = false;
                    for (String excludePrefix : excludedPrefixes) {
                        if (authority.startsWith(excludePrefix)) {
                            hasExcludePrefix = true;
                            break;
                        }
                    }
                    if (hasExcludePrefix)
                        prefix = "";
                }
                authority = (prefix + authority).replaceAll(ROLE_CLEAN_REGEXP, ROLE_CLEAN_REPLACEMENT);
                debug("Parsed LDAP role \"{}\" to role \"{}\"", value, authority);
                if (!groupRoles.isEmpty()) {
                    // The authority is a group role
                    debug("Found group for the group with group role \"{}\"", authority);
                    for (Role role : groupRoles) {
                        authorities.add(new SimpleGrantedAuthority(role.getName()));
                        logger.debug("\tAdded role from role \"{}\"'s group: {}", authority, role);
                    }
                }
                // Finally, add the authority itself
                authorities.add(new SimpleGrantedAuthority(authority));
            } else {
                debug("Found empty authority. Ignoring...");
            }
        }
    }
}
Also used : Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization)

Aggregations

Organization (org.opencastproject.security.api.Organization)135 User (org.opencastproject.security.api.User)60 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 NotFoundException (org.opencastproject.util.NotFoundException)43 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)29 SecurityService (org.opencastproject.security.api.SecurityService)29 IOException (java.io.IOException)24 Before (org.junit.Before)24 ArrayList (java.util.ArrayList)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)22 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)22 JaxbRole (org.opencastproject.security.api.JaxbRole)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 JaxbUser (org.opencastproject.security.api.JaxbUser)20 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 File (java.io.File)18 HashMap (java.util.HashMap)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)17 Test (org.junit.Test)15