use of com.google.cloud.servicedirectory.v1.Namespace in project jspwiki by apache.
the class WebContainerAuthorizer method isConstrained.
/**
* <p>
* Protected method that identifies whether a particular webapp URL is
* constrained to a particular Role. The resource is considered constrained
* if:
* </p>
* <ul>
* <li>the web application deployment descriptor contains a
* <code>security-constraint</code> with a child
* <code>web-resource-collection/url-pattern</code> element matching the
* URL, <em>and</em>:</li>
* <li>this constraint also contains an
* <code>auth-constraint/role-name</code> element equal to the supplied
* Role's <code>getName()</code> method. If the supplied Role is Role.ALL,
* it matches all roles</li>
* </ul>
* @param url the web resource
* @param role the role
* @return <code>true</code> if the resource is constrained to the role,
* <code>false</code> otherwise
*/
public boolean isConstrained(final String url, final Role role) {
final Element root = m_webxml.getRootElement();
final Namespace jeeNs = Namespace.getNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
// Get all constraints that have our URL pattern
// (Note the crazy j: prefix to denote the jee schema)
final String constrainsSelector = "//j:web-app/j:security-constraint[j:web-resource-collection/j:url-pattern=\"" + url + "\"]";
final List<Element> constraints = XPathFactory.instance().compile(constrainsSelector, Filters.element(), null, jeeNs).evaluate(root);
// Get all constraints that match our Role pattern
final String rolesSelector = "//j:web-app/j:security-constraint[j:auth-constraint/j:role-name=\"" + role.getName() + "\"]";
final List<Element> roles = XPathFactory.instance().compile(rolesSelector, Filters.element(), null, jeeNs).evaluate(root);
// If we can't find either one, we must not be constrained
if (constraints.size() == 0) {
return false;
}
// Shortcut: if the role is ALL, we are constrained
if (role.equals(Role.ALL)) {
return true;
}
// If no roles, we must not be constrained
if (roles.size() == 0) {
return false;
}
// If a constraint is contained in both lists, we must be constrained
for (final Element constraint : constraints) {
for (final Element roleConstraint : roles) {
if (constraint.equals(roleConstraint)) {
return true;
}
}
}
return false;
}
use of com.google.cloud.servicedirectory.v1.Namespace in project pom-manipulation-ext by release-engineering.
the class Utils method replaceXpp3DOM.
// -- Element findAndReplaceXpp3DOM( Counter, Element, String, Xpp3Dom )
/**
* Method replaceXpp3DOM.
*
* @param parent
* @param counter
* @param parentDom
*/
public static void replaceXpp3DOM(final Element parent, final Xpp3Dom parentDom, final IndentationCounter counter) {
if (parentDom.getChildCount() > 0) {
final Xpp3Dom[] childs = parentDom.getChildren();
final ArrayList<Xpp3Dom> domChilds = new ArrayList<>(Arrays.asList(childs));
final ListIterator<?> it = parent.getChildren().listIterator();
while (it.hasNext()) {
final Element elem = (Element) it.next();
final Iterator<Xpp3Dom> it2 = domChilds.iterator();
Xpp3Dom corrDom = null;
while (it2.hasNext()) {
final Xpp3Dom dm = it2.next();
// Elem::getName, unlike getQualifiedName, does not return namespaced names which can fail the comparison
if (dm.getName().equals(elem.getQualifiedName())) {
corrDom = dm;
break;
}
}
if (corrDom != null) {
domChilds.remove(corrDom);
replaceXpp3DOM(elem, corrDom, new IndentationCounter(counter.getDepth() + 1));
counter.increaseCount();
} else {
it.remove();
}
}
for (Xpp3Dom dm : domChilds) {
final String rawName = dm.getName();
final String[] parts = rawName.split(":");
Element elem;
if (parts.length > 1) {
final String nsId = parts[0];
String nsUrl = dm.getAttribute("xmlns:" + nsId);
final String name = parts[1];
if (nsUrl == null) {
nsUrl = parentDom.getAttribute("xmlns:" + nsId);
}
elem = factory.element(name, Namespace.getNamespace(nsId, nsUrl));
} else {
Namespace root = parent.getNamespace();
for (Namespace n : getNamespacesInherited(parent)) {
if (n.getPrefix() == null || n.getPrefix().length() == 0) {
root = n;
break;
}
}
elem = factory.element(dm.getName(), root);
}
final String[] attributeNames = dm.getAttributeNames();
for (final String attrName : attributeNames) {
if (attrName.startsWith("xmlns:")) {
continue;
}
elem.setAttribute(attrName, dm.getAttribute(attrName));
}
insertAtPreferredLocation(parent, elem, counter);
counter.increaseCount();
replaceXpp3DOM(elem, dm, new IndentationCounter(counter.getDepth() + 1));
}
} else if (parentDom.getValue() != null) {
List<Content> cl = parent.getContent();
boolean foundCdata = false;
for (Content c : cl) {
if (c instanceof CDATA) {
foundCdata = true;
break;
}
}
if (!foundCdata) {
if (parent.getText().trim().equals(parentDom.getValue())) {
logger.trace("Ignoring during element update as original of '{}' equals (ignoring trimmed whitespace) '{}'", parent.getText(), parentDom.getValue());
} else {
parent.setText(parentDom.getValue());
}
}
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project pom-manipulation-ext by release-engineering.
the class Utils method getNamespacesInherited.
// -- Element findAndReplaceSimpleLists( Counter, Element, java.util.Collection, String, String )
// Copied from JDOM2
static List<Namespace> getNamespacesInherited(Element element) {
if (element.getParentElement() == null) {
ArrayList<Namespace> ret = new ArrayList<>(getNamespacesInScope(element));
for (Iterator<Namespace> it = ret.iterator(); it.hasNext(); ) {
Namespace ns = it.next();
if (ns == Namespace.NO_NAMESPACE || ns == Namespace.XML_NAMESPACE) {
continue;
}
it.remove();
}
return Collections.unmodifiableList(ret);
}
// OK, the things we inherit are the prefixes we have in scope that
// are also in our parent's scope.
HashMap<String, Namespace> parents = new HashMap<>();
for (Namespace ns : getNamespacesInScope(element.getParentElement())) {
parents.put(ns.getPrefix(), ns);
}
ArrayList<Namespace> al = new ArrayList<>();
for (Namespace ns : getNamespacesInScope(element)) {
if (ns == parents.get(ns.getPrefix())) {
// inherited
al.add(ns);
}
}
return Collections.unmodifiableList(al);
}
use of com.google.cloud.servicedirectory.v1.Namespace in project OpenOLAT by OpenOLAT.
the class SCORM12_DocumentHandler method canHandle.
protected static boolean canHandle(Document doc) throws DocumentHandlerException {
// The first thing we do is to see if there is a root Namespace in the Document
Namespace nameSpace = XMLUtils.getDocumentNamespace(doc);
// No Namespace, sorry we don't know what it is!
if (nameSpace == null || nameSpace.equals(Namespace.NO_NAMESPACE)) {
throw new DocumentHandlerException("No Namespace in Document so cannot determine what it is!");
}
// Does it have the correct root Namespace?
if (SUPPORTED_NAMESPACES.containsKey(nameSpace) == false)
return false;
// Now find out if it is a SCORM Document and if so whether we support it
// We'll search all elements for the ADL Namespace
Namespace nsSCORM = getSCORM_Namespace(doc);
if (nsSCORM == null)
return false;
// Do we support this version of SCORM?
return SUPPORTED_SCORM_NAMESPACES.containsKey(nsSCORM);
}
use of com.google.cloud.servicedirectory.v1.Namespace in project OpenOLAT by OpenOLAT.
the class XMLUtils method containsNamespace.
/**
* Hunt for a Namespace in the Element searching all sub-Elements in case the Namespace
* is declared "in-line" at the Element level
* @param element
* @param ns
* @return true if found
*/
private static boolean containsNamespace(Element element, Namespace ns) {
// Element Namespace?
if (ns.equals(element.getNamespace())) {
return true;
}
// Additional Namespace?
Iterator<Namespace> it = element.getAdditionalNamespaces().iterator();
while (it.hasNext()) {
Namespace ns1 = it.next();
if (ns1.equals(ns)) {
return true;
}
}
// Recurse children
Iterator<Element> i = element.getChildren().iterator();
while (i.hasNext()) {
Element child = i.next();
boolean found = containsNamespace(child, ns);
if (found) {
return true;
}
}
return false;
}
Aggregations