001: // LocalAuthFilter.java
002: // $Id: LocalAuthFilter.java,v 1.6 2000/08/16 21:38:03 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.www.protocol.http.auth;
007:
008: import java.net.URL;
009:
010: import org.w3c.www.http.HttpCredential;
011: import org.w3c.www.http.HttpRequestMessage;
012:
013: import org.w3c.www.protocol.http.HttpException;
014: import org.w3c.www.protocol.http.HttpManager;
015: import org.w3c.www.protocol.http.Reply;
016: import org.w3c.www.protocol.http.Request;
017: import org.w3c.www.protocol.http.RequestFilter;
018:
019: public class LocalAuthFilter implements RequestFilter {
020: HttpCredential credentials = null;
021: boolean isProxy = false;
022:
023: /**
024: * Install a local authentication filter for the given target.
025: * @param manager The HttpManager.
026: * @param for The domain to which given credentials apply.
027: * @param credentials The credentials to use for this domain.
028: */
029:
030: public static void installLocalAuth(HttpManager manager,
031: URL domain, HttpCredential credentials) {
032: // Create the cheap but efficient filter:
033: LocalAuthFilter filter = new LocalAuthFilter(credentials);
034: // Install it appropriately:
035: URL includes[] = new URL[1];
036: includes[0] = domain;
037: manager.setFilter(includes, null, filter);
038: }
039:
040: /**
041: * Install a proxy authentication filter globally.
042: * @param manager The HttpManager.
043: * @param credentials The credentials to use for this domain.
044: */
045:
046: public static void installProxyAuth(HttpManager manager,
047: HttpCredential credentials) {
048: // Create the cheap but efficient filter:
049: LocalAuthFilter filter = new LocalAuthFilter(credentials);
050: // Install it appropriately:
051: filter.isProxy = true;
052: manager.setFilter(filter);
053: }
054:
055: /**
056: * This filter doesn't handle exceptions.
057: * @param request The request that triggered the exception.
058: * @param ex The triggered exception.
059: * @return Always <strong>false</strong>.
060: */
061:
062: public boolean exceptionFilter(Request request, HttpException ex) {
063: return false;
064: }
065:
066: /**
067: * The ingoing filter just decorates the request with the credentials.
068: * @param request The request to be processed.
069: * @return Always <strong>null</strong>.
070: */
071:
072: public Reply ingoingFilter(Request request) {
073: // Just add our credentials to the request:
074: if (isProxy)
075: request.setProxyAuthorization(credentials);
076: else
077: request.setAuthorization(credentials);
078: return null;
079: }
080:
081: /**
082: * The outgoing filter is empty here.
083: */
084:
085: public Reply outgoingFilter(Request request, Reply reply) {
086: return null;
087: }
088:
089: /**
090: * We don't maintain cached informations.
091: */
092:
093: public void sync() {
094: }
095:
096: LocalAuthFilter(HttpCredential credentials) {
097: this.credentials = credentials;
098: }
099:
100: }
|