1 23 24 package org.apache.webdav.lib.methods; 25 26 import java.io.IOException ; 27 import java.util.Enumeration ; 28 import java.util.Vector ; 29 import org.apache.commons.httpclient.HttpConnection; 30 import org.apache.commons.httpclient.HttpException; 31 import org.apache.commons.httpclient.HttpState; 32 import org.apache.webdav.lib.Ace; 33 import org.apache.webdav.lib.Privilege; 34 import org.apache.webdav.lib.PropertyName; 35 import org.apache.webdav.lib.util.XMLPrinter; 36 37 41 public class AclMethod 42 extends XMLResponseMethodBase { 43 44 45 47 48 50 51 54 public AclMethod() { 55 } 56 57 58 61 public AclMethod(String path) { 62 super(path); 63 } 64 65 66 68 69 protected Vector aces = new Vector (); 70 71 72 74 75 80 public void addAce(Ace ace) { 81 checkNotUsed(); 82 aces.addElement(ace); 83 } 84 85 86 88 89 public void recycle() { 90 super.recycle(); 91 aces.clear(); 92 } 93 94 95 101 public void addRequestHeaders(HttpState state, HttpConnection conn) 102 throws IOException , HttpException { 103 104 if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 106 super.addRequestHeaders(state, conn); 107 108 } 109 110 116 protected String generateRequestBody() { 117 118 XMLPrinter printer = new XMLPrinter(); 119 120 printer.writeXMLHeader(); 121 printer.writeElement("D", "DAV:", "acl", 122 XMLPrinter.OPENING); 123 124 Enumeration aceList = aces.elements(); 125 126 while (aceList.hasMoreElements()) { 127 Ace ace = (Ace) aceList.nextElement(); 128 129 if (ace.isInherited() || ace.isProtected()) { 130 continue; 134 } 135 136 printer.writeElement("D", null, "ace", 137 XMLPrinter.OPENING); 138 139 printer.writeElement("D", null, "principal", 140 XMLPrinter.OPENING); 141 142 boolean found = false; 143 String principal = ace.getPrincipal(); 144 String [] types = {"all", "authenticated", "unauthenticated", 145 "property", "self"}; 146 for (int i = 0; i < types.length && !found; i++) { 147 if (types[i].equals(principal)) { 148 found = true; 149 if ("property".equals(principal)) { 150 printer.writeElement("D", null, principal, 151 XMLPrinter.OPENING); 152 PropertyName property = ace.getProperty(); 153 String nsURI = property.getNamespaceURI(); 154 if ("DAV:".equals(nsURI)) { 155 printer.writeElement("D", null, 156 property.getLocalName(), 157 XMLPrinter.NO_CONTENT); 158 } else { 159 printer.writeElement("Z", nsURI, 160 property.getLocalName(), 161 XMLPrinter.NO_CONTENT); 162 } 163 printer.writeElement("D", null, principal, 164 XMLPrinter.CLOSING); 165 } else { 166 printer.writeElement("D", null, principal, 167 XMLPrinter.NO_CONTENT); 168 } 169 } 170 } 171 if (!found) { 172 printer.writeElement("D", null, "href", XMLPrinter.OPENING); 173 printer.writeText(principal); 174 printer.writeElement("D", null, "href", XMLPrinter.CLOSING); 175 } 176 177 printer.writeElement("D", null, "principal", 178 XMLPrinter.CLOSING); 179 180 String positive = (ace.isNegative()) ? "deny" : "grant"; 181 182 printer.writeElement("D", null, positive, 183 XMLPrinter.OPENING); 184 185 Enumeration privilegeList = ace.enumeratePrivileges(); 186 while (privilegeList.hasMoreElements()) { 187 Privilege privilege = (Privilege) privilegeList.nextElement(); 188 printer.writeElement("D", null, "privilege", 189 XMLPrinter.OPENING); 190 String nsURI = privilege.getNamespace(); 191 if ("DAV:".equals(nsURI)) { 192 printer.writeElement("D", null, privilege.getName(), 193 XMLPrinter.NO_CONTENT); 194 } else { 195 printer.writeElement("Z", nsURI, privilege.getName(), 196 XMLPrinter.NO_CONTENT); 197 } 198 printer.writeElement("D", null, "privilege", 199 XMLPrinter.CLOSING); 200 } 201 202 printer.writeElement("D", null, positive, 203 XMLPrinter.CLOSING); 204 205 printer.writeElement("D", null, "ace", 206 XMLPrinter.CLOSING); 207 208 } 209 210 printer.writeElement("D", "acl", XMLPrinter.CLOSING); 211 212 return printer.toString(); 213 } 214 215 public String getName() { 216 return "ACL"; 217 } 218 } 219 | Popular Tags |