Search in sources :

Example 56 with JaxbRole

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

the class JpaGroupRoleProvider method findRoles.

/**
 * {@inheritDoc}
 *
 * @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");
    String orgId = securityService.getOrganization().getId();
    // Here we want to return only the ROLE_GROUP_ names, not the roles associated with a group
    List<JpaGroup> groups = UserDirectoryPersistenceUtil.findGroups(orgId, 0, 0, emf);
    List<Role> roles = new ArrayList<Role>();
    for (JpaGroup group : groups) {
        if (like(group.getRole(), query))
            roles.add(new JaxbRole(group.getRole(), JaxbOrganization.fromOrganization(group.getOrganization()), "", Role.Type.GROUP));
    }
    Set<Role> result = new HashSet<Role>();
    int i = 0;
    for (Role entry : roles) {
        if (limit != 0 && result.size() >= limit)
            break;
        if (i >= offset)
            result.add(entry);
        i++;
    }
    return result.iterator();
}
Also used : JpaGroup(org.opencastproject.security.impl.jpa.JpaGroup) JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) JpaRole(org.opencastproject.security.impl.jpa.JpaRole) JaxbRole(org.opencastproject.security.api.JaxbRole) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 57 with JaxbRole

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

the class MoodleUserProviderInstance method findRoles.

/**
 * {@inheritDoc}
 * <p>
 * We search for COURSEID, COURSEID_Learner, COURSEID_Instructor
 *
 * @see org.opencastproject.security.api.RoleProvider#findRoles(java.lang.String, org.opencastproject.security.api.Role.Target, int, int)
 */
@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    // Don't return roles for users or groups
    if (target == Role.Target.USER)
        return Collections.emptyIterator();
    boolean exact = true;
    boolean ltirole = false;
    if (query.endsWith("%")) {
        exact = false;
        query = query.substring(0, query.length() - 1);
    }
    if (query.isEmpty())
        return Collections.emptyIterator();
    // Verify that role name ends with LEARNER_ROLE_SUFFIX or INSTRUCTOR_ROLE_SUFFIX
    if (exact && !query.endsWith("_" + LEARNER_ROLE_SUFFIX) && !query.endsWith("_" + INSTRUCTOR_ROLE_SUFFIX))
        return Collections.emptyIterator();
    // Extract moodle course id
    String moodleCourseId = query;
    if (query.endsWith("_" + LEARNER_ROLE_SUFFIX)) {
        moodleCourseId = query.substring(0, query.lastIndexOf("_" + LEARNER_ROLE_SUFFIX));
        ltirole = true;
    } else if (query.endsWith("_" + INSTRUCTOR_ROLE_SUFFIX)) {
        moodleCourseId = query.substring(0, query.lastIndexOf("_" + INSTRUCTOR_ROLE_SUFFIX));
        ltirole = true;
    }
    // Check if course matches pattern
    try {
        if ((coursePattern != null) && !moodleCourseId.matches(coursePattern)) {
            logger.debug("verify course {} failed regexp {}", moodleCourseId, coursePattern);
            return Collections.emptyIterator();
        }
    } catch (PatternSyntaxException e) {
        logger.warn("Invalid regular expression for course pattern {} - disabling checks", coursePattern);
        coursePattern = null;
    }
    // Roles list
    List<Role> roles = new LinkedList<>();
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
    if (ltirole) {
        // Query is for a Course ID and an LTI role (Instructor/Learner)
        roles.add(new JaxbRole(query, jaxbOrganization, "Moodle Site Role", Role.Type.EXTERNAL));
    } else {
        // Course ID - return both roles
        roles.add(new JaxbRole(moodleCourseId + "_" + INSTRUCTOR_ROLE_SUFFIX, jaxbOrganization, "Moodle Course Instructor Role", Role.Type.EXTERNAL));
        roles.add(new JaxbRole(moodleCourseId + "_" + LEARNER_ROLE_SUFFIX, jaxbOrganization, "Moodle Course Learner Role", Role.Type.EXTERNAL));
    }
    return roles.iterator();
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) LinkedList(java.util.LinkedList) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 58 with JaxbRole

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

the class SakaiUserProviderInstance method findUsers.

@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    if (query.endsWith("%")) {
        query = query.substring(0, query.length() - 1);
    }
    if (query.isEmpty()) {
        return Collections.emptyIterator();
    }
    // Verify if a user exists (non-wildcard searches only)
    if (!verifySakaiUser(query)) {
        return Collections.emptyIterator();
    }
    List<User> users = new LinkedList<User>();
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
    JaxbUser queryUser = new JaxbUser(query, PROVIDER_NAME, jaxbOrganization, new HashSet<JaxbRole>());
    users.add(queryUser);
    return users.iterator();
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) LinkedList(java.util.LinkedList)

Example 59 with JaxbRole

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

the class SakaiUserProviderInstance method findRoles.

@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    // We search for SITEID, SITEID_Learner, SITEID_Instructor
    logger.debug("findRoles(query=" + query + " offset=" + offset + " limit=" + limit + ")");
    // Don't return roles for users or groups
    if (target == Role.Target.USER) {
        return Collections.emptyIterator();
    }
    boolean exact = true;
    boolean ltirole = false;
    if (query.endsWith("%")) {
        exact = false;
        query = query.substring(0, query.length() - 1);
    }
    if (query.isEmpty()) {
        return Collections.emptyIterator();
    }
    // Verify that role name ends with LTI_LEARNER_ROLE or LTI_INSTRUCTOR_ROLE
    if (exact && !query.endsWith("_" + LTI_LEARNER_ROLE) && !query.endsWith("_" + LTI_INSTRUCTOR_ROLE)) {
        return Collections.emptyIterator();
    }
    String sakaiSite = null;
    if (query.endsWith("_" + LTI_LEARNER_ROLE)) {
        sakaiSite = query.substring(0, query.lastIndexOf("_" + LTI_LEARNER_ROLE));
        ltirole = true;
    } else if (query.endsWith("_" + LTI_INSTRUCTOR_ROLE)) {
        sakaiSite = query.substring(0, query.lastIndexOf("_" + LTI_INSTRUCTOR_ROLE));
        ltirole = true;
    }
    if (!ltirole) {
        sakaiSite = query;
    }
    if (!verifySakaiSite(sakaiSite)) {
        return Collections.emptyIterator();
    }
    // Roles list
    List<Role> roles = new LinkedList<Role>();
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
    if (ltirole) {
        // Query is for a Site ID and an LTI role (Instructor/Learner)
        roles.add(new JaxbRole(query, jaxbOrganization, "Sakai Site Role", Role.Type.EXTERNAL));
    } else {
        // Site ID - return both roles
        roles.add(new JaxbRole(sakaiSite + "_" + LTI_INSTRUCTOR_ROLE, jaxbOrganization, "Sakai Site Instructor Role", Role.Type.EXTERNAL));
        roles.add(new JaxbRole(sakaiSite + "_" + LTI_LEARNER_ROLE, jaxbOrganization, "Sakai Site Learner Role", Role.Type.EXTERNAL));
    }
    return roles.iterator();
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) LinkedList(java.util.LinkedList)

Example 60 with JaxbRole

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

the class InMemoryUserAndRoleProvider method createSystemUsers.

/**
 * Creates the system digest user.
 */
private void createSystemUsers() {
    for (Organization organization : orgDirectoryService.getOrganizations()) {
        JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
        // Create the digest auth user with a clear text password
        Set<JaxbRole> roleList = new HashSet<JaxbRole>();
        for (String roleName : SecurityConstants.GLOBAL_SYSTEM_ROLES) {
            roleList.add(new JaxbRole(roleName, jaxbOrganization));
        }
        // Create the digest user
        if (digestUsername != null && digestUserPass != null) {
            logger.info("Creating the system digest user");
            User digestUser = new JaxbUser(digestUsername, digestUserPass, DIGEST_USER_NAME, null, getName(), true, jaxbOrganization, roleList);
            inMemoryUsers.add(digestUser);
        }
    }
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) HashSet(java.util.HashSet)

Aggregations

JaxbRole (org.opencastproject.security.api.JaxbRole)66 JaxbUser (org.opencastproject.security.api.JaxbUser)53 User (org.opencastproject.security.api.User)45 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)39 SecurityService (org.opencastproject.security.api.SecurityService)39 Before (org.junit.Before)30 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)25 HashSet (java.util.HashSet)18 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 Organization (org.opencastproject.security.api.Organization)17 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)17 Test (org.junit.Test)14 Role (org.opencastproject.security.api.Role)13 Workspace (org.opencastproject.workspace.api.Workspace)13 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)11 URI (java.net.URI)10 BundleContext (org.osgi.framework.BundleContext)10 ComponentContext (org.osgi.service.component.ComponentContext)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9