Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 35953 invoked from network); 18 Feb 2004 07:07:37 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 18 Feb 2004 07:07:37 -0000 Received: (qmail 27903 invoked by uid 500); 18 Feb 2004 07:06:55 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 27690 invoked by uid 500); 18 Feb 2004 07:06:54 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 27675 invoked from network); 18 Feb 2004 07:06:53 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by daedalus.apache.org with SMTP; 18 Feb 2004 07:06:53 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1AtLnV-0006j7-00 for ; Wed, 18 Feb 2004 08:07:05 +0100 Received: from 4.43.180.113 ([4.43.180.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed Feb 18 07:07:05 2004 Received: from wbarker by 4.43.180.113 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed Feb 18 07:07:05 2004 X-Injected-Via-Gmane: http://gmane.org/ To: tomcat-user@jakarta.apache.org From: "Bill Barker" Subject: Re: Can I chain authenticators? Date: Tue, 17 Feb 2004 23:19:41 -0800 Lines: 73 Message-ID: References: X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 4.43.180.113 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Sender: news X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N "Ryan Rhodes" wrote in message news:Law12-F75kLwxTQTYkW0001d3f7@hotmail.com... > I have a portal project. I need to allow users to navigate seamlessly from > the portal to a commercial product that's based on Tomcat 4.1 and uses Basic > Authentication. To get around this, I hacked BasicAuthenticator and added > some code to get the credentials from the request body: > > if( hreq.getMethod().toUpperCase().equals("POST") && > hreq.getParameter("username") != null && > hreq.getParameter("password") != null ) { > username = hreq.getParameter("username"); > password = hreq.getParameter("password"); > > principal = context.getRealm().authenticate(username,password); > if (principal != null) { > register(request, response, principal, > Constants.BASIC_METHOD, > username, password); > return (true); > } > } > > I read in the lists somewhere that if I add a custom Authenticator it will > disable the Basic Authenticator. Can I separate this code out and chain the > Authenticators together? What level should I configure the Valve at for the > Authenticator? > It has to be configured at the Context level if it implement Authenticator. The same is true for your code above, since the Context isn't known until then. For what you want, you could probably also use a non-Authenticator valve, and call request.setUserPrincipal with the Principal that is returned by the Realm. Then BasicAuthenticator will think that you are already authenticated, and let you through. > Incidentally, I tried like hell to do this with a Valve. It seems like no > matter which container you put the Valve in the Basic Authenticator always > runs first and causes the login dialog to popup in the browser. It would be > great if anyone could confirm this or explain the ordering of valves and > authenticators to me a little better. Here is the code I used for the valve > approach: > > if( req.getMethod().equals("POST") ) { > if( req.getParameter("username") != null && req.getParameter("password") != > null ) { > String unencoded = req.getParameter("username") + ":" + > req.getParameter("password"); > String encoded = new String(Base64.encode(unencoded.getBytes())); > HttpRequest hreq = (HttpRequest) request; > hreq.setMethod("GET"); > hreq.addHeader("AUTHORIZATION", "BASIC " + encoded); > log("HTTP Basic Credentials: " + unencoded ); > } } > > Thanks for any help, > > Ryan Rhodes > > _________________________________________________________________ > Get fast, reliable access with MSN 9 Dial-up. Click here for Special Offer! > http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/ --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org