public static Principal getHrefPrincipal(String href) { if (href == null) { throw new IllegalArgumentException("Href-Principal must contain a valid href."); } return new Principal(href); }
public static Principal createFromXml(Element principalElement) throws DavException { if (!DomUtil.matches(principalElement, XML_PRINCIPAL, NAMESPACE)) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:principal element expected."); } if (DomUtil.hasChildElement(principalElement, XML_ALL, NAMESPACE)) { return ALL_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_SELF, NAMESPACE)) { return SELF_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_AUTHENTICATED, NAMESPACE)) { return AUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_UNAUTHENTICATED, NAMESPACE)) { return UNAUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE)) { String href = DomUtil.getChildText(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE); return getHrefPrincipal(href); } else if (DomUtil.hasChildElement(principalElement, XML_PROPERTY, NAMESPACE)) { Element propEl = DomUtil.getChildElement(principalElement, XML_PROPERTY, NAMESPACE); DavPropertyName pn = DavPropertyName.createFromXml(DomUtil.getFirstChildElement(propEl)); return getPropertyPrincipal(pn); } else { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid structure inside DAV:principal element."); } } }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element ace = DomUtil.createElement(document, XML_ACE, SecurityConstants.NAMESPACE); if (invert) { Element inv = DomUtil.addChildElement(ace, XML_INVERT, SecurityConstants.NAMESPACE); inv.appendChild(principal.toXml(document)); } else { ace.appendChild(principal.toXml(document)); } Element gd = DomUtil.addChildElement(ace, ((grant) ? XML_GRANT : XML_DENY), SecurityConstants.NAMESPACE); for (int i = 0; i < privileges.length; i++) { gd.appendChild(privileges[i].toXml(document)); } if (isProtected) { DomUtil.addChildElement(ace, XML_PROTECTED, SecurityConstants.NAMESPACE); } if (inheritedHref != null) { Element inh = DomUtil.addChildElement(ace, XML_INHERITED, SecurityConstants.NAMESPACE); inh.appendChild(DomUtil.hrefToXml(inheritedHref, document)); } return ace; }
/** * @see Report#init(DavResource, ReportInfo) */ public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map principalMap = new HashMap(); Iterator aceIt = ((List)((AclProperty)acl).getValue()).iterator(); while (aceIt.hasNext()) { AclProperty.Ace ace = (AclProperty.Ace) aceIt.next(); String href = ace.getPrincipal().getHref(); if (href == null && principalMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); principalMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = (MultiStatusResponse[]) principalMap.values().toArray(new MultiStatusResponse[principalMap.size()]); } }
pe = DomUtil.getChildElement(aceElement, Principal.XML_PRINCIPAL, SecurityConstants.NAMESPACE); Principal principal = Principal.createFromXml(pe);
public static Principal createFromXml(Element principalElement) throws DavException { if (!DomUtil.matches(principalElement, XML_PRINCIPAL, NAMESPACE)) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:principal element expected."); } if (DomUtil.hasChildElement(principalElement, XML_ALL, NAMESPACE)) { return ALL_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_SELF, NAMESPACE)) { return SELF_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_AUTHENTICATED, NAMESPACE)) { return AUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_UNAUTHENTICATED, NAMESPACE)) { return UNAUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE)) { String href = DomUtil.getChildText(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE); return getHrefPrincipal(href); } else if (DomUtil.hasChildElement(principalElement, XML_PROPERTY, NAMESPACE)) { Element propEl = DomUtil.getChildElement(principalElement, XML_PROPERTY, NAMESPACE); DavPropertyName pn = DavPropertyName.createFromXml(DomUtil.getFirstChildElement(propEl)); return getPropertyPrincipal(pn); } else { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid structure inside DAV:principal element."); } } }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element ace = DomUtil.createElement(document, XML_ACE, SecurityConstants.NAMESPACE); if (invert) { Element inv = DomUtil.addChildElement(ace, XML_INVERT, SecurityConstants.NAMESPACE); inv.appendChild(principal.toXml(document)); } else { ace.appendChild(principal.toXml(document)); } Element gd = DomUtil.addChildElement(ace, ((grant) ? XML_GRANT : XML_DENY), SecurityConstants.NAMESPACE); for (Privilege privilege : privileges) { gd.appendChild(privilege.toXml(document)); } if (isProtected) { DomUtil.addChildElement(ace, XML_PROTECTED, SecurityConstants.NAMESPACE); } if (inheritedHref != null) { Element inh = DomUtil.addChildElement(ace, XML_INHERITED, SecurityConstants.NAMESPACE); inh.appendChild(DomUtil.hrefToXml(inheritedHref, document)); } return ace; }
/** * @see Report#init(DavResource, ReportInfo) */ @Override public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>(); List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty)acl).getValue(); for (AclProperty.Ace ace : list) { String href = ace.getPrincipal().getHref(); if (href == null || respMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]); } }
pe = DomUtil.getChildElement(aceElement, Principal.XML_PRINCIPAL, SecurityConstants.NAMESPACE); Principal principal = Principal.createFromXml(pe);
public static Principal createFromXml(Element principalElement) throws DavException { if (!DomUtil.matches(principalElement, XML_PRINCIPAL, NAMESPACE)) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:principal element expected."); } if (DomUtil.hasChildElement(principalElement, XML_ALL, NAMESPACE)) { return ALL_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_SELF, NAMESPACE)) { return SELF_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_AUTHENTICATED, NAMESPACE)) { return AUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, XML_UNAUTHENTICATED, NAMESPACE)) { return UNAUTHENTICATED_PRINCIPAL; } else if (DomUtil.hasChildElement(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE)) { String href = DomUtil.getChildText(principalElement, DavConstants.XML_HREF, DavConstants.NAMESPACE); return getHrefPrincipal(href); } else if (DomUtil.hasChildElement(principalElement, XML_PROPERTY, NAMESPACE)) { Element propEl = DomUtil.getChildElement(principalElement, XML_PROPERTY, NAMESPACE); DavPropertyName pn = DavPropertyName.createFromXml(DomUtil.getFirstChildElement(propEl)); return getPropertyPrincipal(pn); } else { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid structure inside DAV:principal element."); } } }
public static Principal getHrefPrincipal(String href) { if (href == null) { throw new IllegalArgumentException("Href-Principal must contain a valid href."); } return new Principal(href); }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element ace = DomUtil.createElement(document, XML_ACE, SecurityConstants.NAMESPACE); if (invert) { Element inv = DomUtil.addChildElement(ace, XML_INVERT, SecurityConstants.NAMESPACE); inv.appendChild(principal.toXml(document)); } else { ace.appendChild(principal.toXml(document)); } Element gd = DomUtil.addChildElement(ace, ((grant) ? XML_GRANT : XML_DENY), SecurityConstants.NAMESPACE); for (Privilege privilege : privileges) { gd.appendChild(privilege.toXml(document)); } if (isProtected) { DomUtil.addChildElement(ace, XML_PROTECTED, SecurityConstants.NAMESPACE); } if (inheritedHref != null) { Element inh = DomUtil.addChildElement(ace, XML_INHERITED, SecurityConstants.NAMESPACE); inh.appendChild(DomUtil.hrefToXml(inheritedHref, document)); } return ace; }
/** * @see Report#init(DavResource, ReportInfo) */ @Override public void init(DavResource resource, ReportInfo info) throws DavException { super.init(resource, info); // build the DAV:responses objects. DavProperty<?> acl = resource.getProperty(SecurityConstants.ACL); if (!(acl instanceof AclProperty)) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:acl property expected."); } DavResourceLocator loc = resource.getLocator(); Map<String, MultiStatusResponse> respMap = new HashMap<String, MultiStatusResponse>(); List<AclProperty.Ace> list = (List<AclProperty.Ace>) ((AclProperty)acl).getValue(); for (AclProperty.Ace ace : list) { String href = ace.getPrincipal().getHref(); if (href == null || respMap.containsKey(href)) { // ignore non-href principals and principals that have been listed before continue; } // href-principal that has not been found before DavResourceLocator princLocator = loc.getFactory().createResourceLocator(loc.getPrefix(), href); DavResource principalResource = resource.getFactory().createResource(princLocator, resource.getSession()); respMap.put(href, new MultiStatusResponse(principalResource, info.getPropertyNameSet())); } this.responses = respMap.values().toArray(new MultiStatusResponse[respMap.size()]); } }
pe = DomUtil.getChildElement(aceElement, Principal.XML_PRINCIPAL, SecurityConstants.NAMESPACE); Principal principal = Principal.createFromXml(pe);
public static Principal getHrefPrincipal(String href) { if (href == null) { throw new IllegalArgumentException("Href-Principal must contain a valid href."); } return new Principal(href); }
/** * @see DavProperty#toXml(Document) */ public Element toXml(Document document) { Element elem = getName().toXml(document); if (grantOnly) { DomUtil.addChildElement(elem, XML_GRANT_ONLY, SecurityConstants.NAMESPACE); } if (noInvert) { DomUtil.addChildElement(elem, XML_NO_INVERT, SecurityConstants.NAMESPACE); } if (denyBeforeGrant) { DomUtil.addChildElement(elem, XML_DENY_BEFORE_GRANT, SecurityConstants.NAMESPACE); } if (requiredPrincipal != null) { elem.appendChild(requiredPrincipal.toXml(document)); } return elem; }
public static Principal getPropertyPrincipal(DavPropertyName propertyName) { if (propertyName == null) { throw new IllegalArgumentException("Property-Principal must contain a valid property name."); } // there is a limited amount of properties, that can be used // for a Property-Principal if (PROP_PRINCIPALS.containsKey(propertyName)) { return PROP_PRINCIPALS.get(propertyName); } else { Principal p = new Principal(propertyName); PROP_PRINCIPALS.put(propertyName, p); return p; } }
/** * @see DavProperty#toXml(Document) */ @Override public Element toXml(Document document) { Element elem = getName().toXml(document); if (grantOnly) { DomUtil.addChildElement(elem, XML_GRANT_ONLY, SecurityConstants.NAMESPACE); } if (noInvert) { DomUtil.addChildElement(elem, XML_NO_INVERT, SecurityConstants.NAMESPACE); } if (denyBeforeGrant) { DomUtil.addChildElement(elem, XML_DENY_BEFORE_GRANT, SecurityConstants.NAMESPACE); } if (requiredPrincipal != null) { elem.appendChild(requiredPrincipal.toXml(document)); } return elem; }
public static Principal getPropertyPrincipal(DavPropertyName propertyName) { if (propertyName == null) { throw new IllegalArgumentException("Property-Principal must contain a valid property name."); } // there is a limited amount of properties, that can be used // for a Property-Principal if (PROP_PRINCIPALS.containsKey(propertyName)) { return PROP_PRINCIPALS.get(propertyName); } else { Principal p = new Principal(propertyName); PROP_PRINCIPALS.put(propertyName, p); return p; } }
/** * @see DavProperty#toXml(Document) */ @Override public Element toXml(Document document) { Element elem = getName().toXml(document); if (grantOnly) { DomUtil.addChildElement(elem, XML_GRANT_ONLY, SecurityConstants.NAMESPACE); } if (noInvert) { DomUtil.addChildElement(elem, XML_NO_INVERT, SecurityConstants.NAMESPACE); } if (denyBeforeGrant) { DomUtil.addChildElement(elem, XML_DENY_BEFORE_GRANT, SecurityConstants.NAMESPACE); } if (requiredPrincipal != null) { elem.appendChild(requiredPrincipal.toXml(document)); } return elem; }