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/05/15 07:07:28 UTC

svn commit: r406537 - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http: AbstractHTTPSender.java HTTPConstants.java HttpTransportProperties.java

Author: saminda
Date: Sun May 14 22:07:27 2006
New Revision: 406537

URL: http://svn.apache.org/viewcvs?rev=406537&view=rev
Log:
added server preemptive basic authentication scheme.Will upload docs asap

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

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=406537&r1=406536&r2=406537&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Sun May 14 22:07:27 2006
@@ -270,6 +270,8 @@
                                                      URL targetURL)
             throws AxisFault {
         boolean isHostProxy = isProxyListed(msgCtx);    // list the proxy
+
+        boolean basicAuthenticationEnabled = serverBasicPreemtiveAuthentication(msgCtx); // server authentication
         int port = targetURL.getPort();
 
         if (port == -1) {
@@ -279,8 +281,11 @@
         // to see the host is a proxy and in the proxy list - available in axis2.xml
         HostConfiguration config = new HostConfiguration();
 
-        if (!isHostProxy) {
+        if (!isHostProxy && !basicAuthenticationEnabled) {
             config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
+        }else if(basicAuthenticationEnabled){
+             // premtive authentication
+            this.configServerPreemtiveAuthenticaiton(client,msgCtx,config,targetURL);
         } else {
 
             // proxy and NTLM configuration
@@ -291,6 +296,42 @@
         return config;
     }
 
+    private void configServerPreemtiveAuthenticaiton(HttpClient agent,
+                                                     MessageContext msgCtx,
+                                                     HostConfiguration config,
+                                                     URL targetURL) {
+        config.setHost(targetURL.getHost(), targetURL.getPort(),
+                       targetURL.getProtocol());
+
+        agent.getParams().setAuthenticationPreemptive(true);
+
+        HttpTransportProperties.BasicAuthentication basicAuthentication =
+                (HttpTransportProperties.BasicAuthentication) msgCtx
+                        .getProperty(HTTPConstants.BASIC_AUTHENTICATION);
+        Credentials defaultCredentials = new UsernamePasswordCredentials(
+                basicAuthentication.getUsername(),
+                basicAuthentication.getPassword());
+        if (basicAuthentication.getPort() == -1 ||
+            basicAuthentication.getHost() == null) {
+            agent.getState().setCredentials(AuthScope.ANY, defaultCredentials);
+        } else {
+            if (basicAuthentication.getRealm() == null) {
+                agent.getState().setCredentials(new AuthScope(
+                        basicAuthentication.getHost(),
+                        basicAuthentication.getPort(),
+                        AuthScope.ANY_REALM), defaultCredentials);
+
+            } else {
+                agent.getState().setCredentials(new AuthScope(
+                        basicAuthentication.getHost(),
+                        basicAuthentication.getPort(),
+                        basicAuthentication.getRealm()), defaultCredentials);
+            }
+        }
+
+
+    }
+
     /**
      * This is used to get the dynamically set time out values from the
      * message context. If the values are not available or invalid then
@@ -321,6 +362,14 @@
             // If there's a problem log it and use the default values
             log.error("Invalid timeout value format: not a number", nfe);
         }
+    }
+
+    //Server Preemptive Authentication RUNTIME
+
+    private boolean serverBasicPreemtiveAuthentication(MessageContext msgContext) {
+
+        return msgContext.getProperty(HTTPConstants.BASIC_AUTHENTICATION) !=
+               null;
     }
 
     private boolean isProxyListed(MessageContext msgCtx) throws AxisFault {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=406537&r1=406536&r2=406537&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java Sun May 14 22:07:27 2006
@@ -370,6 +370,7 @@
      */
     public static final byte SENDER[] = "400".getBytes();
     public static final String PROXY = "PROXY";
+    public static final String BASIC_AUTHENTICATION = "_BASIC_AUTHENTICATION_";
     public static final String MTOM_RECEIVED_CONTENT_TYPE = "MTOM_RECEIVED";
 
     /**

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java?rev=406537&r1=406536&r2=406537&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HttpTransportProperties.java Sun May 14 22:07:27 2006
@@ -115,4 +115,51 @@
             this.userName = userName;
         }
     }
+    public class BasicAuthentication{
+        private String host;
+        private int port = -1;
+        private String realm;
+        private String username;
+        private String password;
+
+        public String getHost() {
+            return host;
+        }
+
+        public void setHost(String host) {
+            this.host = host;
+        }
+
+        public int getPort() {
+            return port;
+        }
+
+        public void setPort(int port) {
+            this.port = port;
+        }
+
+        public String getRealm() {
+            return realm;
+        }
+
+        public void setRealm(String realm) {
+            this.realm = realm;
+        }
+
+        public String getUsername() {
+            return username;
+        }
+
+        public void setUsername(String username) {
+            this.username = username;
+        }
+
+        public String getPassword() {
+            return password;
+        }
+
+        public void setPassword(String password) {
+            this.password = password;
+        }
+    }
 }