Search in sources :

Example 1 with SupportedPrivilege

use of org.apache.jackrabbit.webdav.security.SupportedPrivilege in project jackrabbit by apache.

the class RepositoryServiceImpl method internalGetPrivilegeDefinitions.

private PrivilegeDefinition[] internalGetPrivilegeDefinitions(SessionInfo sessionInfo, String uri) throws RepositoryException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
    HttpPropfind request = null;
    try {
        request = new HttpPropfind(uri, nameSet, DEPTH_0);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        MultiStatusResponse[] mresponses = request.getResponseBodyAsMultiStatus(response).getResponses();
        if (mresponses.length < 1) {
            throw new PathNotFoundException("Unable to retrieve privileges definitions.");
        }
        DavPropertyName displayName = SecurityConstants.SUPPORTED_PRIVILEGE_SET;
        DavProperty<?> p = mresponses[0].getProperties(DavServletResponse.SC_OK).get(displayName);
        if (p == null) {
            return new PrivilegeDefinition[0];
        } else {
            // build PrivilegeDefinition(s) from the supported-privileges dav property
            Map<Name, SupportedPrivilege> spMap = new HashMap<Name, SupportedPrivilege>();
            fillSupportedPrivilegeMap(new SupportedPrivilegeSetProperty(p).getValue(), spMap, getNameFactory());
            List<PrivilegeDefinition> pDefs = new ArrayList<PrivilegeDefinition>();
            for (Name privilegeName : spMap.keySet()) {
                SupportedPrivilege sp = spMap.get(privilegeName);
                Set<Name> aggrnames = null;
                SupportedPrivilege[] aggregates = sp.getSupportedPrivileges();
                if (aggregates != null && aggregates.length > 0) {
                    aggrnames = new HashSet<Name>();
                    for (SupportedPrivilege aggregate : aggregates) {
                        Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName());
                        aggrnames.add(aggregateName);
                    }
                }
                PrivilegeDefinition def = new PrivilegeDefinitionImpl(privilegeName, sp.isAbstract(), aggrnames);
                pDefs.add(def);
            }
            return pDefs.toArray(new PrivilegeDefinition[pDefs.size()]);
        }
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name) HttpPropfind(org.apache.jackrabbit.webdav.client.methods.HttpPropfind) PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) PathNotFoundException(javax.jcr.PathNotFoundException) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege)

Example 2 with SupportedPrivilege

use of org.apache.jackrabbit.webdav.security.SupportedPrivilege in project jackrabbit by apache.

the class JcrSupportedPrivilegesProperty method asDavProperty.

/**
     * Calculated the supported privileges at {@code absPath} and build a
     * {@link org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty}
     * from the result.
     *
     * @return a new {@code SupportedPrivilegeSetProperty} property.
     * @throws RepositoryException
     */
public SupportedPrivilegeSetProperty asDavProperty() throws RepositoryException {
    if (privileges.isEmpty()) {
        AccessControlManager acMgr = session.getAccessControlManager();
        privileges.addAll(Arrays.asList(acMgr.getSupportedPrivileges(absPath)));
    }
    for (Privilege p : privileges) {
        if (!aggregated.contains(p.getName())) {
            createSupportedPrivilege(p);
        }
    }
    return new SupportedPrivilegeSetProperty(supportedPrivileges.values().toArray(new SupportedPrivilege[supportedPrivileges.size()]));
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) SupportedPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Privilege(javax.jcr.security.Privilege)

Example 3 with SupportedPrivilege

use of org.apache.jackrabbit.webdav.security.SupportedPrivilege in project jackrabbit by apache.

the class JcrSupportedPrivilegesProperty method createSupportedPrivilege.

private SupportedPrivilege createSupportedPrivilege(Privilege privilege) throws RepositoryException {
    String privilegeName = privilege.getName();
    String localName = Text.getLocalName(privilegeName);
    String prefix = Text.getNamespacePrefix(privilegeName);
    Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
    org.apache.jackrabbit.webdav.security.Privilege davPrivilege = org.apache.jackrabbit.webdav.security.Privilege.getPrivilege(localName, ns);
    SupportedPrivilege[] aggregates = (privilege.isAggregate()) ? getDeclaredAggregates(privilege) : null;
    SupportedPrivilege sp = new SupportedPrivilege(davPrivilege, null, null, privilege.isAbstract(), aggregates);
    if (!aggregated.contains(privilegeName)) {
        supportedPrivileges.put(privilegeName, sp);
    }
    return sp;
}
Also used : SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Namespace(org.apache.jackrabbit.webdav.xml.Namespace)

Example 4 with SupportedPrivilege

use of org.apache.jackrabbit.webdav.security.SupportedPrivilege in project jackrabbit by apache.

the class RepositoryServiceImpl method fillSupportedPrivilegeMap.

private static void fillSupportedPrivilegeMap(List<SupportedPrivilege> sps, Map<Name, SupportedPrivilege> spMap, NameFactory nameFactory) throws NamespaceException, IllegalNameException {
    for (SupportedPrivilege sp : sps) {
        Privilege p = sp.getPrivilege();
        Name privName = nameFactory.create(p.getNamespace().getURI(), p.getName());
        spMap.put(privName, sp);
        List<SupportedPrivilege> agg = Arrays.asList(sp.getSupportedPrivileges());
        if (!agg.isEmpty()) {
            fillSupportedPrivilegeMap(agg, spMap, nameFactory);
        }
    }
}
Also used : SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Privilege(org.apache.jackrabbit.webdav.security.Privilege) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) Name(org.apache.jackrabbit.spi.Name)

Aggregations

SupportedPrivilege (org.apache.jackrabbit.webdav.security.SupportedPrivilege)4 Name (org.apache.jackrabbit.spi.Name)2 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)2 SupportedPrivilegeSetProperty (org.apache.jackrabbit.webdav.security.SupportedPrivilegeSetProperty)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 RepositoryException (javax.jcr.RepositoryException)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 Privilege (javax.jcr.security.Privilege)1 HttpResponse (org.apache.http.HttpResponse)1 PrivilegeDefinition (org.apache.jackrabbit.spi.PrivilegeDefinition)1 PrivilegeDefinitionImpl (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl)1 DavException (org.apache.jackrabbit.webdav.DavException)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 HttpPropfind (org.apache.jackrabbit.webdav.client.methods.HttpPropfind)1 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)1 Privilege (org.apache.jackrabbit.webdav.security.Privilege)1