servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r542291 - in /incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http: BasicAuthCredentials.java processors/ProviderProcessor.java
Date Mon, 28 May 2007 18:44:16 GMT
Author: gertv
Date: Mon May 28 11:44:16 2007
New Revision: 542291

URL: http://svn.apache.org/viewvc?view=rev&rev=542291
Log:
Fix for SM-598: Dynamically determine basic authentication credentials for HTTP

Modified:
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
    incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java?view=diff&rev=542291&r1=542290&r2=542291
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
(original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/BasicAuthCredentials.java
Mon May 28 11:44:16 2007
@@ -16,10 +16,15 @@
  */
 package org.apache.servicemix.http;
 
+import javax.jbi.messaging.MessageExchange;
+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.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.servicemix.expression.Expression;
 
 /**
  * @author roehl.sioson
@@ -28,8 +33,8 @@
  */
 public class BasicAuthCredentials {
 
-    protected String username;
-    protected String password;
+    protected Expression username;
+    protected Expression password;
 
     public BasicAuthCredentials() {
     }
@@ -37,50 +42,61 @@
     /**
      * @return Returns the username.
      */
-    public String getUsername() {
+    public Expression getUsername() {
         return username;
     }
 
     /**
      * @param ssl The username to set.
      */
-    public void setUsername(String username) {
+    public void setUsername(Expression username) {
         this.username = username;
     }
 
     /**
      * @return Returns the password.
      */
-    public String getPassword() {
+    public Expression getPassword() {
         return password;
     }
 
     /**
      * @param ssl The password to set.
      */
-    public void setPassword(String password) {
+    public void setPassword(Expression password) {
         this.password = password;
     }
 
-    /**
+
+	/**
      * Applies this authentication to the given method.
      *
-     * @param method The method to receive authentication headers.
+     * @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
+	 * @throws MessagingException if the correct value for username/password cannot be determined
when using an expression
      */
-    public void applyCredentials(HttpClient client) {
+    public void applyCredentials(HttpClient client, MessageExchange exchange, NormalizedMessage
message) throws MessagingException {
         AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
-        Credentials credentials = new UsernamePasswordCredentials(this.username, this.password);
+        Credentials credentials = 
+        	new UsernamePasswordCredentials((String) this.username.evaluate(exchange, message),

+        									(String) this.password.evaluate(exchange, message));
         client.getState().setCredentials(scope, credentials);
     }
-
+    
     /**
      * Applies this authentication to the given method.
      *
-     * @param method The method to receive authentication headers.
+     * @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
+     * @throws MessagingException if the correct value for user name/password cannot be determined
when using an expression
      */
-    public void applyProxyCredentials(HttpClient client) {
+    public void applyProxyCredentials(HttpClient client, MessageExchange exchange, NormalizedMessage
message) throws MessagingException {
         AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
-        Credentials credentials = new UsernamePasswordCredentials(this.username, this.password);
+        Credentials credentials = 
+        	new UsernamePasswordCredentials((String) this.username.evaluate(exchange, message),

+        									(String) this.password.evaluate(exchange, message));
         client.getState().setProxyCredentials(scope, credentials);
     }
 

Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?view=diff&rev=542291&r1=542290&r2=542291
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
(original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
Mon May 28 11:44:16 2007
@@ -151,10 +151,10 @@
             method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(retries,
true));
             // Set authentication
             if (endpoint.getBasicAuthentication() != null) {
-                endpoint.getBasicAuthentication().applyCredentials(getClient());
+                endpoint.getBasicAuthentication().applyCredentials(getClient(), exchange,
nm);
             }
             // Execute the HTTP method
-            int response = getClient().executeMethod(getHostConfiguration(locationURI), method);
+            int response = getClient().executeMethod(getHostConfiguration(locationURI, exchange,
nm), method);
             if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED)
{
                 if (!(exchange instanceof InOnly)) {
                     SoapReader reader = soapHelper.getSoapMarshaler().createReader();
@@ -256,7 +256,7 @@
         return close;
     }
 
-    private HostConfiguration getHostConfiguration(String locationURI) throws Exception {
+    private HostConfiguration getHostConfiguration(String locationURI, MessageExchange exchange,
NormalizedMessage message) throws Exception {
         HostConfiguration host;
         URI uri = new URI(locationURI, false);
         if (uri.getScheme().equals("https")) {
@@ -280,7 +280,7 @@
                 host.setProxy(endpoint.getProxy().getProxyHost(), endpoint.getProxy().getProxyPort());
             }
             if (endpoint.getProxy().getProxyCredentials() != null) {
-                endpoint.getProxy().getProxyCredentials().applyProxyCredentials(getClient());
+                endpoint.getProxy().getProxyCredentials().applyProxyCredentials(getClient(),
exchange, message);
             }
         } else if ((getConfiguration().getProxyHost() != null) && (getConfiguration().getProxyPort()
!= 0)) {
             host.setProxy(getConfiguration().getProxyHost(), getConfiguration().getProxyPort());



Mime
View raw message