cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r737299 - in /cxf/trunk/rt/transports/http/src: main/java/org/apache/cxf/transport/http/ main/java/org/apache/cxf/transport/http/spring/ main/resources/schemas/configuration/ test/java/org/apache/cxf/transport/http/
Date Sat, 24 Jan 2009 04:01:19 GMT
Author: dkulp
Date: Sat Jan 24 04:01:19 2009
New Revision: 737299

URL: http://svn.apache.org/viewvc?rev=737299&view=rev
Log:
Implement old API overtop of new API

Added:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java
      - copied, changed from r737125, cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
  (with props)
Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DigestAuthSupplier.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/NamespaceHandler.java
    cxf/trunk/rt/transports/http/src/main/resources/schemas/configuration/http-conf.xsd
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DigestAuthSupplier.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DigestAuthSupplier.java?rev=737299&r1=737298&r2=737299&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DigestAuthSupplier.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/DigestAuthSupplier.java
Sat Jan 24 04:01:19 2009
@@ -86,8 +86,8 @@
                 }
                 authInfo.put(currentURL, di);
                 return di.generateAuth(currentURL.getFile(), 
-                                       getUsername(message),
-                                       getPassword(message));
+                                       getUsername(conduit, message),
+                                       getPassword(conduit, message));
             }
             
         }
@@ -98,25 +98,35 @@
         DigestInfo di = authInfo.get(currentURL);
         if (di != null) {
             return di.generateAuth(currentURL.getFile(), 
-                                   getUsername(message),
-                                   getPassword(message));            
+                                   getUsername(conduit, message),
+                                   getPassword(conduit, message));            
         }
         return null;
     }
 
-    private String getPassword(Message message) {
+    private String getPassword(HTTPConduit conduit, Message message) {
         AuthorizationPolicy policy 
             = (AuthorizationPolicy)message.getContextualProperty(AuthorizationPolicy.class.getName());
-        if (policy != null) {
+        if (policy == null) {
+            policy = conduit.getAuthorization();
+        }
+        if (policy != null
+            && (!policy.isSetAuthorizationType()
+                || "Digest".equals(policy.getAuthorizationType()))) {
             return policy.getUserName();            
         }
         return null;
     }
 
-    private String getUsername(Message message) {
+    private String getUsername(HTTPConduit conduit, Message message) {
         AuthorizationPolicy policy 
             = (AuthorizationPolicy)message.getContextualProperty(AuthorizationPolicy.class.getName());
-        if (policy != null) {
+        if (policy == null) {
+            policy = conduit.getAuthorization();
+        }
+        if (policy != null
+            && (!policy.isSetAuthorizationType()
+                || "Digest".equals(policy.getAuthorizationType()))) {
             return policy.getPassword();            
         }
         return null;
@@ -135,7 +145,6 @@
         
         synchronized String generateAuth(String uri, String username, String password) {
             try {
-                StringBuilder builder = new StringBuilder("Digest qop=auth, realm=\"");
                 nc++;
                 String ncstring = Integer.toString(nc);
                 while (ncstring.length() < 8) {
@@ -172,7 +181,12 @@
                         + qop + ":" + hasha2;
                 }
                 serverDigestValue = encode(digester.digest(serverDigestValue.getBytes("US-ASCII")));
-                builder.append(realm).append("\", opaque=\"")
+                StringBuilder builder = new StringBuilder("Digest ");
+                if (qop != null) {
+                    builder.append("qop=auth, ");
+                }  
+                builder.append("realm=\"")
+                    .append(realm).append("\", opaque=\"")
                     .append(opaque)
                     .append("\", nonce=\"")
                     .append(nonce)

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=737299&r1=737298&r2=737299&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
Sat Jan 24 04:01:19 2009
@@ -527,6 +527,7 @@
                         "Auth Supplier, but no Premeptive User Pass." 
                         + " We must cache request.");
             }
+            message.put("AUTH_VALUE", auth);
         }
         if (getClient().isAutoRedirect()) {
             needToCacheRequest = true;
@@ -1088,8 +1089,13 @@
             && (newPolicy == null
                 || (!"Basic".equals(newPolicy.getAuthorizationType())
                     && newPolicy.getAuthorization() == null))) {
-            authString = authSupplier.getPreemptiveAuthorization(
+            authString = (String)message.get("AUTH_VALUE");
+            if (authString == null) {
+                authString = authSupplier.getPreemptiveAuthorization(
                     this, url, message);
+            } else {
+                message.remove("AUTH_VALUE");
+            }
             if (authString != null) {
                 headers.put("Authorization",
                             createMutableList(authString));
@@ -2142,6 +2148,11 @@
     public boolean canAssert(QName type) {
         return PolicyUtils.HTTPCLIENTPOLICY_ASSERTION_QNAME.equals(type);  
     }
+
+    @Deprecated
+    public void setBasicAuthSupplier(HttpBasicAuthSupplier basicAuthSupplier) {
+        setAuthSupplier(basicAuthSupplier);
+    }
     
 }
 

Copied: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java
(from r737125, cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java?p2=cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java&p1=cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java&r1=737125&r2=737299&rev=737299&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpBasicAuthSupplier.java
Sat Jan 24 04:01:19 2009
@@ -21,6 +21,7 @@
 
 import java.net.URL;
 
+import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.message.Message;
 
 /**
@@ -44,22 +45,13 @@
  * that URL. Then this implementation may provide the UserPass for this
  * particular URL preemptively for subsequent calls to getPreemptiveUserPass.
  */
-public abstract class HttpBasicAuthSupplier {
-    
-    /**
-     * This field contains the logical name of this HttpBasicAuthSuppler.
-     * This field is not assigned to be final, since an extension may be
-     * Spring initialized as a bean, have an appropriate setLogicalName
-     * method, and set this field.
-     */
-    protected String logicalName;
+public abstract class HttpBasicAuthSupplier extends HttpAuthSupplier {
     
     /**
      * The default constructor assigns the class name as the LogicalName.
      *
      */
     protected HttpBasicAuthSupplier() {
-        logicalName = this.getClass().getName();
     }
     
     /**
@@ -68,16 +60,35 @@
      * @param name The Logical Name.
      */
     protected HttpBasicAuthSupplier(String name) {
-        logicalName = name;
+        super(name);
     }
     
-    /**
-     * This method returns the LogicalName of this HttpBasicAuthSupplier.
-     */
-    public String getLogicalName() {
-        return logicalName;
+    @Override
+    public String getAuthorizationForRealm(HTTPConduit conduit, URL currentURL, Message message,
+                                           String realm, String fullHeader) {
+        
+        UserPass up = getUserPassForRealm(conduit.getConduitName(),
+                                          currentURL,
+                                          message,
+                                          realm);
+        if (up != null) {
+            String key = up.getUserid() + ":" + up.getPassword();
+            return "Basic " + Base64Utility.encode(key.getBytes());
+        }
+        return null;
     }
-    
+    @Override
+    public String getPreemptiveAuthorization(HTTPConduit conduit, URL currentURL, Message
message) {
+        UserPass up = getPreemptiveUserPass(conduit.getConduitName(),
+                                            currentURL,
+                                            message);
+        if (up != null) {
+            String key = up.getUserid() + ":" + up.getPassword();
+            return "Basic " + Base64Utility.encode(key.getBytes());
+        }
+        return null;
+    }
+
     /**
      * This class is used to return the values of the 
      * userid and password used in the HTTP Authorization

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java?rev=737299&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
(added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
Sat Jan 24 04:01:19 2009
@@ -0,0 +1,39 @@
+/**
+ * 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.spring;
+
+
+import org.w3c.dom.Element;
+import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
+import org.apache.cxf.transport.http.HttpBasicAuthSupplier;
+
+public class HttpBasicAuthSupplierBeanDefinitionParser extends
+        AbstractBeanDefinitionParser {
+
+    @Override
+    protected String getJaxbPackage() {
+        return "org.apache.cxf.transports.http.configuration";
+    }
+    @Override
+    protected Class getBeanClass(Element arg0) {
+        return HttpBasicAuthSupplier.class;
+    }
+
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/HttpBasicAuthSupplierBeanDefinitionParser.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/NamespaceHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/NamespaceHandler.java?rev=737299&r1=737298&r2=737299&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/NamespaceHandler.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/spring/NamespaceHandler.java
Sat Jan 24 04:01:19 2009
@@ -28,6 +28,8 @@
                 new MessageTrustDeciderBeanDefinitionParser());        
         registerBeanDefinitionParser("authSupplier", 
                 new HttpAuthSupplierBeanDefinitionParser()); 
+        registerBeanDefinitionParser("basicAuthSupplier", 
+                                     new HttpBasicAuthSupplierBeanDefinitionParser()); 
         registerBeanDefinitionParser("destination", 
                 new HttpDestinationBeanDefinitionParser());        
     }

Modified: cxf/trunk/rt/transports/http/src/main/resources/schemas/configuration/http-conf.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/resources/schemas/configuration/http-conf.xsd?rev=737299&r1=737298&r2=737299&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/resources/schemas/configuration/http-conf.xsd (original)
+++ cxf/trunk/rt/transports/http/src/main/resources/schemas/configuration/http-conf.xsd Sat
Jan 24 04:01:19 2009
@@ -49,6 +49,7 @@
     <xs:element name="tlsClientParameters" type="sec:TLSClientParametersType"/>
     <xs:element name="trustDecider"        type="cxf-beans:ClassOrBeanType"/>
     <xs:element name="authSupplier"        type="cxf-beans:ClassOrBeanType"/>
+    <xs:element name="basicAuthSupplier"   type="cxf-beans:ClassOrBeanType"/>
     
     
     <xs:element name="conduit">
@@ -104,6 +105,18 @@
                      </xs:documentation>
                    </xs:annotation>
                 </xs:element>
+                <xs:element ref="http-conf:basicAuthSupplier" 
+                			minOccurs="0" maxOccurs="1">
+                   <xs:annotation>
+                     <xs:documentation>
+                       Holds the bean reference or class name
+                       of an object that supplies Auth information
+                       both preemptively and in response to a 401 HTTP
+                       Challenge. This class must extend the abstract class 
+                       org.apache.cxf.transport.http.HttpBasicAuthSupplier.
+                     </xs:documentation>
+                   </xs:annotation>
+                </xs:element>
                 <xs:element ref="http-conf:trustDecider" 
                 			minOccurs="0" maxOccurs="1">
                    <xs:annotation>

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java?rev=737299&r1=737298&r2=737299&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
(original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
Sat Jan 24 04:01:19 2009
@@ -82,17 +82,16 @@
      * This test class is a Basic Auth Supplier with a
      * preemptive UserPass.
      */
-    class BasicAuthSupplier extends HttpAuthSupplier {
-        public String getPreemptiveAuthorization(
-                HTTPConduit conduit, URL url, Message m) {
-            String userpass = "Gandalf:staff";
-            String token = Base64Utility.encode(userpass.getBytes());
-            return "Basic " + token;
+    class BasicAuthSupplier extends HttpBasicAuthSupplier {
+        public UserPass getPreemptiveUserPass(
+                String conduitName, URL url, Message m) {
+            return createUserPass("Gandalf", "staff");
         }
-        public String getAuthorizationForRealm(
-                HTTPConduit conduit, URL url, Message m, String r, String fh) {
+        public UserPass getUserPassForRealm(
+                String conduitName, URL url, Message m, String r) {
             return null;
         }
+
     }
 
     /**
@@ -218,11 +217,9 @@
         headers =
             CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
 
-        String head = headers.get("Authorization").get(0);
-        assertEquals("Unexpected Authorization Token: " 
-                     + new String(Base64Utility.decode(head.substring(6))),
+        assertEquals("Unexpected Authorization Token",
                 "Basic " + Base64Utility.encode("Gandalf:staff".getBytes()),
-                head);
+                headers.get("Authorization").get(0));
 
         // Setting authorization policy on the message should override all.
         AuthorizationPolicy authPolicy = new AuthorizationPolicy();



Mime
View raw message