Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 
 
 package org.exoplatform.services.jcr.webdav.command.acl;
 
 
 import java.util.List;
 
Created by The eXo Platform SAS. Utility class to simplify operations with ACL properties of JCR nodes for PROPFIND method.

Author(s):
Vitaliy Gulyy
Version:
$
 
 
 public class ACLProperties
 {
   
Defines the name of the element corresponding to a protected property that specifies the list of access control entries. More details can be found here.
 
    public final static QName ACL = new QName("DAV:""acl");

   
Defines the name of the element corresponding to a property that the set of privileges to be either granted or denied to a single principal. More details can be found here.
 
    public final static QName ACE = new QName("DAV:""ace");

   
Defines the name of the element corresponding to a property which identifies the principal to which this ACE applies. More details can be found here and here.
 
    public final static QName PRINCIPAL = new QName("DAV:""principal");

   
Defines the name of the element corresponding to a property that can be either an aggregate privilege that contains the entire set of privileges that can be applied to the resource or an aggregate principal that contains the entire set of principals. More details can be found here.
 
    public final static QName ALL = new QName("DAV:""all");

   
Defines the name of the element corresponding to a property which is used to uniquely identify a principal. More details can be found here.
 
    public final static QName HREF = new QName("DAV:""href");

   
Defines the name of the element containing privilege's name. More details can be found here.
 
    public final static QName PRIVILEGE = new QName("DAV:""privilege");

   
Defines the name of the element containing privileges to be granted. More details can be found here.
 
    public final static QName GRANT = new QName("DAV:""grant");

   
Defines the name of the element containing privileges to be denied. More details can be found here.
   public final static QName DENY = new QName("DAV:""deny");

   
Defines the name of the element corresponding to write privilege which in current implementation aggregate: ADD_NODE, SET_PROPERTY, REMOVE permissions. More details can be found here.
   public final static QName WRITE = new QName("DAV:""write");

   
Defines the name of the element corresponding to read privilege which in current implementation aggregate: READ permission. More details can be found here.
   public final static QName READ = new QName("DAV:""read");

   
Gets org.exoplatform.services.jcr.access.AccessControlList and transform it to DAV:acl property view represented by a org.exoplatform.common.util.HierarchicalProperty instance.

Parameters:
node - org.exoplatform.services.jcr.impl.core.NodeImpl from which we are to get an ACL
Returns:
HierarchicalProperty - tree like structure corresponding to an DAV:acl property
Throws:
javax.jcr.RepositoryException
   public static HierarchicalProperty getACL(NodeImpl nodethrows RepositoryException
   {
      HierarchicalProperty property = new HierarchicalProperty();
      AccessControlList acl = node.getACL();
      HashMap<StringList<String>> principals = new HashMap<StringList<String>>();
      List<AccessControlEntryentryList = acl.getPermissionEntries();
      for (AccessControlEntry entry : entryList)
      {
         String principal = entry.getIdentity();
         String grant = entry.getPermission();
         List<StringgrantList = principals.get(principal);
         if (grantList == null)
         {
            grantList = new ArrayList<String>();
            principals.put(principalgrantList);
         }
         grantList.add(grant);
      }
      Iterator<StringprincipalIter = principals.keySet().iterator();
      while (principalIter.hasNext())
      {
         HierarchicalProperty aceProperty = new HierarchicalProperty();
         String curPrincipal = principalIter.next();
         aceProperty.addChild(getPrincipalProperty(curPrincipal));
         aceProperty.addChild(getGrantProperty(principals.get(curPrincipal)));
         property.addChild(aceProperty);
      }
      return property;
   }

   
Transform owner got from node's org.exoplatform.services.jcr.access.AccessControlList to tree like org.exoplatform.common.util.HierarchicalProperty instance to use in PROPFIND response body

Parameters:
node
Returns:
org.exoplatform.common.util.HierarchicalProperty representation of node owner
Throws:
javax.jcr.RepositoryException
   public static HierarchicalProperty getOwner(NodeImpl nodethrows RepositoryException
   {
      HierarchicalProperty href = new HierarchicalProperty(new QName("DAV:""href"));
      href.setValue(node.getACL().getOwner());
      ownerProperty.addChild(href);
      return ownerProperty;
   }
   private static HierarchicalProperty getPrincipalProperty(String principal)
   {
      HierarchicalProperty principalProperty = new HierarchicalProperty();
      if (..equals(principal))
      {
         HierarchicalProperty all = new HierarchicalProperty();
         principalProperty.addChild(all);
      }
      else
      {
         HierarchicalProperty href = new HierarchicalProperty();
         href.setValue(principal);
         principalProperty.addChild(href);
      }
      return principalProperty;
   }
   private static HierarchicalProperty getGrantProperty(List<StringgrantList)
   {
      HierarchicalProperty grant = new HierarchicalProperty();
      if (grantList.contains(.) || grantList.contains(.)
         || grantList.contains(.))
      {
         HierarchicalProperty privilege = new HierarchicalProperty();
         privilege.addChild(new HierarchicalProperty());
         grant.addChild(privilege);
      }
      if (grantList.contains(.))
      {
         HierarchicalProperty privilege = new HierarchicalProperty();
         privilege.addChild(new HierarchicalProperty());
         grant.addChild(privilege);
      }
      return grant;
   }
New to GrepCode? Check out our FAQ X