Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 61087 invoked from network); 14 Dec 2009 20:03:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Dec 2009 20:03:47 -0000 Received: (qmail 44929 invoked by uid 500); 14 Dec 2009 20:03:47 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 44857 invoked by uid 500); 14 Dec 2009 20:03:47 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 44848 invoked by uid 99); 14 Dec 2009 20:03:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 20:03:47 +0000 X-ASF-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Dec 2009 20:03:45 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0234C23889C5; Mon, 14 Dec 2009 20:03:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r890464 - in /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http: CXFAuthenticator.java HTTPConduit.java Date: Mon, 14 Dec 2009 20:03:15 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091214200325.0234C23889C5@eris.apache.org> Author: dkulp Date: Mon Dec 14 20:03:04 2009 New Revision: 890464 URL: http://svn.apache.org/viewvc?rev=890464&view=rev Log: [CXF-2223] Try to install a JRE Authenticator to handle proxy CONNECT requests. Not sure if this will work or not. Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java (with props) Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java?rev=890464&view=auto ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java (added) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java Mon Dec 14 20:03:04 2009 @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.transport.http; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.Authenticator; +import java.net.PasswordAuthentication; + +import org.apache.cxf.message.Exchange; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.PhaseInterceptorChain; +import org.apache.cxf.transport.Conduit; + +/** + * + */ +public class CXFAuthenticator extends Authenticator { + static Authenticator wrapped; + static boolean setup; + + + public CXFAuthenticator() { + try { + for (Field f : Authenticator.class.getDeclaredFields()) { + if (f.getType().equals(Authenticator.class)) { + f.setAccessible(true); + wrapped = (Authenticator)f.get(null); + } + } + } catch (Throwable ex) { + //ignore + } + } + + public static synchronized void addAuthenticator() { + if (!setup) { + try { + Authenticator.setDefault(new CXFAuthenticator()); + } catch (Throwable t) { + //ignore + } + setup = true; + } + } + + protected PasswordAuthentication getPasswordAuthentication() { + PasswordAuthentication auth = null; + if (wrapped != null) { + try { + for (Field f : Authenticator.class.getDeclaredFields()) { + if (!Modifier.isStatic(f.getModifiers())) { + f.setAccessible(true); + f.set(wrapped, f.get(this)); + } + } + Method m = Authenticator.class.getMethod("getPasswordAuthentication"); + m.setAccessible(true); + auth = (PasswordAuthentication)m.invoke(wrapped); + } catch (Throwable t) { + //ignore + } + } + if (auth == null) { + Message m = PhaseInterceptorChain.getCurrentMessage(); + Exchange exchange = m.getExchange(); + Conduit conduit = exchange.getConduit(m); + if (conduit instanceof HTTPConduit) { + HTTPConduit httpConduit = (HTTPConduit)conduit; + if (getRequestorType() == RequestorType.PROXY + && httpConduit.getProxyAuthorization() != null) { + + auth = new PasswordAuthentication(httpConduit.getProxyAuthorization().getUserName(), + httpConduit.getProxyAuthorization() + .getPassword().toCharArray()); + } else if (getRequestorType() == RequestorType.SERVER + && httpConduit.getAuthorization() != null) { + auth = new PasswordAuthentication(httpConduit.getAuthorization().getUserName(), + httpConduit.getAuthorization() + .getPassword().toCharArray()); + } + } + } + return auth; + } +} Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=890464&r1=890463&r2=890464&view=diff ============================================================================== --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original) +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Mon Dec 14 20:03:04 2009 @@ -297,7 +297,8 @@ fromEndpointReferenceType = true; } - initializeConfig(); + initializeConfig(); + CXFAuthenticator.addAuthenticator(); } /**