Author: tterm
Date: Fri Jan 21 16:51:25 2011
New Revision: 1061902

URL: http://svn.apache.org/viewvc?rev=1061902&view=rev
Log:
SMXCOMP-843 The old provider processor has no possibilty to bind the Auth scope 
on a host:port config

Modified:
    
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
    
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
    
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java

Modified: 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java?rev=1061902&r1=1061901&r2=1061902&view=diff
==============================================================================
--- 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
 (original)
+++ 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
 Fri Jan 21 16:51:25 2011
@@ -20,10 +20,7 @@ import javax.jbi.messaging.MessageExchan
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
 
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.servicemix.expression.Expression;
 
@@ -124,11 +121,17 @@ public class BasicAuthCredentials {
      * @param client the client on which to set the authentication information
      * @param exchange the message exchange to be used for evaluating the 
expression
      * @param message the normalized message to be used for evaluating the 
expression
+     * @param hostConfig optional but if set the AuthScope is bind to that 
host and port from that hostConfig
      * @throws MessagingException if the correct value for username/password 
cannot be determined when using an expression
      */
-    public void applyCredentials(HttpClient client, MessageExchange exchange, 
NormalizedMessage message)
+    public void applyCredentials(HttpClient client, MessageExchange exchange, 
NormalizedMessage message, HostConfiguration hostConfig)
         throws MessagingException {
-        AuthScope scope = new AuthScope(AuthScope.ANY_HOST, 
AuthScope.ANY_PORT);
+        AuthScope scope = null;
+        if (hostConfig != null) {
+            scope = new AuthScope(hostConfig.getHost(), hostConfig.getPort());
+        } else {
+            scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
+        }
         Credentials credentials;
         if (domain != null && host != null) {
             credentials = new 
NTCredentials((String)this.username.evaluate(exchange, message), 

Modified: 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?rev=1061902&r1=1061901&r2=1061902&view=diff
==============================================================================
--- 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
 (original)
+++ 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
 Fri Jan 21 16:51:25 2011
@@ -156,6 +156,8 @@ public class HttpConfiguration implement
    */
     private boolean preemptiveAuthentication;
 
+    private boolean useHostPortForAuthScope;
+
     /**
      * @return Returns the rootDir.
      * @org.apache.xbean.Property hidden="true"
@@ -678,14 +680,36 @@ public class HttpConfiguration implement
     }
 
     /**
-     *
+     * Specifies of the httpclient uses preemptive authentication which can 
save performance. The default is false.
+     * If enabled it always send credentials also if it is not needed. 
      * @param preemptiveAuthentication the value which strategy should be used
+     *
+     * @org.apache.xbean.Property description="Specifies of the httpclient 
uses preemptive authentication which can save performance. The default is false"
      */
     public void setPreemptiveAuthentication(boolean preemptiveAuthentication) {
         this.preemptiveAuthentication = preemptiveAuthentication;
         save();
     }
 
+    /**
+     *
+     * @return true if AuthScope of httpclient depeneds on host and port
+     */
+    public boolean isUseHostPortForAuthScope() {
+        return useHostPortForAuthScope;
+    }
+
+    /**
+     *
+     * @param useHostPortForAuthScope If true the AuthScope of the httpclient 
is bind to a special host and port from the url. The default is false
+     *
+     * @org.apache.xbean.Property description="If true the AuthScope of the 
httpclient is bind to a special host and port from the url. The default is 
false"
+     */
+    public void setUseHostPortForAuthScope(boolean useHostPortForAuthScope) {
+        this.useHostPortForAuthScope = useHostPortForAuthScope;
+        save();
+    }
+
     public void save() {
         setProperty(componentName + ".jettyThreadPoolSize", 
Integer.toString(jettyThreadPoolSize));
         setProperty(componentName + ".jettyClientThreadPoolSize", 
Integer.toString(jettyClientThreadPoolSize));
@@ -708,6 +732,7 @@ public class HttpConfiguration implement
         setProperty(componentName + ".wantHeadersFromHttpIntoExchange", Boolean
             .toString(wantHeadersFromHttpIntoExchange));
         setProperty(componentName + ".preemptiveAuthentication", 
Boolean.toString(preemptiveAuthentication));
+        setProperty(componentName + ".useHostPortForAuthScope", 
Boolean.toString(useHostPortForAuthScope));
         if (rootDir != null) {
             File f = new File(rootDir, CONFIG_FILE);
             try {
@@ -825,6 +850,9 @@ public class HttpConfiguration implement
             preemptiveAuthentication = 
Boolean.valueOf(properties.getProperty(componentName + 
".preemptiveAuthentication")).booleanValue();
         }
 
+        if (properties.getProperty(componentName + ".useHostPortForAuthScope") 
!= null) {
+            useHostPortForAuthScope = 
Boolean.valueOf(properties.getProperty(componentName + 
".useHostPortForAuthScope")).booleanValue();
+        }
         return true;
     }
 

Modified: 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=1061902&r1=1061901&r2=1061902&view=diff
==============================================================================
--- 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
 (original)
+++ 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
 Fri Jan 21 16:51:25 2011
@@ -153,8 +153,13 @@ public class ProviderProcessor extends A
             int retries = getConfiguration().isStreamingEnabled() ? 0 : 
getConfiguration().getRetryCount();
             method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
new DefaultHttpMethodRetryHandler(retries, true));
             // Set authentication
+            HostConfiguration hostConfig = getHostConfiguration(locationURI, 
exchange, nm);
             if (endpoint.getBasicAuthentication() != null) {
-                
endpoint.getBasicAuthentication().applyCredentials(getClient(), exchange, nm);
+                if (getConfiguration().isUseHostPortForAuthScope()) {
+                    
endpoint.getBasicAuthentication().applyCredentials(getClient(), exchange, nm, 
hostConfig);
+                } else {
+                    
endpoint.getBasicAuthentication().applyCredentials(getClient(), exchange, nm, 
null);
+                }
             }
             // Execute the HTTP method
             int response = 
getClient().executeMethod(getHostConfiguration(locationURI, exchange, nm), 
method);


Reply via email to