* <code>false</code> otherwise
* @throws JDOMException if elements cannot be parsed correctly
*/
public boolean isConstrained( String url, Role role ) throws JDOMException
{
Element root = m_webxml.getRootElement();
XPath xpath;
String selector;
// Get all constraints that have our URL pattern
// (Note the crazy j: prefix to denote the 2.4 j2ee schema)
selector = "//j:web-app/j:security-constraint[j:web-resource-collection/j:url-pattern=\"" + url + "\"]";
xpath = XPath.newInstance( selector );
xpath.addNamespace( "j", J2EE_SCHEMA_24_NAMESPACE );
List<?> constraints = xpath.selectNodes( root );
// Get all constraints that match our Role pattern
selector = "//j:web-app/j:security-constraint[j:auth-constraint/j:role-name=\"" + role.getName() + "\"]";
xpath = XPath.newInstance( selector );
xpath.addNamespace( "j", J2EE_SCHEMA_24_NAMESPACE );
List<?> roles = xpath.selectNodes( 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 ( Iterator<?> c = constraints.iterator(); c.hasNext(); )
{
Element constraint = (Element)c.next();
for ( Iterator<?> r = roles.iterator(); r.hasNext(); )
{
Element roleConstraint = (Element)r.next();
if ( constraint.equals( roleConstraint ) )
{
return true;
}
}