Java Code Examples for org.apache.catalina.connector.Request.getContextPath()

The following are Jave code examples for showing how to use getContextPath() of the org.apache.catalina.connector.Request class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lams   File: JAASMemoryLoginModule.java   Source Code and License Vote up 5 votes
/**
 * Return the SecurityConstraints configured to guard the request URI for
 * this request, or <code>null</code> if there is no such constraint.
 *
 * @param request Request we are processing
 * @param context Context the Request is mapped to
 */
public SecurityConstraint [] findSecurityConstraints(Request request,
                                                 Context context) {
    ArrayList<SecurityConstraint> results = null;
    // Are there any defined security constraints?
    SecurityConstraint constraints[] = context.findConstraints();
    if ((constraints == null) || (constraints.length == 0)) {
        if (context.getLogger().isDebugEnabled())
            context.getLogger().debug("  No applicable constraints defined");
        return (null);
    }

    // Check each defined security constraint
    String uri = request.getDecodedRequestURI();
    String contextPath = request.getContextPath();
    if (contextPath.length() > 0)
        uri = uri.substring(contextPath.length());
    uri = RequestUtil.URLDecode(uri); // Before checking constraints
    String method = request.getMethod();
    for (int i = 0; i < constraints.length; i++) {
        if (context.getLogger().isDebugEnabled())
            context.getLogger().debug("  Checking constraint '" + constraints[i] +
                "' against " + method + " " + uri + " --> " +
                constraints[i].included(uri, method));
        if (constraints[i].included(uri, method)) {
            if(results == null) {
                results = new ArrayList<SecurityConstraint>();
            }
            results.add(constraints[i]);
        }
    }

    // No applicable security constraint was found
    if (context.getLogger().isDebugEnabled())
        context.getLogger().debug("  No applicable constraint located");
    if(results == null)
        return null;
    SecurityConstraint [] array = new SecurityConstraint[results.size()];
    System.arraycopy(results.toArray(), 0, array, 0, array.length);
    return array;
}