cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
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 GMT
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();
     }
 
     /**



Mime
View raw message