/**
         * auto generated function definition signature
         * for "applySecurity|http://service.config.security.carbon.wso2.org" operation.
         * @param env environment ( mandatory)* @param MessageContext the outmessage context
         * @param _applySecurity of the adb_applySecurity_t*
         *
         * @return 
         */
        axis2_status_t  axis2_skel_SecurityAdminService_applySecurity(const axutil_env_t *env , axis2_msg_ctx_t *msg_ctx,
                                              adb_applySecurity_t* _applySecurity,
                                          axis2_skel_SecurityAdminService_applySecurity_fault *fault )
        {
			axis2_char_t* service_name = NULL;
			axis2_char_t* scenario_id = NULL;
			axis2_conf_ctx_t* conf_ctx = NULL;
			axis2_conf_t* conf = NULL;
			axis2_svc_t* svc = NULL;
			axis2_char_t* repo_path = NULL;
			axis2_char_t* policy_file_name = NULL;
			neethi_policy_t* neethi_policy = NULL;
			axis2_desc_t* desc = NULL;
			axis2_policy_include_t* policy_include = NULL;
			axutil_qname_t* module_qname = NULL;
			axis2_module_desc_t* module_desc = NULL;

			/* Get parameters */
			service_name = adb_applySecurity_get_serviceName(_applySecurity, env);
			scenario_id = adb_applySecurity_get_policyId(_applySecurity, env);

			/* Load neethi policy */
			conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
			repo_path = axis2_conf_ctx_get_root_dir(conf_ctx, env);
			policy_file_name = axutil_strcat(env, repo_path, AXIS2_PATH_SEP_STR, "services",
				AXIS2_PATH_SEP_STR, "SecurityAdminService", AXIS2_PATH_SEP_STR, "policies",
				AXIS2_PATH_SEP_STR, scenario_id, "-policy.xml", NULL);

			neethi_policy = neethi_util_create_policy_from_file(env, policy_file_name);
			AXIS2_FREE(env->allocator, policy_file_name);
			if (!neethi_policy) return AXIS2_FAILURE;
			
			/* Get service instance*/
			conf = axis2_conf_ctx_get_conf(conf_ctx, env);
			svc = axis2_conf_get_svc(conf, env, service_name);
			if (!svc) return AXIS2_FAILURE;

			desc = axis2_svc_get_base(svc, env);
			if (!desc) return AXIS2_FAILURE;

			policy_include = axis2_desc_get_policy_include(desc, env);
			if (!policy_include) return AXIS2_FAILURE;

			/* Attach policy*/
			axis2_policy_include_add_policy_element(policy_include, env, 
				AXIS2_SERVICE_POLICY, neethi_policy);

			/* Enagage modules*/
			module_qname = axutil_qname_create(env, "rampart", NULL, NULL);
			module_desc = axis2_conf_get_module(conf, env, module_qname);
			axutil_qname_free(module_qname, env);

			axis2_svc_disengage_module(svc, env, module_desc, conf);
			axis2_svc_engage_module(svc, env, module_desc, conf);

			return AXIS2_SUCCESS;
        }
Example #2
0
AXIS2_EXTERN void AXIS2_CALL
savan_default_publisher_publish(
    savan_publisher_t *publishermod,
    const axutil_env_t *env,
    void *msg_ctx,
    savan_subs_mgr_t *subs_mgr)
{
    savan_default_publisher_t *publishermodimpl = NULL;
    axutil_array_list_t *subs_store = NULL;
    int i = 0, size = 0;
    savan_filter_mod_t *filtermod = NULL;
    const axis2_char_t *path = NULL;
    axiom_node_t *payload = NULL;
    axiom_soap_envelope_t *envelope = NULL;
    axiom_soap_body_t *body = NULL;
    axiom_node_t *body_node = NULL;
    const axis2_char_t *filter = NULL;
    axis2_conf_ctx_t *conf_ctx = NULL;
    axutil_property_t *topic_property = NULL;

    publishermodimpl = SAVAN_INTF_TO_IMPL(publishermod);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Entry:savan_default_publisher_publish");

    topic_property = axis2_msg_ctx_get_property(msg_ctx, env, ELEM_NAME_TOPIC);
    if(topic_property)
    {
        filter = axutil_property_get_value(topic_property, env);
    }
    axutil_allocator_switch_to_global_pool(env->allocator);
    if(subs_mgr)
    {
        subs_store = savan_subs_mgr_retrieve_all_subscribers(subs_mgr, env, filter);
    }

    if (!subs_store)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "[savan] Subscriber store is NULL"); 
    }

    conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
    path = axis2_conf_ctx_get_root_dir(conf_ctx, env);
    if(!path)
    {
        path = AXIS2_GETENV("AXIS2C_HOME");
    }

    envelope =  axis2_msg_ctx_get_soap_envelope((axis2_msg_ctx_t *) msg_ctx, env);
    if (!envelope)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the soap envelop");
    }
    
    body = axiom_soap_envelope_get_body(envelope, env);
    if (!body)
    {
        axutil_allocator_switch_to_local_pool(env->allocator);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[savan] Failed to extract the soap body"); 
    }
    
    body_node = axiom_soap_body_get_base_node(body, env);

    payload = axiom_node_get_first_child(body_node, env);
    size = axutil_array_list_size(subs_store, env);
    for(i = 0; i < size; i++)
    {
        axis2_svc_client_t *svc_client = NULL;
        savan_subscriber_t *sub = NULL;

        sub = (savan_subscriber_t *)axutil_array_list_get(subs_store, env, i);
        if (sub)
        {
            axis2_char_t *id = savan_subscriber_get_id(sub, env);
            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[savan] Publishing to:%s", id);

            svc_client = axis2_svc_client_create(env, path);
            filtermod = savan_util_get_filter_module(env, publishermodimpl->conf);
            /* Ideally publishing to each subscriber should happen within a thread for each 
             * subscriber. However until Axis2/C provide a good thread pool to handle
             * such tasks I use this sequential publishing to subscribers.
             */
            if(!savan_default_publisher_publish_to_subscriber(publishermod, env, svc_client, sub, 
                        filtermod, payload))
            {
                axis2_endpoint_ref_t *notifyto = savan_subscriber_get_notify_to(sub, env);
                const axis2_char_t *address = NULL;

                if(notifyto)
                {
                    address = axis2_endpoint_ref_get_address(notifyto, env);
                }

                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                        "Publishing to the Data Sink:%s proviced by subscriber:%s Failed. Check "\
                        "whether the Data Sink url is correct", address, id);
            }
            if(svc_client)
            {
                axis2_svc_client_free(svc_client, env);
            }
        }
    }

    axutil_allocator_switch_to_local_pool(env->allocator);

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[savan] Exit:savan_default_publisher_publish");
}
Example #3
0
AXIS2_EXTERN axutil_array_list_t* AXIS2_CALL
security_admin_load_scenarios(
		const axutil_env_t* env, 
		axis2_msg_ctx_t* msg_ctx)
{
	/* Read senarios from config file*/
	axis2_conf_ctx_t* conf_ctx = NULL;
	axis2_char_t* repo_path = NULL;
	axis2_char_t* scenario_config_file_path = NULL;
	axiom_xml_reader_t* xml_reader = NULL;
	axiom_document_t* document = NULL;
	axiom_stax_builder_t* stax_builder = NULL;
	axiom_node_t* scenario_config_root_node = NULL;
	axiom_element_t* scenario_config_root_element = NULL;
	axiom_children_iterator_t* children_ite = NULL;
	axutil_array_list_t* scenarios = NULL;
			
	/* Form absolute path to config file*/
	conf_ctx = axis2_msg_ctx_get_conf_ctx(msg_ctx, env);
	repo_path = axis2_conf_ctx_get_root_dir(conf_ctx, env);
	scenario_config_file_path = axutil_strcat(env, repo_path, AXIS2_PATH_SEP_STR, "services", 
		AXIS2_PATH_SEP_STR, "SecurityAdminService", AXIS2_PATH_SEP_STR, "scenario-config.xml", 
		NULL);

	xml_reader = axiom_xml_reader_create_for_file(env, scenario_config_file_path, NULL);
	AXIS2_FREE(env->allocator, scenario_config_file_path);
	if (!xml_reader) return NULL;

	stax_builder = axiom_stax_builder_create(env, xml_reader);
	if (!stax_builder) return NULL;

	document = axiom_stax_builder_get_document(stax_builder, env);
	if (!document) return NULL;

	/* Build XML document*/
	axiom_document_build_all(document, env);

	scenario_config_root_node = axiom_document_get_root_element(document, env);
	scenario_config_root_element = axiom_node_get_data_element(scenario_config_root_node, env);
	axiom_stax_builder_free_self(stax_builder, env);
			
	children_ite = axiom_element_get_children(scenario_config_root_element, env, 
		scenario_config_root_node);
	if (children_ite)
	{
		/* Get Scenario nodes and build hash*/
		while (axiom_children_iterator_has_next(children_ite, env))
		{
			axiom_node_t* node = NULL;

			node = axiom_children_iterator_next(children_ite, env);

			if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT)
			{
				axis2_char_t* localname = NULL;
				axiom_element_t* scenario_ele = NULL;
				axiom_children_iterator_t* ite = NULL;
	
				scenario_ele = axiom_node_get_data_element(node, env);

				localname = axiom_element_get_localname(scenario_ele, env);

				if (0 == axutil_strcmp(localname, "Scenario")) /* Scenario */
				{
					axis2_char_t* id = NULL;
					security_admin_scenario_data_t* data = NULL;

					/* Create scenarios hash*/
					if (!scenarios)
						scenarios = axutil_array_list_create(env, SEC_ADMIN_SCENARIO_COUNT);

					data = security_admin_scenario_data_create(env);

					/* Current scenario*/
					security_admin_scenario_data_set_current_scenario(data, AXIS2_TRUE);

					/* id*/
					id = axiom_element_get_attribute_value_by_name(scenario_ele, env, "id");
					security_admin_scenario_data_set_id(data, axutil_strdup(env, id));

					ite = axiom_element_get_children(scenario_ele, env, node);
					while (axiom_children_iterator_has_next(ite, env))
					{
						axiom_node_t* node = NULL;
						node = axiom_children_iterator_next(ite, env);

						if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT)
						{
							axiom_element_t* node_ele = NULL;
							axis2_char_t* localname = NULL;
							axis2_char_t* text = NULL;

							node_ele = axiom_node_get_data_element(node, env);

							localname = axiom_element_get_localname(node_ele, env);
							text = axiom_element_get_text(node_ele, env, node);
									
							if (0 == axutil_strcmp(localname, "Summary")) /* Summary */
							{
								security_admin_scenario_data_set_summary(data, 
									axutil_strdup(env, text));
							}
							else if (0 == axutil_strcmp(localname, "Description")) /* Description */
							{
								security_admin_scenario_data_set_description(data, 
									axutil_strdup(env, text));
							}
							else if (0 == axutil_strcmp(localname, "Category")) /* Category */
							{
								security_admin_scenario_data_set_category(data, 
									axutil_strdup(env, text));
							}
							/*else if (0 == axutil_strcmp(localname, "WsuId")*/ /* WsuId */
							/*{
							}*/
							else if (0 == axutil_strcmp(localname, "Type")) /* Type */
							{
								security_admin_scenario_data_set_type(data, 
									axutil_strdup(env, text));
							}
							else if (0 == axutil_strcmp(localname, "Modules")) /* Modules */
							{
										
							}
						}
					}

					/* Add scenario data into the hash map*/
					axutil_array_list_add(scenarios, env, data);
				}
			}
		}
	}

	return scenarios;
}