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 du...@apache.org on 2007/12/09 05:55:03 UTC
svn commit: r602635 - in /webservices/axis2/trunk/c: include/
samples/server/ src/core/clientapi/ src/core/transport/http/sender/
Author: dumindu
Date: Sat Dec 8 20:55:02 2007
New Revision: 602635
URL: http://svn.apache.org/viewvc?rev=602635&view=rev
Log:
Fixing Jira issues 716, 757, 821, 817, 820, 814, 815 and 819.
(HTTP authentication and Proxy authetication related issues)
Thanks Senaka for the patch.
Modified:
webservices/axis2/trunk/c/include/axis2_const.h
webservices/axis2/trunk/c/include/axis2_http_transport.h
webservices/axis2/trunk/c/include/axis2_options.h
webservices/axis2/trunk/c/include/axis2_svc_client.h
webservices/axis2/trunk/c/samples/server/axis2.xml
webservices/axis2/trunk/c/src/core/clientapi/options.c
webservices/axis2/trunk/c/src/core/clientapi/svc_client.c
webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c
Modified: webservices/axis2/trunk/c/include/axis2_const.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_const.h?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_const.h (original)
+++ webservices/axis2/trunk/c/include/axis2_const.h Sat Dec 8 20:55:02 2007
@@ -313,6 +313,12 @@
#define AXIS2_ENABLE_REST "enableREST"
#define AXIS2_ENABLE_REST_THROUGH_GET "restThroughGet"
+#define AXIS2_FORCE_PROXY_AUTH "forceProxyAuth"
+#define AXIS2_FORCE_HTTP_AUTH "forceHTTPAuth"
+
+#define AXIS2_PROXY_AUTH_TYPE "proxyAuthType"
+#define AXIS2_HTTP_AUTH_TYPE "HTTPAuthType"
+
/* globally enable MTOM */
#define AXIS2_ENABLE_MTOM "enableMTOM"
#define AXIS2_ATTACHMENT_TEMP_DIR "attachmentDIR"
Modified: webservices/axis2/trunk/c/include/axis2_http_transport.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_http_transport.h?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_transport.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_transport.h Sat Dec 8 20:55:02 2007
@@ -74,6 +74,11 @@
#define AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL 401
/**
+ * AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL
+ */
+#define AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL 407
+
+ /**
* RESPONSE_ACK_CODE_VAL
*/
#define AXIS2_HTTP_RESPONSE_ACK_CODE_VAL 202
@@ -190,6 +195,11 @@
#define AXIS2_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
/**
+ * HEADER_PROXY_AUTHENTICATE
+ */
+#define AXIS2_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
+
+ /**
* HEADER_PROXY_AUTHORIZATION
*/
#define AXIS2_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
@@ -371,6 +381,11 @@
#define AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED "401 Unauthorized"
/**
+ * RESPONSE_PROXY_AUTHENTICATION_REQUIRED
+ */
+#define AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED "401 Proxy Authentication Required"
+
+ /**
* RESPONSE_BAD_REQUEST
*/
#define AXIS2_HTTP_RESPONSE_BAD_REQUEST "400 Bad Request"
@@ -433,6 +448,21 @@
#define MTOM_RECIVED_CONTENT_TYPE "MTOM_RECEIVED"
/**
+ * Constant for HTTP authentication
+ */
+#define AXIS2_HTTP_AUTHENTICATION "HTTP-Authentication"
+
+ /**
+ * Constant for HTTP authentication username
+ */
+#define AXIS2_HTTP_AUTHENTICATION_USERNAME "http_authentication_username"
+
+ /**
+ * Constant for HTTP authentication password
+ */
+#define AXIS2_HTTP_AUTHENTICATION_PASSWORD "http_authentication_password"
+
+ /**
* Constant for HTTP proxy
*/
#define AXIS2_HTTP_PROXY "PROXY"
@@ -447,6 +477,17 @@
*/
#define AXIS2_HTTP_PROXY_PORT "proxy_port"
+ /**
+ * Constant for HTTP proxy username
+ */
+#define AXIS2_HTTP_PROXY_USERNAME "proxy_username"
+
+ /**
+ * Constant for HTTP proxy password
+ */
+#define AXIS2_HTTP_PROXY_PASSWORD "proxy_password"
+
+
#define AXIS2_HTTP_PROXY_API "PROXY_API"
/**
@@ -479,6 +520,17 @@
*/
#define AXIS2_HTTP_AUTH_PASSWD "HTTP_AUTH_PASSWD"
+ /**
+ * Proxy authentication username property name
+ */
+#define AXIS2_PROXY_AUTH_UNAME "PROXY_AUTH_USERNAME"
+
+ /**
+ * Proxy authentication password property name
+ */
+#define AXIS2_PROXY_AUTH_PASSWD "PROXY_AUTH_PASSWD"
+
+
/*#define AXIS2_HTTP_AUTH_TYPE "HTTP_AUTH_TYPE"*/
/**
@@ -490,6 +542,17 @@
* HTTP "Digest" authentication
*/
#define AXIS2_HTTP_AUTH_TYPE_DIGEST "Digest"
+
+ /**
+ * Proxy "Basic" authentication
+ */
+#define AXIS2_PROXY_AUTH_TYPE_BASIC "Basic"
+
+ /**
+ * Proxy "Digest" authentication
+ */
+#define AXIS2_PROXY_AUTH_TYPE_DIGEST "Digest"
+
/**
*HTTP Transport Level Error
Modified: webservices/axis2/trunk/c/include/axis2_options.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_options.h?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_options.h (original)
+++ webservices/axis2/trunk/c/include/axis2_options.h Sat Dec 8 20:55:02 2007
@@ -737,8 +737,8 @@
axis2_options_t * options,
const axutil_env_t * env,
const axis2_bool_t enable_rest);
-
- /**
+
+/**
* Sets the HTTP method to be used
* @param options pointer to options struct
* @param env pointer to environment struct
@@ -775,6 +775,44 @@
axis2_options_create_with_parent(
const axutil_env_t * env,
axis2_options_t * parent);
+
+ /**
+ * Sets HTTP authentication information.
+ * @param env pointer to environment stnuct
+ * @param parent pointer to parent struct
+ * @param username string representing username
+ * @param password string representing password
+ * @param auth_type use "Basic" to force basic authentication
+ * and "Digest" to force digest authentication or NULL for not
+ * forcing authentication
+ * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axis2_options_set_http_auth_info(
+ axis2_options_t * options,
+ const axutil_env_t * env,
+ const axis2_char_t * username,
+ const axis2_char_t * password,
+ const axis2_char_t * auth_type);
+
+ /**
+ * Sets proxy authentication information.
+ * @param env pointer to environment stnuct
+ * @param parent pointer to parent struct
+ * @param username string representing username
+ * @param password string representing password
+ * @param auth_type use "Basic" to force basic authentication
+ * and "Digest" to force digest authentication or NULL for not
+ * forcing authentication
+ * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
+ */
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axis2_options_set_proxy_auth_info(
+ axis2_options_t * options,
+ const axutil_env_t * env,
+ const axis2_char_t * username,
+ const axis2_char_t * password,
+ const axis2_char_t * auth_type);
/** @} */
#ifdef __cplusplus
Modified: webservices/axis2/trunk/c/include/axis2_svc_client.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/include/axis2_svc_client.h?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_svc_client.h (original)
+++ webservices/axis2/trunk/c/include/axis2_svc_client.h Sat Dec 8 20:55:02 2007
@@ -407,16 +407,34 @@
axis2_endpoint_ref_t * target_epr);
/**
- * Sets the proxy.
+ * Sets the proxy with authentication support.
* @param svc_client pointer to service client struct
* @param env pointer to environment struct
* @param proxy_host pointer to the proxy_host settings to be set
- * as
* @param proxy_port pointer to the proxy_port settings to be set
- * as
- * target. service client takes over the ownership of the struct.
+ * @param username pointer to the username associated with proxy
+ * which is required for authentication
+ * @param password pointer to the password associated with proxy
+ * which is required for authentication
* @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
*/
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ axis2_svc_client_set_proxy_with_auth(
+ axis2_svc_client_t * svc_client,
+ const axutil_env_t * env,
+ axis2_char_t * proxy_host,
+ axis2_char_t * proxy_port,
+ axis2_char_t * username,
+ axis2_char_t * password);
+
+ /**
+ * Sets the proxy.
+ * @param svc_client pointer to service client struct
+ * @param env pointer to environment struct
+ * @param proxy_host pointer to the proxy_host settings to be set
+ * @param proxy_port pointer to the proxy_port settings to be set
+ * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
+ */
AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_svc_client_set_proxy(
axis2_svc_client_t * svc_client,
Modified: webservices/axis2/trunk/c/samples/server/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/samples/server/axis2.xml?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/samples/server/axis2.xml (original)
+++ webservices/axis2/trunk/c/samples/server/axis2.xml Sat Dec 8 20:55:02 2007
@@ -39,7 +39,8 @@
<transportSender name="http" class="axis2_http_sender">
<parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
<!--parameter name="Transfer-Encoding">chunked</parameter-->
- <!--parameter name="PROXY" proxy_host="127.0.0.1" proxy_port="8080" locked="true"/-->
+ <!--parameter name="HTTP-Authentication" http_authentication_username="" http_authentication_password="" locked="true"/-->
+ <!--parameter name="PROXY" proxy_host="127.0.0.1" proxy_port="8080" proxy_username="" proxy_password="" locked="true"/-->
</transportSender>
<!-- Uncomment this one with the appropriate papameters to enable the XMPP transport Sender-->
<!--transportSender name="xmpp" class="axis2_xmpp_sender">
Modified: webservices/axis2/trunk/c/src/core/clientapi/options.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/clientapi/options.c?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/clientapi/options.c (original)
+++ webservices/axis2/trunk/c/src/core/clientapi/options.c Sat Dec 8 20:55:02 2007
@@ -934,3 +934,108 @@
method_property);
return AXIS2_SUCCESS;
}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_options_set_proxy_auth_info(
+ axis2_options_t * options,
+ const axutil_env_t * env,
+ const axis2_char_t * username,
+ const axis2_char_t * password,
+ const axis2_char_t * auth_type)
+{
+ AXIS2_ENV_CHECK(env, NULL);
+ axutil_property_t *prop_un = axutil_property_create(env);
+ axutil_property_set_value(prop_un, env, axutil_strdup(env, username));
+ axis2_options_set_property(options, env, AXIS2_PROXY_AUTH_UNAME, prop_un);
+
+ axutil_property_t *prop_pw = axutil_property_create(env);
+ axutil_property_set_value(prop_pw, env, axutil_strdup(env, password));
+ axis2_options_set_property(options, env, AXIS2_PROXY_AUTH_PASSWD, prop_pw);
+
+ axis2_bool_t force_proxy_auth = AXIS2_FALSE;
+
+ if(auth_type)
+ {
+ if ((axutil_strcmp (auth_type, AXIS2_PROXY_AUTH_TYPE_BASIC) == 0) ||
+ (axutil_strcmp (auth_type, AXIS2_PROXY_AUTH_TYPE_DIGEST) == 0))
+ {
+ force_proxy_auth = AXIS2_TRUE;
+ }
+ }
+ if (force_proxy_auth)
+ {
+ axutil_property_t *proxy_auth_property = axutil_property_create(env);
+ axutil_property_set_value(proxy_auth_property, env,
+ axutil_strdup(env, AXIS2_VALUE_TRUE));
+ axis2_options_set_property(options, env, AXIS2_FORCE_PROXY_AUTH,
+ proxy_auth_property);
+
+ axutil_property_t *proxy_auth_type_property = axutil_property_create(env);
+ axutil_property_set_value(proxy_auth_type_property, env,
+ axutil_strdup(env, auth_type));
+ axis2_options_set_property(options, env, AXIS2_PROXY_AUTH_TYPE,
+ proxy_auth_type_property);
+ }
+ else
+ {
+ axutil_property_t *proxy_auth_property = axutil_property_create(env);
+ axutil_property_set_value(proxy_auth_property, env,
+ axutil_strdup(env, AXIS2_VALUE_FALSE));
+ axis2_options_set_property(options, env, AXIS2_FORCE_PROXY_AUTH,
+ proxy_auth_property);
+ }
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_options_set_http_auth_info(
+ axis2_options_t * options,
+ const axutil_env_t * env,
+ const axis2_char_t * username,
+ const axis2_char_t * password,
+ const axis2_char_t * auth_type)
+{
+ AXIS2_ENV_CHECK(env, NULL);
+ axutil_property_t *prop_un = axutil_property_create(env);
+ axutil_property_set_value(prop_un, env, axutil_strdup(env, username));
+ axis2_options_set_property(options, env, AXIS2_HTTP_AUTH_UNAME, prop_un);
+
+ axutil_property_t *prop_pw = axutil_property_create(env);
+ axutil_property_set_value(prop_pw, env, axutil_strdup(env, password));
+ axis2_options_set_property(options, env, AXIS2_HTTP_AUTH_PASSWD, prop_pw);
+
+ axis2_bool_t force_http_auth = AXIS2_FALSE;
+
+ if (auth_type)
+ {
+ if ((axutil_strcmp (auth_type, AXIS2_HTTP_AUTH_TYPE_BASIC) == 0) ||
+ (axutil_strcmp (auth_type, AXIS2_HTTP_AUTH_TYPE_DIGEST) == 0))
+ {
+ force_http_auth = AXIS2_TRUE;
+ }
+ }
+ if (force_http_auth)
+ {
+ axutil_property_t *http_auth_property = axutil_property_create(env);
+ axutil_property_set_value(http_auth_property, env,
+ axutil_strdup(env, AXIS2_VALUE_TRUE));
+ axis2_options_set_property(options, env, AXIS2_FORCE_HTTP_AUTH,
+ http_auth_property);
+
+ axutil_property_t *http_auth_type_property = axutil_property_create(env);
+ axutil_property_set_value(http_auth_type_property, env,
+ axutil_strdup(env, auth_type));
+ axis2_options_set_property(options, env, AXIS2_HTTP_AUTH_TYPE,
+ http_auth_type_property);
+ }
+ else
+ {
+ axutil_property_t *http_auth_property = axutil_property_create(env);
+ axutil_property_set_value(http_auth_property, env,
+ axutil_strdup(env, AXIS2_VALUE_FALSE));
+ axis2_options_set_property(options, env, AXIS2_FORCE_HTTP_AUTH,
+ http_auth_property);
+ }
+ return AXIS2_SUCCESS;
+}
+
Modified: webservices/axis2/trunk/c/src/core/clientapi/svc_client.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/clientapi/svc_client.c?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/clientapi/svc_client.c (original)
+++ webservices/axis2/trunk/c/src/core/clientapi/svc_client.c Sat Dec 8 20:55:02 2007
@@ -1417,11 +1417,13 @@
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
-axis2_svc_client_set_proxy(
+axis2_svc_client_set_proxy_with_auth(
axis2_svc_client_t * svc_client,
const axutil_env_t * env,
axis2_char_t * proxy_host,
- axis2_char_t * proxy_port)
+ axis2_char_t * proxy_port,
+ axis2_char_t * username,
+ axis2_char_t * password)
{
axis2_transport_out_desc_t *trans_desc = NULL;
axis2_conf_t *conf = NULL;
@@ -1431,8 +1433,12 @@
axutil_hash_t *attribute;
axutil_generic_obj_t *host_obj = NULL;
axutil_generic_obj_t *port_obj = NULL;
+ axutil_generic_obj_t *username_obj = NULL;
+ axutil_generic_obj_t *password_obj = NULL;
axiom_attribute_t *host_attr = NULL;
axiom_attribute_t *port_attr = NULL;
+ axiom_attribute_t *username_attr = NULL;
+ axiom_attribute_t *password_attr = NULL;
AXIS2_PARAM_CHECK(env->error, svc_client, AXIS2_FAILURE);
AXIS2_PARAM_CHECK(env->error, proxy_host, AXIS2_FAILURE);
@@ -1455,7 +1461,7 @@
{
return AXIS2_FAILURE;
}
-
+
attribute = axutil_hash_make(env);
host_obj = axutil_generic_obj_create(env);
port_obj = axutil_generic_obj_create(env);
@@ -1468,11 +1474,33 @@
host_obj);
axutil_hash_set(attribute, AXIS2_HTTP_PROXY_PORT, AXIS2_HASH_KEY_STRING,
port_obj);
+ if (username && password)
+ {
+ username_obj = axutil_generic_obj_create(env);
+ password_obj = axutil_generic_obj_create(env);
+ username_attr = axiom_attribute_create(env, username, NULL, NULL);
+ password_attr = axiom_attribute_create(env, password, NULL, NULL);
+ axutil_generic_obj_set_value(username_obj, env, username_attr);
+ axutil_generic_obj_set_value(password_obj, env, password_attr);
+ axutil_hash_set(attribute, AXIS2_HTTP_PROXY_USERNAME, AXIS2_HASH_KEY_STRING,
+ username_obj);
+ axutil_hash_set(attribute, AXIS2_HTTP_PROXY_PASSWORD, AXIS2_HASH_KEY_STRING,
+ password_obj);
+ }
axutil_param_set_attributes(param, env, attribute);
axutil_param_container_add_param(param_container, env, param);
-
}
return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_svc_client_set_proxy(
+ axis2_svc_client_t * svc_client,
+ const axutil_env_t * env,
+ axis2_char_t * proxy_host,
+ axis2_char_t * proxy_port)
+{
+ return axis2_svc_client_set_proxy_with_auth(svc_client, env, proxy_host, proxy_port, NULL, NULL);
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
Modified: webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c?rev=602635&r1=602634&r2=602635&view=diff
==============================================================================
--- webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c (original)
+++ webservices/axis2/trunk/c/src/core/transport/http/sender/http_sender.c Sat Dec 8 20:55:02 2007
@@ -86,11 +86,24 @@
axis2_http_simple_request_t * request);
static axis2_status_t
+axis2_http_sender_configure_proxy_auth (axis2_http_sender_t * sender,
+ const axutil_env_t * env,
+ axis2_msg_ctx_t * msg_ctx,
+ axis2_http_simple_request_t * request);
+
+static axis2_status_t
axis2_http_sender_configure_http_basic_auth (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t *
request);
+
+static axis2_status_t
+axis2_http_sender_configure_proxy_basic_auth (axis2_http_sender_t * sender,
+ const axutil_env_t * env,
+ axis2_msg_ctx_t * msg_ctx,
+ axis2_http_simple_request_t *
+ request);
#endif
AXIS2_EXTERN axis2_http_sender_t *AXIS2_CALL
@@ -171,6 +184,12 @@
axutil_property_t *dump_property = NULL;
axutil_param_t *ssl_pp_param = NULL; /* ssl passphrase */
axis2_char_t *ssl_pp = NULL;
+ axutil_property_t *proxy_auth_property = NULL;
+ axis2_char_t *proxy_auth_property_value = NULL;
+ axis2_bool_t force_proxy_auth = AXIS2_FALSE;
+ axutil_property_t *http_auth_property = NULL;
+ axis2_char_t *http_auth_property_value = NULL;
+ axis2_bool_t force_http_auth = AXIS2_FALSE;
axutil_property_t *content_type_property = NULL;
axutil_hash_t *content_type_hash = NULL;
axis2_char_t *content_type_value = NULL;
@@ -583,26 +602,111 @@
ssl_pp = axutil_param_get_value (ssl_pp_param, env);
}
- /* how should this status_code be handled? */
- status_code = axis2_http_client_send (sender->client, env, request, ssl_pp);
+ proxy_auth_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_FORCE_PROXY_AUTH);
+ if (proxy_auth_property)
+ proxy_auth_property_value = (axis2_char_t *) axutil_property_get_value (proxy_auth_property,
+ env);
+
+ if (proxy_auth_property_value && 0 == axutil_strcmp (proxy_auth_property_value, AXIS2_VALUE_TRUE))
+ {
+ force_proxy_auth = AXIS2_TRUE;
+ }
+ http_auth_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_FORCE_HTTP_AUTH);
+ if (http_auth_property)
+ http_auth_property_value = (axis2_char_t *) axutil_property_get_value (http_auth_property,
+ env);
+
+ if (http_auth_property_value && 0 == axutil_strcmp (http_auth_property_value, AXIS2_VALUE_TRUE))
+ {
+ force_http_auth = AXIS2_TRUE;
+ }
- status_code = axis2_http_client_recieve_header (sender->client, env);
+ axis2_bool_t http_auth_header_added = AXIS2_FALSE;
- if (AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL == status_code)
+ if (force_proxy_auth)
+ {
+ status_code = AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL;
+ }
+ else
+ {
+ if (force_http_auth)
+ {
+ axis2_status_t auth_status;
+ auth_status = axis2_http_sender_configure_http_auth (sender,
+ env,
+ msg_ctx, request);
+
+ if (auth_status != AXIS2_SUCCESS)
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Error in setting HTTP"
+ " Authentication header");
+ http_auth_header_added = AXIS2_TRUE;
+ }
+ /* how should this status_code be handled? */
+ status_code = axis2_http_client_send (sender->client, env, request, ssl_pp);
+
+ status_code = axis2_http_client_recieve_header (sender->client, env);
+ }
+
+ if (AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL == status_code)
{
axis2_status_t auth_status;
- auth_status = axis2_http_sender_configure_http_auth (sender,
+ auth_status = axis2_http_sender_configure_proxy_auth (sender,
env,
msg_ctx, request);
if (auth_status != AXIS2_SUCCESS)
- AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Error in setting HTTP"
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Error in setting Proxy"
" Authentication header");
- status_code = axis2_http_client_send (sender->client,
- env, request, ssl_pp);
+ if (force_http_auth && !http_auth_header_added)
+ {
+ status_code = AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL;
+ }
+ else
+ {
+ /* how should this status_code be handled? */
+ status_code = axis2_http_client_send (sender->client, env, request, ssl_pp);
- status_code = axis2_http_client_recieve_header (sender->client, env);
+ status_code = axis2_http_client_recieve_header (sender->client, env);
+ if (AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL == status_code)
+ {
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Proxy Authentication failed");
+ }
+ }
+ }
+
+ if (AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL == status_code)
+ {
+ if (!http_auth_header_added)
+ {
+ axis2_status_t auth_status;
+ auth_status = axis2_http_sender_configure_http_auth (sender,
+ env,
+ msg_ctx, request);
+
+ if (auth_status != AXIS2_SUCCESS)
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Error in setting HTTP"
+ " Authentication header");
+
+ status_code = axis2_http_client_send (sender->client,
+ env, request, ssl_pp);
+
+ status_code = axis2_http_client_recieve_header (sender->client, env);
+ if (AXIS2_HTTP_RESPONSE_HTTP_UNAUTHORIZED_CODE_VAL == status_code)
+ {
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "HTTP Authentication failed");
+ }
+ if (AXIS2_HTTP_RESPONSE_PROXY_AUTHENTICATION_REQUIRED_CODE_VAL == status_code)
+ {
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Proxy Authentication failed");
+ }
+ }
+ else
+ {
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "HTTP Authentication failed");
+ }
}
/*AXIS2_FREE(env->allocator, buffer);
buffer = NULL; */
@@ -878,7 +982,7 @@
return AXIS2_SUCCESS;
}
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_http_sender_set_http_version (axis2_http_sender_t * sender,
const axutil_env_t * env,
axis2_char_t * version)
@@ -947,7 +1051,14 @@
proxy_param =
axutil_param_container_get_param
(axis2_transport_out_desc_param_container (trans_desc, env), env,
- AXIS2_HTTP_PROXY);
+ AXIS2_HTTP_PROXY_API);
+ if (!proxy_param)
+ {
+ proxy_param =
+ axutil_param_container_get_param
+ (axis2_transport_out_desc_param_container (trans_desc, env), env,
+ AXIS2_HTTP_PROXY);
+ }
if (proxy_param)
{
transport_attrs = axutil_param_get_attributes (proxy_param, env);
@@ -992,59 +1103,6 @@
}
}
}
- else
- {
- proxy_param =
- axutil_param_container_get_param
- (axis2_transport_out_desc_param_container (trans_desc, env), env,
- AXIS2_HTTP_PROXY_API);
- if (proxy_param)
- {
- transport_attrs = axutil_param_get_attributes (proxy_param, env);
- if (transport_attrs)
- {
- axutil_generic_obj_t *obj = NULL;
- axiom_attribute_t *host_attr = NULL;
- axiom_attribute_t *port_attr = NULL;
-
- obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_PROXY_HOST,
- AXIS2_HASH_KEY_STRING);
- if (!obj)
- {
- return AXIS2_FAILURE;
- }
- host_attr =
- (axiom_attribute_t *) axutil_generic_obj_get_value (obj, env);
- if (!host_attr)
- {
- return AXIS2_FAILURE;
- }
- proxy_host = axiom_attribute_get_localname (host_attr, env);
- if (!proxy_host)
- {
- return AXIS2_FAILURE;
- }
- /* Now we get the port */
- obj = NULL;
-
- obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_PROXY_PORT,
- AXIS2_HASH_KEY_STRING);
- port_attr =
- (axiom_attribute_t *) axutil_generic_obj_get_value (obj, env);
- if (!port_attr)
- {
- return AXIS2_FAILURE;
- }
-
- proxy_port = axiom_attribute_get_localname (port_attr, env);
- if (!proxy_port)
- {
- return AXIS2_FAILURE;
- }
-
- }
- }
- }
if (proxy_port && proxy_host)
{
axis2_http_client_set_proxy (sender->client, env, proxy_host,
@@ -1160,45 +1218,231 @@
{
uname = (axis2_char_t *) axutil_property_get_value (http_auth_un, env);
passwd = (axis2_char_t *) axutil_property_get_value (http_auth_pw, env);
+ }
+ if (!uname || !passwd)
+ {
+ axis2_conf_ctx_t *conf_ctx = NULL;
+ axis2_conf_t *conf = NULL;
+ axis2_transport_out_desc_t *trans_desc = NULL;
+ axutil_param_t *http_auth_param = NULL;
+ axutil_hash_t *transport_attrs = NULL;
- if (uname && passwd)
+ conf_ctx = axis2_msg_ctx_get_conf_ctx (msg_ctx, env);
+ if (conf_ctx)
{
- int elen;
- int plen = axutil_strlen (uname) + axutil_strlen (passwd) + 1;
- axis2_char_t *to_encode =
- (axis2_char_t
- *) (AXIS2_MALLOC (env->allocator, sizeof (axis2_char_t) * plen));
- axis2_char_t *encoded = NULL;
- axis2_char_t *auth_str = NULL;
- sprintf (to_encode, "%s:%s", uname, passwd);
- elen = axutil_base64_encode_len (plen);
- encoded = (axis2_char_t *) (AXIS2_MALLOC (env->allocator,
- sizeof (axis2_char_t) *
- elen));
- auth_str =
- (axis2_char_t
- *) (AXIS2_MALLOC (env->allocator,
- sizeof (axis2_char_t) * (elen + 6)));
- axutil_base64_encode (encoded, to_encode, plen);
- sprintf (auth_str, "%s %s", AXIS2_HTTP_AUTH_TYPE_BASIC, encoded);
- axis2_http_sender_util_add_header (env, request,
- AXIS2_HTTP_HEADER_AUTHORIZATION,
- auth_str);
-
- AXIS2_FREE (env->allocator, to_encode);
- to_encode = NULL;
- AXIS2_FREE (env->allocator, encoded);
- encoded = NULL;
- AXIS2_FREE (env->allocator, auth_str);
- auth_str = NULL;
+ conf = axis2_conf_ctx_get_conf (conf_ctx, env);
+ if (conf)
+ {
+ trans_desc = axis2_conf_get_transport_out (conf,
+ env, AXIS2_TRANSPORT_ENUM_HTTP);
+ }
+ }
+ if (trans_desc)
+ {
+ http_auth_param =
+ axutil_param_container_get_param
+ (axis2_transport_out_desc_param_container (trans_desc, env), env,
+ AXIS2_HTTP_AUTHENTICATION);
+ if (http_auth_param)
+ {
+ transport_attrs = axutil_param_get_attributes (http_auth_param, env);
+ if (transport_attrs)
+ {
+ axutil_generic_obj_t *obj = NULL;
+ axiom_attribute_t *username_attr = NULL;
+ axiom_attribute_t *password_attr = NULL;
+
+ obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_AUTHENTICATION_USERNAME,
+ AXIS2_HASH_KEY_STRING);
+ if (obj)
+ {
+ username_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj,
+ env);
+ }
+ if (username_attr)
+ {
+ uname = axiom_attribute_get_value (username_attr, env);
+ }
+ obj = NULL;
- return AXIS2_SUCCESS;
+ obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_AUTHENTICATION_PASSWORD,
+ AXIS2_HASH_KEY_STRING);
+ if (obj)
+ {
+ password_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj,
+ env);
+ }
+ if (password_attr)
+ {
+ passwd = axiom_attribute_get_value (password_attr, env);
+ }
+ }
+ }
}
}
+ if (uname && passwd)
+ {
+ int elen;
+ int plen = axutil_strlen (uname) + axutil_strlen (passwd) + 1;
+ axis2_char_t *to_encode =
+ (axis2_char_t
+ *) (AXIS2_MALLOC (env->allocator, sizeof (axis2_char_t) * plen));
+ axis2_char_t *encoded = NULL;
+ axis2_char_t *auth_str = NULL;
+ sprintf (to_encode, "%s:%s", uname, passwd);
+ elen = axutil_base64_encode_len (plen);
+ encoded = (axis2_char_t *) (AXIS2_MALLOC (env->allocator,
+ sizeof (axis2_char_t) *
+ elen));
+ auth_str =
+ (axis2_char_t
+ *) (AXIS2_MALLOC (env->allocator,
+ sizeof (axis2_char_t) * (elen + 6)));
+ axutil_base64_encode (encoded, to_encode, plen);
+ sprintf (auth_str, "%s %s", AXIS2_HTTP_AUTH_TYPE_BASIC, encoded);
+ axis2_http_sender_util_add_header (env, request,
+ AXIS2_HTTP_HEADER_AUTHORIZATION,
+ auth_str);
+
+ AXIS2_FREE (env->allocator, to_encode);
+ to_encode = NULL;
+ AXIS2_FREE (env->allocator, encoded);
+ encoded = NULL;
+ AXIS2_FREE (env->allocator, auth_str);
+ auth_str = NULL;
+
+ return AXIS2_SUCCESS;
+ }
return AXIS2_FAILURE;
}
+
+static axis2_status_t
+axis2_http_sender_configure_proxy_basic_auth (axis2_http_sender_t * sender,
+ const axutil_env_t * env,
+ axis2_msg_ctx_t * msg_ctx,
+ axis2_http_simple_request_t *
+ request)
+{
+ axutil_property_t *proxy_auth_un = NULL;
+ axutil_property_t *proxy_auth_pw = NULL;
+ axis2_char_t *uname = NULL;
+ axis2_char_t *passwd = NULL;
+
+ proxy_auth_un = axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_PROXY_AUTH_UNAME);
+ proxy_auth_pw = axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_PROXY_AUTH_PASSWD);
+
+ if (proxy_auth_un && proxy_auth_pw)
+ {
+ uname = (axis2_char_t *) axutil_property_get_value (proxy_auth_un, env);
+ passwd = (axis2_char_t *) axutil_property_get_value (proxy_auth_pw, env);
+ }
+ if (!uname || !passwd)
+ {
+ axis2_conf_ctx_t *conf_ctx = NULL;
+ axis2_conf_t *conf = NULL;
+ axis2_transport_out_desc_t *trans_desc = NULL;
+ axutil_param_t *proxy_param = NULL;
+ axutil_hash_t *transport_attrs = NULL;
+
+ conf_ctx = axis2_msg_ctx_get_conf_ctx (msg_ctx, env);
+ if (conf_ctx)
+ {
+ conf = axis2_conf_ctx_get_conf (conf_ctx, env);
+ if (conf)
+ {
+ trans_desc = axis2_conf_get_transport_out (conf,
+ env, AXIS2_TRANSPORT_ENUM_HTTP);
+ }
+ }
+ if (trans_desc)
+ {
+ proxy_param =
+ axutil_param_container_get_param
+ (axis2_transport_out_desc_param_container (trans_desc, env), env,
+ AXIS2_HTTP_PROXY_API);
+ if (!proxy_param)
+ {
+ proxy_param =
+ axutil_param_container_get_param
+ (axis2_transport_out_desc_param_container (trans_desc, env), env,
+ AXIS2_HTTP_PROXY);
+ }
+ if (proxy_param)
+ {
+ transport_attrs = axutil_param_get_attributes (proxy_param, env);
+ if (transport_attrs)
+ {
+ axutil_generic_obj_t *obj = NULL;
+ axiom_attribute_t *username_attr = NULL;
+ axiom_attribute_t *password_attr = NULL;
+
+ obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_PROXY_USERNAME,
+ AXIS2_HASH_KEY_STRING);
+ if (obj)
+ {
+ username_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj,
+ env);
+ }
+ if (username_attr)
+ {
+ uname = axiom_attribute_get_value (username_attr, env);
+ }
+ obj = NULL;
+
+ obj = axutil_hash_get (transport_attrs, AXIS2_HTTP_PROXY_PASSWORD,
+ AXIS2_HASH_KEY_STRING);
+ if (obj)
+ {
+ password_attr = (axiom_attribute_t *) axutil_generic_obj_get_value (obj,
+ env);
+ }
+ if (password_attr)
+ {
+ passwd = axiom_attribute_get_value (password_attr, env);
+ }
+ }
+ }
+ }
+ }
+ if (uname && passwd)
+ {
+ int elen;
+ int plen = axutil_strlen (uname) + axutil_strlen (passwd) + 1;
+ axis2_char_t *to_encode =
+ (axis2_char_t
+ *) (AXIS2_MALLOC (env->allocator, sizeof (axis2_char_t) * plen));
+ axis2_char_t *encoded = NULL;
+ axis2_char_t *auth_str = NULL;
+ sprintf (to_encode, "%s:%s", uname, passwd);
+ elen = axutil_base64_encode_len (plen);
+ encoded = (axis2_char_t *) (AXIS2_MALLOC (env->allocator,
+ sizeof (axis2_char_t) *
+ elen));
+ auth_str =
+ (axis2_char_t
+ *) (AXIS2_MALLOC (env->allocator,
+ sizeof (axis2_char_t) * (elen + 6)));
+ axutil_base64_encode (encoded, to_encode, plen);
+ sprintf (auth_str, "%s %s", AXIS2_PROXY_AUTH_TYPE_BASIC, encoded);
+ axis2_http_sender_util_add_header (env, request,
+ AXIS2_HTTP_HEADER_PROXY_AUTHORIZATION,
+ auth_str);
+
+ AXIS2_FREE (env->allocator, to_encode);
+ to_encode = NULL;
+ AXIS2_FREE (env->allocator, encoded);
+ encoded = NULL;
+ AXIS2_FREE (env->allocator, auth_str);
+ auth_str = NULL;
+
+ return AXIS2_SUCCESS;
+ }
+ return AXIS2_FAILURE;
+}
#endif
#ifndef AXIS2_LIBCURL_ENABLED
@@ -1212,6 +1456,17 @@
/*TODO: Implement Digest Auth */
return AXIS2_FAILURE;
}
+
+static axis2_status_t
+axis2_http_sender_configure_proxy_digest_auth (axis2_http_sender_t * sender,
+ const axutil_env_t * env,
+ axis2_msg_ctx_t * msg_ctx,
+ axis2_http_simple_request_t *
+ request)
+{
+ /*TODO: Implement Digest Auth */
+ return AXIS2_FAILURE;
+}
#endif
#ifndef AXIS2_LIBCURL_ENABLED
@@ -1221,29 +1476,61 @@
axis2_msg_ctx_t * msg_ctx,
axis2_http_simple_request_t * request)
{
- axis2_status_t status = AXIS2_FALSE;
axis2_char_t *auth_type = NULL;
- axis2_http_header_t *auth_header = NULL;
- axis2_http_simple_response_t *response = NULL;
- axis2_char_t *auth_type_end = NULL;
+ axis2_status_t status = AXIS2_FALSE;
+ axutil_property_t *http_auth_property = NULL;
+ axis2_char_t *http_auth_property_value = NULL;
+ axis2_bool_t force_http_auth = AXIS2_FALSE;
+ axutil_property_t *http_auth_type_property = NULL;
+ axis2_char_t *http_auth_type_property_value = NULL;
- response = axis2_http_client_get_response (sender->client, env);
+ http_auth_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_FORCE_HTTP_AUTH);
+ if (http_auth_property)
+ http_auth_property_value = (axis2_char_t *) axutil_property_get_value (http_auth_property,
+ env);
- if (response)
- auth_header = axis2_http_simple_response_get_first_header (response, env,
- AXIS2_HTTP_HEADER_WWW_AUTHENTICATE);
+ if (http_auth_property_value && 0 == axutil_strcmp (http_auth_property_value, AXIS2_VALUE_TRUE))
+ {
+ force_http_auth = AXIS2_TRUE;
+ }
- if (auth_header)
- auth_type = axis2_http_header_get_value (auth_header, env);
+ if (force_http_auth)
+ {
+ http_auth_type_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_HTTP_AUTH_TYPE);
+ if (http_auth_type_property)
+ http_auth_type_property_value = (axis2_char_t *) axutil_property_get_value (http_auth_type_property,
+ env);
- if (auth_type)
+ if (http_auth_type_property_value)
+ {
+ auth_type = http_auth_type_property_value;
+ }
+ }
+ else
{
- auth_type_end = axutil_strchr (auth_type, ' ');
- *auth_type_end = '\0';
- auth_type_end++;
- /*Read the realm and the rest stuff now from auth_type_end */
+ axis2_http_header_t *auth_header = NULL;
+ axis2_http_simple_response_t *response = NULL;
+ axis2_char_t *auth_type_end = NULL;
+
+ response = axis2_http_client_get_response (sender->client, env);
+
+ if (response)
+ auth_header = axis2_http_simple_response_get_first_header (response, env,
+ AXIS2_HTTP_HEADER_WWW_AUTHENTICATE);
+
+ if (auth_header)
+ auth_type = axis2_http_header_get_value (auth_header, env);
+
+ if (auth_type)
+ {
+ auth_type_end = axutil_strchr (auth_type, ' ');
+ *auth_type_end = '\0';
+ auth_type_end++;
+ /*Read the realm and the rest stuff now from auth_type_end */
+ }
}
-
if (auth_type)
{
if (axutil_strcmp (auth_type, AXIS2_HTTP_AUTH_TYPE_BASIC) == 0)
@@ -1252,6 +1539,90 @@
request);
else if (axutil_strcmp (auth_type, AXIS2_HTTP_AUTH_TYPE_DIGEST) == 0)
status = axis2_http_sender_configure_http_digest_auth (sender, env,
+ msg_ctx,
+ request);
+ else
+ AXIS2_LOG_ERROR (env->log, AXIS2_LOG_SI, "Authtype %s is not"
+ "supported", auth_type);
+ }
+ else
+ {
+ AXIS2_ERROR_SET (env->error, AXIS2_ERROR_HTTP_CLIENT_TRANSPORT_ERROR,
+ AXIS2_FAILURE);
+ }
+
+ return status;
+}
+
+static axis2_status_t
+axis2_http_sender_configure_proxy_auth (axis2_http_sender_t * sender,
+ const axutil_env_t * env,
+ axis2_msg_ctx_t * msg_ctx,
+ axis2_http_simple_request_t * request)
+{
+ axis2_char_t *auth_type = NULL;
+ axis2_status_t status = AXIS2_FALSE;
+ axutil_property_t *proxy_auth_property = NULL;
+ axis2_char_t *proxy_auth_property_value = NULL;
+ axis2_bool_t force_proxy_auth = AXIS2_FALSE;
+ axutil_property_t *proxy_auth_type_property = NULL;
+ axis2_char_t *proxy_auth_type_property_value = NULL;
+
+ proxy_auth_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_FORCE_PROXY_AUTH);
+ if (proxy_auth_property)
+ proxy_auth_property_value = (axis2_char_t *) axutil_property_get_value (proxy_auth_property,
+ env);
+
+ if (proxy_auth_property_value && 0 == axutil_strcmp (proxy_auth_property_value, AXIS2_VALUE_TRUE))
+ {
+ force_proxy_auth = AXIS2_TRUE;
+ }
+
+ if (force_proxy_auth)
+ {
+ proxy_auth_type_property = (axutil_property_t *) axis2_msg_ctx_get_property (msg_ctx, env,
+ AXIS2_PROXY_AUTH_TYPE);
+ if (proxy_auth_type_property)
+ proxy_auth_type_property_value = (axis2_char_t *) axutil_property_get_value (proxy_auth_type_property,
+ env);
+
+ if (proxy_auth_type_property_value)
+ {
+ auth_type = proxy_auth_type_property_value;
+ }
+ }
+ else
+ {
+ axis2_http_header_t *auth_header = NULL;
+ axis2_http_simple_response_t *response = NULL;
+ axis2_char_t *auth_type_end = NULL;
+
+ response = axis2_http_client_get_response (sender->client, env);
+
+ if (response)
+ auth_header = axis2_http_simple_response_get_first_header (response, env,
+ AXIS2_HTTP_HEADER_PROXY_AUTHENTICATE);
+
+ if (auth_header)
+ auth_type = axis2_http_header_get_value (auth_header, env);
+
+ if (auth_type)
+ {
+ auth_type_end = axutil_strchr (auth_type, ' ');
+ *auth_type_end = '\0';
+ auth_type_end++;
+ /*Read the realm and the rest stuff now from auth_type_end */
+ }
+ }
+ if (auth_type)
+ {
+ if (axutil_strcmp (auth_type, AXIS2_PROXY_AUTH_TYPE_BASIC) == 0)
+ status = axis2_http_sender_configure_proxy_basic_auth (sender, env,
+ msg_ctx,
+ request);
+ else if (axutil_strcmp (auth_type, AXIS2_PROXY_AUTH_TYPE_DIGEST) == 0)
+ status = axis2_http_sender_configure_proxy_digest_auth (sender, env,
msg_ctx,
request);
else
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org