URLPatternMatcher.java revision b91c214dd5376ef5e0e408936d75fa201eea1a38
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The contents of this file are subject to the terms
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * of the Common Development and Distribution License
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * (the License). You may not use this file except in
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * compliance with the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * You can obtain a copy of the License at
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * See the License for the specific language governing
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * permission and limitations under the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * When distributing Covered Code, include this CDDL
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Header Notice in each file and include the License file
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * If applicable, add the following below the CDDL Header,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * with the fields enclosed by brackets [] replaced by
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * your own identifying information:
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * $Id: URLPatternMatcher.java,v 1.1 2009/11/24 21:42:35 madan_ranganath Exp $
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington * Portions Copyrighted 2014-2015 ForgeRock AS.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The class provides pattern matching for notenforced URIs/URLs.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major private static final Debug DEBUG = Debug.getInstance("patternMatching");
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private HttpURLResourceName resourceName = null;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Constructor
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * Matches the URL against the provided URL patterns.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * @param requestedURL The URL to be matched.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * @param patterns The patterns to match the URL against.
b1b9ed659b5ba78c15d544b1a76134a6eba06a55David Luna * @param wildcard Flag for wildcard comparison
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * @return <code>true</code> if matched, <code>false</code> otherwise.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * @throws MalformedURLException If the URL or one of the patterns is invalid.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major public boolean match(String requestedURL, Collection<String> patterns, boolean wildcard)
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major boolean result = false;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major requestedURL = resourceName.canonicalize(requestedURL);
b1b9ed659b5ba78c15d544b1a76134a6eba06a55David Luna // convert URI to URL if required (but not if pattern is relative)
b91c214dd5376ef5e0e408936d75fa201eea1a38Tony Bamford pattern = convertToURL("/" + pattern, requestedURL);
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major DEBUG.message("URLPatternMatcher.match(" + requestedURL + "): matching by pattern: " + pattern);
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major ResourceMatch res = resourceName.compare(requestedURL, pattern, wildcard);
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major if (res == ResourceMatch.WILDCARD_MATCH || res == ResourceMatch.EXACT_MATCH) {
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major DEBUG.message("URLPatternMatcher.match(" + requestedURL + "): matched by pattern: " + pattern
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * convert pattern's URI to URL format.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private String convertToURL(String pattern, String requestedURL) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster builder.append(url.getProtocol()).append("://");
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major DEBUG.warning("URLPatternMatcher.convertToURL()- pattern:" + pattern + " requestedURL:" + requestedURL