Search in sources :

Example 26 with Role

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

the class GroupMessageReceiverImpl method execute.

@Override
protected void execute(GroupItem groupItem) {
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(groupItem.getType()) {
        case Update:
            org.opencastproject.security.api.Group jaxbGroup = groupItem.getGroup();
            logger.debug("Update the group with id '{}', name '{}', description '{}', organization '{}', roles '{}', members '{}'", jaxbGroup.getGroupId(), jaxbGroup.getName(), jaxbGroup.getDescription(), jaxbGroup.getOrganization(), jaxbGroup.getRoles(), jaxbGroup.getMembers());
            try {
                Group group = GroupIndexUtils.getOrCreate(jaxbGroup.getGroupId(), organization, user, getSearchIndex());
                group.setName(jaxbGroup.getName());
                group.setDescription(jaxbGroup.getDescription());
                group.setMembers(jaxbGroup.getMembers());
                Set<String> roles = new HashSet<>();
                for (Role role : jaxbGroup.getRoles()) {
                    roles.add(role.getName());
                }
                group.setRoles(roles);
                getSearchIndex().addOrUpdate(group);
            } catch (SearchIndexException e) {
                logger.error("Error storing the group {} to the search index: {}", jaxbGroup.getGroupId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            break;
        case Delete:
            logger.debug("Received Delete Group Event {}", groupItem.getGroupId());
            // Remove the group from the search index
            try {
                getSearchIndex().delete(Group.DOCUMENT_TYPE, groupItem.getGroupId().concat(organization));
                logger.debug("Group {} removed from external search index", groupItem.getGroupId());
            } catch (SearchIndexException e) {
                logger.error("Error deleting the group {} from the search index: {}", groupItem.getGroupId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of GroupItem");
    }
}
Also used : Role(org.opencastproject.security.api.Role) Group(org.opencastproject.index.service.impl.index.group.Group) User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) HashSet(java.util.HashSet)

Example 27 with Role

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

the class SeriesServiceSolrIndex method appendAuthorization.

/**
 * Appends the authorization information to the solr query string
 *
 * @param sb
 *          the {@link StringBuilder} containing the query
 * @param forEdit
 *          if this query should return only series available to the current user for editing
 *
 * @return the appended {@link StringBuilder}
 */
protected StringBuilder appendAuthorization(StringBuilder sb, boolean forEdit) {
    User currentUser = securityService.getUser();
    Organization currentOrg = securityService.getOrganization();
    if (!currentUser.hasRole(currentOrg.getAdminRole()) && !currentUser.hasRole(GLOBAL_ADMIN_ROLE)) {
        List<String> roleList = new ArrayList<String>();
        for (Role role : currentUser.getRoles()) {
            roleList.add(role.getName());
        }
        String[] roles = roleList.toArray(new String[roleList.size()]);
        if (forEdit) {
            appendAnd(sb, SolrFields.ACCESS_CONTROL_EDIT, roles);
        } else if (roles.length > 0) {
            sb.append(" AND (");
            append(sb, "", SolrFields.ACCESS_CONTROL_CONTRIBUTE, roles);
            sb.append(" OR ");
            append(sb, "", SolrFields.ACCESS_CONTROL_READ, roles);
            sb.append(")");
        }
    }
    return sb;
}
Also used : Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) ArrayList(java.util.ArrayList)

Example 28 with Role

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

the class ResourceServlet method isUserAllowed.

protected boolean isUserAllowed(File aclFile) throws SAXException, IOException, XPathExpressionException {
    Document aclDoc = builder.parse(aclFile);
    XPath xPath = XPathFactory.newInstance().newXPath();
    NodeList roles = (NodeList) xPath.evaluate("//*[local-name() = 'role']", aclDoc, XPathConstants.NODESET);
    for (int i = 0; i < roles.getLength(); i++) {
        Node role = roles.item(i);
        for (Role userRole : securityService.getUser().getRoles()) {
            if (userRole.getName().equals(role.getTextContent())) {
                return true;
            }
        }
    }
    return false;
}
Also used : XPath(javax.xml.xpath.XPath) Role(org.opencastproject.security.api.Role) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 29 with Role

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

the class JpaUserAndRoleProvider 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)
        return roles;
    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) JpaUser(org.opencastproject.security.impl.jpa.JpaUser) ArrayList(java.util.ArrayList)

Example 30 with Role

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

the class OrganizationRoleProvider method getRoles.

/**
 * @see org.opencastproject.security.api.RoleProvider#getRoles()
 */
@Override
public Iterator<Role> getRoles() {
    Organization organization = securityService.getOrganization();
    List<Role> roles = new ArrayList<Role>();
    // The GLOBAL_ADMIN_ROLE is provided by the InMemoryUserAndRoleProvider
    if (!GLOBAL_ADMIN_ROLE.equals(organization.getAdminRole())) {
        roles.add(new JaxbRole(organization.getAdminRole(), JaxbOrganization.fromOrganization(organization), "", Type.INTERNAL));
    }
    roles.add(new JaxbRole(organization.getAnonymousRole(), JaxbOrganization.fromOrganization(organization), "", Type.SYSTEM));
    return roles.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) ArrayList(java.util.ArrayList)

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