1 23 24 package org.apache.slide.webdav.method.report; 25 26 import java.io.IOException ; 27 import java.util.Enumeration ; 28 import java.util.List ; 29 30 import org.apache.slide.common.NamespaceAccessToken; 31 import org.apache.slide.common.PropertyParseException; 32 import org.apache.slide.common.RequestedProperties; 33 import org.apache.slide.common.RequestedPropertiesImpl; 34 import org.apache.slide.common.ServiceAccessException; 35 import org.apache.slide.common.SlideException; 36 import org.apache.slide.common.SlideToken; 37 import org.apache.slide.content.NodeProperty; 38 import org.apache.slide.content.NodeRevisionDescriptor; 39 import org.apache.slide.content.NodeRevisionDescriptors; 40 import org.apache.slide.content.NodeRevisionNumber; 41 import org.apache.slide.security.NodePermission; 42 import org.apache.slide.structure.SubjectNode; 43 import org.apache.slide.webdav.WebdavServletConfig; 44 import org.apache.slide.webdav.util.AclConstants; 45 import org.apache.slide.webdav.util.PreconditionViolationException; 46 import org.apache.slide.webdav.util.ViolatedPrecondition; 47 import org.apache.slide.webdav.util.WebdavStatus; 48 import org.jdom.Element; 49 50 51 55 public class AclPrincipalPropSetReport extends AbstractReport implements AclConstants { 56 57 private RequestedProperties requestedProperties = null; 58 59 68 public AclPrincipalPropSetReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String slideContextPath) { 69 super(slideToken, token, config, slideContextPath); 70 } 71 72 80 public void init(String resourcePath, Element aclPrincipalPropSetElm) throws PreconditionViolationException { 81 if (aclPrincipalPropSetElm.getChildren().size() == 0) { 82 throw new PreconditionViolationException( 83 new ViolatedPrecondition("at-least-one-child-element", 84 WebdavStatus.SC_BAD_REQUEST, 85 "DAV:acl-principal-prop-set element must have at least one child"), 86 resourcePath 87 ); 88 } 89 List propElmL = aclPrincipalPropSetElm.getChildren(E_PROP, DNSP); 90 if (propElmL.size() > 1) { 91 throw new PreconditionViolationException( 92 new ViolatedPrecondition("at-most-one-prop-element", 93 WebdavStatus.SC_BAD_REQUEST, 94 "DAV:acl-principal-prop-set element must have at most one DAV:prop child"), 95 resourcePath 96 ); 97 } 98 99 if (propElmL.size() == 1) { 100 Element propElm = (Element)propElmL.get(0); 101 try { 102 this.requestedProperties = new RequestedPropertiesImpl(propElm); 103 } 104 catch (PropertyParseException e) { 105 throw new PreconditionViolationException( 106 new ViolatedPrecondition("invalid-prop", 107 WebdavStatus.SC_BAD_REQUEST, 108 e.getMessage()), 109 resourcePath 110 ); 111 } 112 } 113 } 114 115 125 public void execute(String resourcePath, Element multistatusElm, int depth) throws SlideException, IOException { 126 NodeRevisionDescriptors nrds = content.retrieve(slideToken, resourcePath); 127 NodeRevisionDescriptor nrd = content.retrieve(slideToken, nrds); 128 Enumeration permissions = security.enumeratePermissions(slideToken, resourcePath, true); 129 while (permissions != null && permissions.hasMoreElements()) { 130 NodePermission p = (NodePermission)permissions.nextElement(); 131 SubjectNode principalNode = SubjectNode.getSubjectNode(p.getSubjectUri()); 132 String principalPath = getPrincipalPath(principalNode, nrd); 133 if (principalPath != null) { 134 multistatusElm.addContent(getResponseElement(slideToken, principalPath, new NodeRevisionNumber(), requestedProperties)); 135 } 136 } 137 } 138 139 private String getPrincipalPath(SubjectNode principalNode, NodeRevisionDescriptor nrd) throws SlideException { 140 if (principalNode.equals(SubjectNode.ALL) 141 || principalNode.equals(SubjectNode.SELF) 142 || principalNode.equals(SubjectNode.AUTHENTICATED) 143 || principalNode.equals(SubjectNode.UNAUTHENTICATED) 144 ) { 145 return null; 146 } 147 else if (principalNode.equals(SubjectNode.OWNER)) { 148 NodeProperty ownerProp = nrd.getProperty(P_OWNER); 149 if (ownerProp != null) { 150 return token.getNamespaceConfig().getUsersPath()+"/"+ownerProp.getValue(); 151 } 152 else { 153 return null; 154 } 155 } 156 else { 157 return principalNode.getUri(); 158 } 159 } 160 161 168 public void checkPreconditions(String resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException { 169 if (depth != 0) { 170 throw new PreconditionViolationException( 171 new ViolatedPrecondition("depth-must-be-zero", 172 WebdavStatus.SC_BAD_REQUEST, 173 "This report is only defined for depth=0."), 174 resourcePath 175 ); 176 } 177 } 178 } 179 | Popular Tags |