/** * Create a new <code>CurrentUserPrivilegeSetProperty</code> from a DavProperty * as obtained from a MultiStatusResponse. * * @param xmlDavProperty * @throws DavException */ public CurrentUserPrivilegeSetProperty(DavProperty xmlDavProperty) throws DavException { super(xmlDavProperty.getName(), true); if (!SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(getName())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:current-user-privilege-set expected."); } privileges = new HashSet(); // parse property value Object value = xmlDavProperty.getValue(); if (value != null) { if (value instanceof Element) { privileges.add(Privilege.getPrivilege((Element)value)); } else if (value instanceof Collection) { Iterator it = ((Collection)value).iterator(); while (it.hasNext()) { Object entry = it.next(); if (entry instanceof Element) { privileges.add(Privilege.getPrivilege((Element)entry)); } } } } }
/** * Factory method to create/retrieve a <code>Privilege</code>. * * @param privilege * @param namespace * @return */ public static Privilege getPrivilege(String privilege, Namespace namespace) { if (privilege == null) { throw new IllegalArgumentException("'null' is not a valid privilege."); } if (namespace == null) { namespace = Namespace.EMPTY_NAMESPACE; } String key = "{" + namespace.getURI() + "}" + privilege; if (REGISTERED_PRIVILEGES.containsKey(key)) { return REGISTERED_PRIVILEGES.get(key); } else { Privilege p = new Privilege(privilege, namespace); REGISTERED_PRIVILEGES.put(key, p); return p; } }
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); } } }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element spElem = DomUtil.createElement(document, XML_SUPPORTED_PRIVILEGE, SecurityConstants.NAMESPACE); spElem.appendChild(privilege.toXml(document)); if (isAbstract) { DomUtil.addChildElement(spElem, XML_ABSTRACT, SecurityConstants.NAMESPACE); } if (description != null) { Element desc = DomUtil.addChildElement(spElem, XML_DESCRIPTION, SecurityConstants.NAMESPACE, description); if (descriptionLanguage != null) { DomUtil.setAttribute(desc, "lang", Namespace.XML_NAMESPACE, descriptionLanguage); } } if (supportedPrivileges != null) { for (SupportedPrivilege supportedPrivilege : supportedPrivileges) { spElem.appendChild(supportedPrivilege.toXml(document)); } } return spElem; }
private void addResponses(DavResourceLocator locator) { String repositoryPath = locator.getRepositoryPath(); MultiStatusResponse resp = new MultiStatusResponse(locator.getHref(false), null); List<Privilege> currentPrivs = new ArrayList<Privilege>(); for (Privilege priv : PRIVS) { try { if (getRepositorySession().hasPermission(repositoryPath, priv.getName())) { currentPrivs.add(priv); } } catch (RepositoryException e) { // ignore log.debug(e.toString()); } } resp.add(new CurrentUserPrivilegeSetProperty(currentPrivs.toArray(new Privilege[currentPrivs.size()]))); ms.addResponse(resp); }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element spElem = DomUtil.createElement(document, XML_SUPPORTED_PRIVILEGE, SecurityConstants.NAMESPACE); spElem.appendChild(privilege.toXml(document)); if (isAbstract) { DomUtil.addChildElement(spElem, XML_ABSTRACT, SecurityConstants.NAMESPACE); } if (description != null) { Element desc = DomUtil.addChildElement(spElem, XML_DESCRIPTION, SecurityConstants.NAMESPACE, description); if (descriptionLanguage != null) { DomUtil.setAttribute(desc, "lang", Namespace.XML_NAMESPACE, descriptionLanguage); } } if (supportedPrivileges != null) { for (SupportedPrivilege supportedPrivilege : supportedPrivileges) { spElem.appendChild(supportedPrivilege.toXml(document)); } } return spElem; }
/** * Create a new <code>CurrentUserPrivilegeSetProperty</code> from a DavProperty * as obtained from a MultiStatusResponse. * * @param xmlDavProperty * @throws DavException */ public CurrentUserPrivilegeSetProperty(DavProperty<?> xmlDavProperty) throws DavException { super(xmlDavProperty.getName(), true); if (!SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(getName())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:current-user-privilege-set expected."); } privileges = new HashSet<Privilege>(); // parse property value Object value = xmlDavProperty.getValue(); if (value != null) { if (value instanceof Element) { privileges.add(Privilege.getPrivilege((Element)value)); } else if (value instanceof Collection) { for (Object entry : ((Collection<?>) value)) { if (entry instanceof Element) { privileges.add(Privilege.getPrivilege((Element) entry)); } } } } }
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); } } }
/** * @see XmlSerializable#toXml(Document) */ public Element toXml(Document document) { Element spElem = DomUtil.createElement(document, XML_SUPPORTED_PRIVILEGE, SecurityConstants.NAMESPACE); spElem.appendChild(privilege.toXml(document)); if (isAbstract) { DomUtil.addChildElement(spElem, XML_ABSTRACT, SecurityConstants.NAMESPACE); } if (description != null) { Element desc = DomUtil.addChildElement(spElem, XML_DESCRIPTION, SecurityConstants.NAMESPACE, description); if (descriptionLanguage != null) { DomUtil.setAttribute(desc, "lang", Namespace.XML_NAMESPACE, descriptionLanguage); } } if (supportedPrivileges != null) { for (int i = 0; i < supportedPrivileges.length; i++) { spElem.appendChild(supportedPrivileges[i].toXml(document)); } } return spElem; } }
/** * Factory method to create/retrieve a <code>Privilege</code>. * * @param privilege * @param namespace * @return */ public static Privilege getPrivilege(String privilege, Namespace namespace) { if (privilege == null) { throw new IllegalArgumentException("'null' is not a valid privilege."); } if (namespace == null) { namespace = Namespace.EMPTY_NAMESPACE; } String key = "{" + namespace.getURI() + "}" + privilege; if (REGISTERED_PRIVILEGES.containsKey(key)) { return (Privilege) REGISTERED_PRIVILEGES.get(key); } else { Privilege p = new Privilege(privilege, namespace); REGISTERED_PRIVILEGES.put(key, p); return p; } }
public CurrentUserPrivilegeSetProperty asDavProperty() throws RepositoryException { List<Privilege> davPrivs = new ArrayList<Privilege>(); for (javax.jcr.security.Privilege privilege : session.getAccessControlManager().getPrivileges(absPath)) { String privilegeName = privilege.getName(); String prefix = Text.getNamespacePrefix(privilegeName); Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix)); davPrivs.add(Privilege.getPrivilege(Text.getLocalName(privilegeName), ns)); } return new CurrentUserPrivilegeSetProperty(davPrivs.toArray(new Privilege[davPrivs.size()])); } }
aggrnames = new HashSet<Name>(); for (SupportedPrivilege aggregate : aggregates) { Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName()); aggrnames.add(aggregateName);
/** * @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; }
/** * Factory method to create/retrieve a <code>Privilege</code>. * * @param privilege * @param namespace * @return */ public static Privilege getPrivilege(String privilege, Namespace namespace) { if (privilege == null) { throw new IllegalArgumentException("'null' is not a valid privilege."); } if (namespace == null) { namespace = Namespace.EMPTY_NAMESPACE; } String key = "{" + namespace.getURI() + "}" + privilege; if (REGISTERED_PRIVILEGES.containsKey(key)) { return REGISTERED_PRIVILEGES.get(key); } else { Privilege p = new Privilege(privilege, namespace); REGISTERED_PRIVILEGES.put(key, p); return p; } }
/** * Create a new <code>CurrentUserPrivilegeSetProperty</code> from a DavProperty * as obtained from a MultiStatusResponse. * * @param xmlDavProperty * @throws DavException */ public CurrentUserPrivilegeSetProperty(DavProperty<?> xmlDavProperty) throws DavException { super(xmlDavProperty.getName(), true); if (!SecurityConstants.CURRENT_USER_PRIVILEGE_SET.equals(getName())) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "DAV:current-user-privilege-set expected."); } privileges = new HashSet<Privilege>(); // parse property value Object value = xmlDavProperty.getValue(); if (value != null) { if (value instanceof Element) { privileges.add(Privilege.getPrivilege((Element)value)); } else if (value instanceof Collection) { for (Object entry : ((Collection<?>) value)) { if (entry instanceof Element) { privileges.add(Privilege.getPrivilege((Element) entry)); } } } } }
aggrnames = new HashSet<Name>(); for (SupportedPrivilege aggregate : aggregates) { Name aggregateName = nameFactory.create(aggregate.getPrivilege().getNamespace().getURI(), aggregate.getPrivilege().getName()); aggrnames.add(aggregateName);
/** * @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; }
isAbstract = true; } else if (child.getLocalName().equals(Privilege.XML_PRIVILEGE)) { privilege = Privilege.getPrivilege(child); } else if (child.getLocalName().equals(XML_DESCRIPTION)) { description = child.getLocalName();
Set<Name> privNames = new HashSet<Name>(privs.size()); for (Privilege priv : privs) { privNames.add(nameFactory.create(priv.getNamespace().getURI(), priv.getName()));
/** * @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; }