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();
}
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();
}
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();
}
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();
}
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);
}
}
}
Aggregations