You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2006/09/30 15:18:09 UTC

svn commit: r451595 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http: AbstractHTTPSender.java HttpTransportProperties.java SOAPOverHTTPSender.java

Author: saminda
Date: Sat Sep 30 06:18:08 2006
New Revision: 451595

URL: http://svn.apache.org/viewvc?view=rev&rev=451595
Log:
Reverted back some changes and added some functionality for auth 
handling 

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?view=diff&rev=451595&r1=451594&r2=451595
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Sat Sep 30 06:18:08 2006
@@ -30,6 +30,7 @@
 import org.apache.axis2.util.Utils;
 import org.apache.commons.httpclient.*;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.auth.AuthPolicy;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -40,6 +41,7 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.zip.GZIPInputStream;
 
 public abstract class AbstractHTTPSender {
@@ -59,10 +61,10 @@
     int connectionTimeout = HTTPConstants.DEFAULT_CONNECTION_TIMEOUT;
 
     /**
-     * isAuthenticationEnabled will be used as a flag to check whether
-     * authentication is enabled or not.
+     * isAllowedRetry will be using to check where the
+     * retry should be allowed or not.
      */
-    protected boolean isAuthenticationEnabled = false;
+    protected boolean isAllowedRetry = false;
 
     public void setChunked(boolean chunked) {
         this.chunked = chunked;
@@ -297,7 +299,7 @@
         boolean isHostProxy = isProxyListed(msgCtx);    // list the proxy
 
         
-        isAuthenticationEnabled = isAuthenticationEnabled(msgCtx);
+        boolean isAuthenticationEnabled = isAuthenticationEnabled(msgCtx);
         int port = targetURL.getPort();
 
         if (port == -1) {
@@ -328,7 +330,8 @@
     }
 
     /*
-    This will handle server Authentication, It could be either NTLM, Digest or Basic Authentication
+    This will handle server Authentication, It could be either NTLM, Digest or Basic Authentication.
+    Apart from that user can change the priory or add a custom authentication scheme.
     */
     protected void setAuthenticationInfo(HttpClient agent,
                                                        MessageContext msgCtx,
@@ -351,6 +354,9 @@
                 int port = authenticator.getPort();
                 String realm = authenticator.getRealm();
 
+                /* If retrying is available set it first */
+                isAllowedRetry = authenticator.isAllowedRetry();
+
                 Credentials creds;
 
                 agent.getParams().setAuthenticationPreemptive(authenticator.getPreemptiveAuthentication());
@@ -368,6 +374,28 @@
                     /*Credentials only for Digest and Basic Authentication*/
                     creds = new UsernamePasswordCredentials(username, password);
                     agent.getState().setCredentials(new AuthScope(AuthScope.ANY), creds);
+                }
+
+                /* Customizing the priority Order */
+                List schemes = authenticator.getAuthSchemes();
+                if (schemes != null && schemes.size() > 0) {
+                    List authPrefs = new ArrayList(3);
+                    for (int i = 0; i < schemes.size(); i++) {
+                        if (schemes.get(i) instanceof AuthPolicy) {
+                            authPrefs.add(schemes.get(i));
+                            continue;
+                        }
+                        String scheme = (String) schemes.get(i);
+                        if (HttpTransportProperties.Authenticator.BASIC.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.BASIC);
+                        } else if (HttpTransportProperties.Authenticator.NTLM.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.NTLM);
+                        } else if (HttpTransportProperties.Authenticator.DIGEST.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.DIGEST);
+                        }
+                    }
+                    agent.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
+                                                   authPrefs);
                 }
 
             } else {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java?view=diff&rev=451595&r1=451594&r2=451595
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HttpTransportProperties.java Sat Sep 30 06:18:08 2006
@@ -18,8 +18,11 @@
 
 import org.apache.commons.httpclient.HttpVersion;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.auth.AuthPolicy;
 
+import java.util.List;
 import java.util.Properties;
+
 /**
  * Utility bean for setting transport properties in runtime.
  */
@@ -137,8 +140,16 @@
         /*Password of the user for authenticate*/
         private String password;
         /* Switch to use preemptive authentication or not*/
-        private boolean preempt = true;
-       /* Note: Registering a custom AuthPolicy yet to be given */
+        private boolean preemptive = false;
+        /* if Authentication scheme needs retry just turn on the following flag */
+        private boolean allowedRetry = false;
+        /* Changing the priorty or adding a custom AuthPolicy*/
+        private List authSchemes;
+
+        /* Default Auth Schems*/
+        public static final String NTLM = AuthPolicy.NTLM;
+        public static final String DIGEST = AuthPolicy.DIGEST;
+        public static final String BASIC = AuthPolicy.BASIC;
 
         public String getHost() {
             return host;
@@ -180,12 +191,12 @@
             this.password = password;
         }
 
-        public void setPreemptiveAuthentication(boolean preempt) {
-            this.preempt = preempt; 
+        public void setPreemptiveAuthentication(boolean preemptive) {
+            this.preemptive = preemptive;
         }
 
         public boolean getPreemptiveAuthentication() {
-            return this.preempt; 
+            return this.preemptive;
         }
 
         public String getDomain() {
@@ -194,6 +205,20 @@
 
         public void setDomain(String domain) {
             this.domain = domain;
+        }
+
+        public void setAuthSchemes(List authSchemes) {
+            this.authSchemes = authSchemes;
+        }
+
+        public List getAuthSchemes() {
+            return this.authSchemes;
+        }
+        public void setAllowedRetry(boolean allowedRetry){
+            this.allowedRetry = allowedRetry;
+        }
+        public boolean isAllowedRetry() {
+            return  this.allowedRetry;
         }
     }
     public static class MailProperties{

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?view=diff&rev=451595&r1=451594&r2=451595
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java Sat Sep 30 06:18:08 2006
@@ -174,14 +174,14 @@
 
 			if (!doingMTOM & doingSWA) {
 				 StringWriter bufferedSOAPBody = new StringWriter();
-				if (isAuthenticationEnabled) {
+				if (isAllowedRetry) {
 					element.serialize(bufferedSOAPBody, format);
 				} else {
 					element.serializeAndConsume(bufferedSOAPBody, format);
 				}
 				MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody,out,msgCtxt.getAttachmentMap(), format);
 			} else {
-				if (isAuthenticationEnabled) {
+				if (isAllowedRetry) {
 					element.serialize(out, format);
 				} else {
 					element.serializeAndConsume(out, format);



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org