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