From 0425aadc78680e53000fd0108b540d6eca048516 Mon Sep 17 00:00:00 2001 From: gmcdonald Date: Sat, 13 Feb 2010 01:32:03 +0000 Subject: Moving axis svn, part of TLP move INFRA-2441 git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68 --- neethi/src/Makefile.am | 53 + neethi/src/all.c | 183 +++ neethi/src/assertion.c | 424 ++++++ neethi/src/assertion_builder.c | 513 ++++++++ neethi/src/engine.c | 1390 ++++++++++++++++++++ neethi/src/exactlyone.c | 188 +++ neethi/src/mtom_assertion_checker.c | 75 ++ neethi/src/operator.c | 216 +++ neethi/src/policy.c | 446 +++++++ neethi/src/reference.c | 104 ++ neethi/src/registry.c | 131 ++ neethi/src/rmpolicy/Makefile.am | 13 + neethi/src/rmpolicy/rm_assertion.c | 511 +++++++ neethi/src/rmpolicy/rm_assertion_builder.c | 562 ++++++++ neethi/src/samples/test1.xml | 4 + neethi/src/samples/test10.xml | 1 + neethi/src/samples/test11.xml | 1 + neethi/src/samples/test12.xml | 1 + neethi/src/samples/test13.xml | 1 + neethi/src/samples/test14.xml | 1 + neethi/src/samples/test15.xml | 1 + neethi/src/samples/test16.xml | 1 + neethi/src/samples/test17.xml | 1 + neethi/src/samples/test18.xml | 1 + neethi/src/samples/test19.xml | 1 + neethi/src/samples/test2.xml | 1 + neethi/src/samples/test20.xml | 1 + neethi/src/samples/test21.xml | 10 + neethi/src/samples/test22.xml | 1 + neethi/src/samples/test23.xml | 1 + neethi/src/samples/test24.xml | 1 + neethi/src/samples/test25.xml | 7 + neethi/src/samples/test3.xml | 20 + neethi/src/samples/test4.xml | 1 + neethi/src/samples/test5.xml | 1 + neethi/src/samples/test6.xml | 1 + neethi/src/samples/test7.xml | 1 + neethi/src/samples/test8.xml | 4 + neethi/src/samples/test9.xml | 1 + neethi/src/secpolicy/Makefile.am | 1 + neethi/src/secpolicy/builder/Makefile.am | 25 + .../src/secpolicy/builder/algorithmsuite_builder.c | 82 ++ .../secpolicy/builder/asymmetric_binding_builder.c | 234 ++++ .../secpolicy/builder/bootstrap_policy_builder.c | 61 + .../secpolicy/builder/encryption_token_builder.c | 175 +++ neethi/src/secpolicy/builder/https_token_builder.c | 56 + .../secpolicy/builder/initiator_token_builder.c | 138 ++ .../src/secpolicy/builder/issued_token_builder.c | 164 +++ neethi/src/secpolicy/builder/layout_builder.c | 74 ++ .../secpolicy/builder/protection_token_builder.c | 175 +++ .../src/secpolicy/builder/rampart_config_builder.c | 213 +++ .../secpolicy/builder/recipient_token_builder.c | 139 ++ neethi/src/secpolicy/builder/saml_token_builder.c | 155 +++ neethi/src/secpolicy/builder/secpolicy_builder.c | 241 ++++ .../builder/security_context_token_builder.c | 231 ++++ .../secpolicy/builder/signature_token_builder.c | 175 +++ .../builder/signed_encrypted_parts_builder.c | 209 +++ .../secpolicy/builder/supporting_tokens_builder.c | 203 +++ .../secpolicy/builder/symmetric_binding_builder.c | 245 ++++ neethi/src/secpolicy/builder/token_identifier.c | 78 ++ .../secpolicy/builder/transport_binding_builder.c | 196 +++ .../secpolicy/builder/transport_token_builder.c | 138 ++ neethi/src/secpolicy/builder/trust10_builder.c | 139 ++ .../src/secpolicy/builder/username_token_builder.c | 150 +++ neethi/src/secpolicy/builder/wss10_builder.c | 135 ++ neethi/src/secpolicy/builder/wss11_builder.c | 147 +++ neethi/src/secpolicy/builder/x509_token_builder.c | 168 +++ neethi/src/secpolicy/model/Makefile.am | 21 + neethi/src/secpolicy/model/algorithmsuite.c | 627 +++++++++ neethi/src/secpolicy/model/asymmetric_binding.c | 160 +++ neethi/src/secpolicy/model/binding_commons.c | 245 ++++ neethi/src/secpolicy/model/element.c | 112 ++ neethi/src/secpolicy/model/header.c | 123 ++ neethi/src/secpolicy/model/https_token.c | 153 +++ neethi/src/secpolicy/model/issued_token.c | 211 +++ neethi/src/secpolicy/model/layout.c | 99 ++ neethi/src/secpolicy/model/property.c | 265 ++++ neethi/src/secpolicy/model/rampart_config.c | 446 +++++++ neethi/src/secpolicy/model/saml_token.c | 160 +++ neethi/src/secpolicy/model/secpolicy.c | 493 +++++++ .../src/secpolicy/model/security_context_token.c | 239 ++++ .../secpolicy/model/signed_encrypted_elements.c | 180 +++ .../src/secpolicy/model/signed_encrypted_items.c | 136 ++ .../src/secpolicy/model/signed_encrypted_parts.c | 176 +++ neethi/src/secpolicy/model/supporting_tokens.c | 300 +++++ .../model/symmetric_asymmetric_binding_commons.c | 192 +++ neethi/src/secpolicy/model/symmetric_binding.c | 216 +++ neethi/src/secpolicy/model/token.c | 190 +++ neethi/src/secpolicy/model/transport_binding.c | 137 ++ neethi/src/secpolicy/model/trust10.c | 201 +++ neethi/src/secpolicy/model/ut.c | 214 +++ neethi/src/secpolicy/model/wss10.c | 178 +++ neethi/src/secpolicy/model/wss11.c | 256 ++++ neethi/src/secpolicy/model/x509_token.c | 231 ++++ neethi/src/util.c | 95 ++ 95 files changed, 15077 insertions(+) create mode 100644 neethi/src/Makefile.am create mode 100644 neethi/src/all.c create mode 100644 neethi/src/assertion.c create mode 100644 neethi/src/assertion_builder.c create mode 100644 neethi/src/engine.c create mode 100644 neethi/src/exactlyone.c create mode 100644 neethi/src/mtom_assertion_checker.c create mode 100644 neethi/src/operator.c create mode 100644 neethi/src/policy.c create mode 100644 neethi/src/reference.c create mode 100644 neethi/src/registry.c create mode 100644 neethi/src/rmpolicy/Makefile.am create mode 100644 neethi/src/rmpolicy/rm_assertion.c create mode 100644 neethi/src/rmpolicy/rm_assertion_builder.c create mode 100644 neethi/src/samples/test1.xml create mode 100644 neethi/src/samples/test10.xml create mode 100644 neethi/src/samples/test11.xml create mode 100644 neethi/src/samples/test12.xml create mode 100644 neethi/src/samples/test13.xml create mode 100644 neethi/src/samples/test14.xml create mode 100644 neethi/src/samples/test15.xml create mode 100644 neethi/src/samples/test16.xml create mode 100644 neethi/src/samples/test17.xml create mode 100644 neethi/src/samples/test18.xml create mode 100644 neethi/src/samples/test19.xml create mode 100644 neethi/src/samples/test2.xml create mode 100644 neethi/src/samples/test20.xml create mode 100644 neethi/src/samples/test21.xml create mode 100644 neethi/src/samples/test22.xml create mode 100644 neethi/src/samples/test23.xml create mode 100644 neethi/src/samples/test24.xml create mode 100644 neethi/src/samples/test25.xml create mode 100644 neethi/src/samples/test3.xml create mode 100644 neethi/src/samples/test4.xml create mode 100644 neethi/src/samples/test5.xml create mode 100644 neethi/src/samples/test6.xml create mode 100644 neethi/src/samples/test7.xml create mode 100644 neethi/src/samples/test8.xml create mode 100644 neethi/src/samples/test9.xml create mode 100644 neethi/src/secpolicy/Makefile.am create mode 100644 neethi/src/secpolicy/builder/Makefile.am create mode 100644 neethi/src/secpolicy/builder/algorithmsuite_builder.c create mode 100644 neethi/src/secpolicy/builder/asymmetric_binding_builder.c create mode 100644 neethi/src/secpolicy/builder/bootstrap_policy_builder.c create mode 100644 neethi/src/secpolicy/builder/encryption_token_builder.c create mode 100644 neethi/src/secpolicy/builder/https_token_builder.c create mode 100644 neethi/src/secpolicy/builder/initiator_token_builder.c create mode 100644 neethi/src/secpolicy/builder/issued_token_builder.c create mode 100644 neethi/src/secpolicy/builder/layout_builder.c create mode 100644 neethi/src/secpolicy/builder/protection_token_builder.c create mode 100644 neethi/src/secpolicy/builder/rampart_config_builder.c create mode 100644 neethi/src/secpolicy/builder/recipient_token_builder.c create mode 100644 neethi/src/secpolicy/builder/saml_token_builder.c create mode 100644 neethi/src/secpolicy/builder/secpolicy_builder.c create mode 100644 neethi/src/secpolicy/builder/security_context_token_builder.c create mode 100644 neethi/src/secpolicy/builder/signature_token_builder.c create mode 100644 neethi/src/secpolicy/builder/signed_encrypted_parts_builder.c create mode 100644 neethi/src/secpolicy/builder/supporting_tokens_builder.c create mode 100644 neethi/src/secpolicy/builder/symmetric_binding_builder.c create mode 100644 neethi/src/secpolicy/builder/token_identifier.c create mode 100644 neethi/src/secpolicy/builder/transport_binding_builder.c create mode 100644 neethi/src/secpolicy/builder/transport_token_builder.c create mode 100644 neethi/src/secpolicy/builder/trust10_builder.c create mode 100644 neethi/src/secpolicy/builder/username_token_builder.c create mode 100644 neethi/src/secpolicy/builder/wss10_builder.c create mode 100644 neethi/src/secpolicy/builder/wss11_builder.c create mode 100644 neethi/src/secpolicy/builder/x509_token_builder.c create mode 100644 neethi/src/secpolicy/model/Makefile.am create mode 100644 neethi/src/secpolicy/model/algorithmsuite.c create mode 100644 neethi/src/secpolicy/model/asymmetric_binding.c create mode 100644 neethi/src/secpolicy/model/binding_commons.c create mode 100644 neethi/src/secpolicy/model/element.c create mode 100644 neethi/src/secpolicy/model/header.c create mode 100644 neethi/src/secpolicy/model/https_token.c create mode 100644 neethi/src/secpolicy/model/issued_token.c create mode 100644 neethi/src/secpolicy/model/layout.c create mode 100644 neethi/src/secpolicy/model/property.c create mode 100644 neethi/src/secpolicy/model/rampart_config.c create mode 100644 neethi/src/secpolicy/model/saml_token.c create mode 100644 neethi/src/secpolicy/model/secpolicy.c create mode 100644 neethi/src/secpolicy/model/security_context_token.c create mode 100644 neethi/src/secpolicy/model/signed_encrypted_elements.c create mode 100644 neethi/src/secpolicy/model/signed_encrypted_items.c create mode 100644 neethi/src/secpolicy/model/signed_encrypted_parts.c create mode 100644 neethi/src/secpolicy/model/supporting_tokens.c create mode 100644 neethi/src/secpolicy/model/symmetric_asymmetric_binding_commons.c create mode 100644 neethi/src/secpolicy/model/symmetric_binding.c create mode 100644 neethi/src/secpolicy/model/token.c create mode 100644 neethi/src/secpolicy/model/transport_binding.c create mode 100644 neethi/src/secpolicy/model/trust10.c create mode 100644 neethi/src/secpolicy/model/ut.c create mode 100644 neethi/src/secpolicy/model/wss10.c create mode 100644 neethi/src/secpolicy/model/wss11.c create mode 100644 neethi/src/secpolicy/model/x509_token.c create mode 100644 neethi/src/util.c (limited to 'neethi/src') diff --git a/neethi/src/Makefile.am b/neethi/src/Makefile.am new file mode 100644 index 0000000..12bff83 --- /dev/null +++ b/neethi/src/Makefile.am @@ -0,0 +1,53 @@ +SUBDIRS = secpolicy rmpolicy +lib_LTLIBRARIES=libneethi.la + +libneethi_la_SOURCES= all.c \ + assertion.c \ + engine.c \ + exactlyone.c \ + operator.c \ + policy.c \ + reference.c \ + registry.c \ + assertion_builder.c \ + mtom_assertion_checker.c \ + util.c + +libneethi_la_LIBADD = ../../axiom/src/om/libaxis2_axiom.la \ + ../../util/src/libaxutil.la \ + secpolicy/builder/librp_builder.la \ + secpolicy/model/librp_model.la \ + rmpolicy/librm_policy.la + +#libneethi_LIBADD=$(top_builddir)/src/core/description/libaxis2_description.la \ +# $(top_builddir)/src/core/receivers/libaxis2_receivers.la \ +# $(top_builddir)/src/core/deployment/libaxis2_deployment.la \ +# $(top_builddir)/src/core/context/libaxis2_context.la \ +# $(top_builddir)/src/core/addr/libaxis2_addr.la \ +# $(top_builddir)/src/core/clientapi/libaxis2_clientapi.la \ +# $(top_builddir)/src/core/phaseresolver/libaxis2_phaseresolver.la \ +# $(top_builddir)/src/core/util/libaxis2_core_utils.la \ +# $(top_builddir)/src/core/transport/http/common/libaxis2_http_common.la \ +# $(top_builddir)/src/core/transport/http/util/libaxis2_http_util.la \ +# $(top_builddir)/util/src/libaxutil.la \ +# $(top_builddir)/axiom/src/om/libaxis2_axiom.la + + +libneethi_la_LDFLAGS = -version-info $(VERSION_NO) + +INCLUDES = -I$(top_builddir)/include \ + -I ../../util/include \ + -I ../../axiom/include \ + -I ../../include + +# -I$(top_builddir)/src/wsdl \ +# -I$(top_builddir)/src/core/description \ +# -I$(top_builddir)/src/core/engine \ +# -I$(top_builddir)/src/core/phaseresolver \ +# -I$(top_builddir)/src/core/deployment \ +# -I$(top_builddir)/src/core/context \ +# -I$(top_builddir)/src/core/util \ +# -I$(top_builddir)/src/core/clientapi \ +# -I$(top_builddir)/util/include \ +# -I$(top_builddir)/axiom/include + diff --git a/neethi/src/all.c b/neethi/src/all.c new file mode 100644 index 0000000..780cd3f --- /dev/null +++ b/neethi/src/all.c @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct neethi_all_t +{ + axutil_array_list_t *policy_components; +}; + +AXIS2_EXTERN neethi_all_t *AXIS2_CALL +neethi_all_create( + const axutil_env_t *env) +{ + neethi_all_t *neethi_all = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_all = (neethi_all_t *)AXIS2_MALLOC(env->allocator, sizeof(neethi_all_t)); + + if(neethi_all == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_all->policy_components = NULL; + + neethi_all->policy_components = axutil_array_list_create(env, 0); + if(!(neethi_all->policy_components)) + { + neethi_all_free(neethi_all, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + return neethi_all; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_all_free( + neethi_all_t *neethi_all, + const axutil_env_t *env) +{ + if(neethi_all) + { + if(neethi_all->policy_components) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(neethi_all->policy_components, env); + + for(i = 0; i < size; i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get( + neethi_all->policy_components, env, i); + if(operator) + { + neethi_operator_free(operator, env); + operator = NULL; + } + operator = NULL; + } + axutil_array_list_free(neethi_all->policy_components, env); + neethi_all->policy_components = NULL; + } + AXIS2_FREE(env->allocator, neethi_all); + neethi_all = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +neethi_all_get_policy_components( + neethi_all_t *neethi_all, + const axutil_env_t *env) +{ + return neethi_all->policy_components; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_all_add_policy_components( + neethi_all_t *all, + axutil_array_list_t *arraylist, + const axutil_env_t *env) +{ + + int size = axutil_array_list_size(arraylist, env); + int i = 0; + + if(axutil_array_list_ensure_capacity(all->policy_components, env, size + 1) != AXIS2_SUCCESS) + return AXIS2_FAILURE; + + for(i = 0; i < size; i++) + { + void *value = NULL; + value = axutil_array_list_get(arraylist, env, i); + neethi_operator_increment_ref((neethi_operator_t *)value, env); + axutil_array_list_add(all->policy_components, env, value); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_all_add_operator( + neethi_all_t *neethi_all, + const axutil_env_t *env, + neethi_operator_t *operator) +{ + neethi_operator_increment_ref(operator, env); + axutil_array_list_add(neethi_all->policy_components, env, operator); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_all_is_empty( + neethi_all_t *all, + const axutil_env_t *env) +{ + return axutil_array_list_is_empty(all->policy_components, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_all_serialize( + neethi_all_t *neethi_all, + axiom_node_t *parent, + const axutil_env_t *env) +{ + axiom_node_t *all_node = NULL; + axiom_element_t *all_ele = NULL; + axiom_namespace_t *policy_ns = NULL; + axutil_array_list_t *components = NULL; + + policy_ns = axiom_namespace_create(env, NEETHI_NAMESPACE, NEETHI_PREFIX); + all_ele = axiom_element_create(env, parent, NEETHI_ALL, policy_ns, &all_node); + if(!all_node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Neethi 'all' node creation failed. Cannot serialize 'all' assertion"); + return AXIS2_FAILURE; + } + + components = neethi_all_get_policy_components(neethi_all, env); + if(components) + { + axis2_status_t status = AXIS2_FAILURE; + int i = 0; + for(i = 0; i < axutil_array_list_size(components, env); i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get(components, env, i); + if(operator) + { + status = neethi_operator_serialize(operator, env, all_node); + if(status != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Neethi operator serialization failed. Cannot serialize 'all' assertion"); + return AXIS2_FAILURE; + } + } + } + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/assertion.c b/neethi/src/assertion.c new file mode 100644 index 0000000..29c70be --- /dev/null +++ b/neethi/src/assertion.c @@ -0,0 +1,424 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct neethi_assertion_t +{ + void *value; + neethi_assertion_type_t type; + axutil_array_list_t *policy_components; + axiom_element_t *element; + axiom_node_t *node; + axis2_bool_t is_optional; + AXIS2_FREE_VOID_ARG free_func; +}; + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +neethi_assertion_create( + const axutil_env_t *env) +{ + neethi_assertion_t *neethi_assertion = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_assertion = (neethi_assertion_t *)AXIS2_MALLOC(env->allocator, + sizeof(neethi_assertion_t)); + + if(neethi_assertion == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_assertion->policy_components = NULL; + + neethi_assertion->policy_components = axutil_array_list_create(env, 0); + if(!(neethi_assertion->policy_components)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_assertion->value = NULL; + neethi_assertion->type = ASSERTION_TYPE_UNKNOWN; + neethi_assertion->element = NULL; + neethi_assertion->is_optional = AXIS2_FALSE; + neethi_assertion->node = NULL; + neethi_assertion->free_func = 0; + + return neethi_assertion; +} + +neethi_assertion_t *AXIS2_CALL +neethi_assertion_create_with_args( + const axutil_env_t *env, + AXIS2_FREE_VOID_ARG free_func, + void *value, + neethi_assertion_type_t type) +{ + neethi_assertion_t *neethi_assertion = NULL; + neethi_assertion = (neethi_assertion_t *)AXIS2_MALLOC(env->allocator, + sizeof(neethi_assertion_t)); + + if(!neethi_assertion) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Neethi assertion creation failed. Out of memory"); + return NULL; + } + + neethi_assertion->policy_components = NULL; + neethi_assertion->policy_components = axutil_array_list_create(env, 0); + if(!(neethi_assertion->policy_components)) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Neethi assertion policy components creation failed."); + return NULL; + } + + /* This ref count is for asertions which are represented from a struct. + * These assertion structs are more probably referenced from some other + * struct. So we need to increment the ref count in order to prevent + * unnecessary memory freeing */ + + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_increment_ref((rp_x509_token_t *)value, env); + } + else if(type == ASSERTION_TYPE_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_increment_ref((rp_security_context_token_t *)value, env); + } + else if(type == ASSERTION_TYPE_INITIATOR_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_RECIPIENT_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_PROTECTION_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_ENCRYPTION_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_TRANSPORT_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_SIGNATURE_TOKEN) + { + rp_property_increment_ref((rp_property_t *)value, env); + } + else if(type == ASSERTION_TYPE_LAYOUT) + { + rp_layout_increment_ref((rp_layout_t *)value, env); + } + else if(type == ASSERTION_TYPE_ALGORITHM_SUITE) + { + rp_algorithmsuite_increment_ref((rp_algorithmsuite_t *)value, env); + } + else if(type == ASSERTION_TYPE_WSS10) + { + rp_wss10_increment_ref((rp_wss10_t *)value, env); + } + else if(type == ASSERTION_TYPE_WSS11) + { + rp_wss11_increment_ref((rp_wss11_t *)value, env); + } + else if(type == ASSERTION_TYPE_TRUST10) + { + rp_trust10_increment_ref((rp_trust10_t *)value, env); + } + else if(type == ASSERTION_TYPE_SUPPORTING_TOKENS) + { + rp_supporting_tokens_increment_ref((rp_supporting_tokens_t *)value, env); + } + else if(type == ASSERTION_TYPE_USERNAME_TOKEN) + { + rp_username_token_increment_ref((rp_username_token_t *)value, env); + } + else if(type == ASSERTION_TYPE_ASSYMMETRIC_BINDING) + { + rp_asymmetric_binding_increment_ref((rp_asymmetric_binding_t *)value, env); + } + else if(type == ASSERTION_TYPE_SYMMETRIC_BINDING) + { + rp_symmetric_binding_increment_ref((rp_symmetric_binding_t *)value, env); + } + else if(type == ASSERTION_TYPE_TRANSPORT_BINDING) + { + rp_transport_binding_increment_ref((rp_transport_binding_t *)value, env); + } + else if(type == ASSERTION_TYPE_SIGNED_ENCRYPTED_PARTS) + { + rp_signed_encrypted_parts_increment_ref((rp_signed_encrypted_parts_t *)value, env); + } + else if(type == ASSERTION_TYPE_RAMPART_CONFIG) + { + rp_rampart_config_increment_ref((rp_rampart_config_t *)value, env); + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + rp_issued_token_increment_ref((rp_issued_token_t *)value, env); + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + rp_saml_token_increment_ref((rp_saml_token_t *)value, env); + } + + neethi_assertion->value = value; + neethi_assertion->type = type; + neethi_assertion->element = NULL; + neethi_assertion->is_optional = AXIS2_FALSE; + neethi_assertion->node = NULL; + neethi_assertion->free_func = free_func; + + return neethi_assertion; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_assertion_free( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + if(neethi_assertion) + { + if(neethi_assertion->policy_components) + { + int i = 0; + for(i = 0; i < axutil_array_list_size(neethi_assertion->policy_components, env); i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get( + neethi_assertion->policy_components, env, i); + if(operator) + neethi_operator_free(operator, env); + + operator = NULL; + } + axutil_array_list_free(neethi_assertion->policy_components, env); + neethi_assertion->policy_components = NULL; + } + if(neethi_assertion->value) + { + if(neethi_assertion->free_func) + { + neethi_assertion->free_func(neethi_assertion->value, env); + } + } + AXIS2_FREE(env->allocator, neethi_assertion); + neethi_assertion = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN neethi_assertion_type_t AXIS2_CALL +neethi_assertion_get_type( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return neethi_assertion->type; +} + +AXIS2_EXTERN void *AXIS2_CALL +neethi_assertion_get_value( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return neethi_assertion->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_set_value( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env, + void *value, + neethi_assertion_type_t type) +{ + neethi_assertion->type = type; + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_increment_ref((rp_x509_token_t *)value, env); + } + neethi_assertion->value = (void *)value; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_element_t *AXIS2_CALL +neethi_assertion_get_element( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return neethi_assertion->element; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_set_element( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env, + axiom_element_t *element) +{ + neethi_assertion->element = element; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +neethi_assertion_get_node( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return neethi_assertion->node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_set_node( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env, + axiom_node_t * node) +{ + if(neethi_assertion->node) + { + axiom_node_free_tree(neethi_assertion->node, env); + neethi_assertion->node = NULL; + } + + if(node) + { + neethi_assertion->node = axiom_util_clone_node(env, node); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_assertion_get_is_optional( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return neethi_assertion->is_optional; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_set_is_optional( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env, + axis2_bool_t is_optional) +{ + neethi_assertion->is_optional = is_optional; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +neethi_assertion_get_policy_components( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return neethi_assertion->policy_components; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_add_policy_components( + neethi_assertion_t *neethi_assertion, + axutil_array_list_t *arraylist, + const axutil_env_t *env) +{ + + int size = axutil_array_list_size(arraylist, env); + int i = 0; + + if(axutil_array_list_ensure_capacity(neethi_assertion->policy_components, env, size + 1) + != AXIS2_SUCCESS) + return AXIS2_FAILURE; + + for(i = 0; i < size; i++) + { + void *value = NULL; + value = axutil_array_list_get(arraylist, env, i); + neethi_operator_increment_ref((neethi_operator_t *)value, env); + axutil_array_list_add(neethi_assertion->policy_components, env, value); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_add_operator( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env, + neethi_operator_t *operator) +{ + neethi_operator_increment_ref(operator, env); + axutil_array_list_add(neethi_assertion->policy_components, env, operator); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_assertion_is_empty( + neethi_assertion_t *neethi_assertion, + const axutil_env_t *env) +{ + return axutil_array_list_is_empty(neethi_assertion->policy_components, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_assertion_serialize( + neethi_assertion_t *assertion, + axiom_node_t *parent, + const axutil_env_t *env) +{ + axiom_node_t *node = NULL; + if(assertion->node) + { + node = axiom_util_clone_node(env, assertion->node); + } + + if(!node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "assertion node creation failed. Cannot serialize assertion"); + return AXIS2_FAILURE; + } + + axiom_node_add_child(parent, env, node); + return AXIS2_SUCCESS; +} diff --git a/neethi/src/assertion_builder.c b/neethi/src/assertion_builder.c new file mode 100644 index 0000000..e6f4064 --- /dev/null +++ b/neethi/src/assertion_builder.c @@ -0,0 +1,513 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +neethi_assertion_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + axis2_char_t *localname = NULL; + axis2_char_t *ns = NULL; + axutil_qname_t *node_qname = NULL; + + localname = axiom_element_get_localname(element, env); + if(!localname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get localname from element."); + return NULL; + } + + node_qname = axiom_element_get_qname(element, env, node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get qname from element %s.", + localname); + return NULL; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get namespace from element %s.", + localname); + return NULL; + } + + if(!(axutil_strcmp(ns, RP_SP_NS_11) && axutil_strcmp(ns, RP_SP_NS_12))) + { + /* if namespace is WS-SecurityPolicy Namespace */ + if(!axutil_strcmp(localname, RP_TRANSPORT_BINDING)) + { + return rp_transport_binding_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_ASYMMETRIC_BINDING)) + { + return rp_asymmetric_binding_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SYMMETRIC_BINDING)) + { + return rp_symmetric_binding_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_TRANSPORT_TOKEN)) + { + return rp_transport_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_RECIPIENT_TOKEN)) + { + return rp_recipient_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_INITIATOR_TOKEN)) + { + return rp_initiator_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_PROTECTION_TOKEN)) + { + return rp_protection_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_ENCRYPTION_TOKEN)) + { + return rp_encryption_token_builder_build(env, node, element); + } + + else if(!axutil_strcmp(localname, RP_SIGNATURE_TOKEN)) + { + return rp_signature_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_X509_TOKEN)) + { + return rp_x509_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SECURITY_CONTEXT_TOKEN)) + { + return rp_security_context_token_builder_build(env, node, element, ns, AXIS2_FALSE); + } + else if(!axutil_strcmp(localname, RP_SECURE_CONVERSATION_TOKEN)) + { + return rp_security_context_token_builder_build(env, node, element, ns, AXIS2_TRUE); + } + else if(!axutil_strcmp(localname, RP_ENCRYPT_BEFORE_SIGNING)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_ENCRYPT_BEFORE_SIGNING); + return assertion; + } + else if(!axutil_strcmp(localname, RP_SIGN_BEFORE_ENCRYPTING)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_SIGN_BEFORE_ENCRYPTING); + return assertion; + } + else if(!axutil_strcmp(localname, RP_ENCRYPT_SIGNATURE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_ENCRYPT_SIGNATURE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_PROTECT_TOKENS)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_PROTECT_TOKENS); + return assertion; + } + else if(!axutil_strcmp(localname, RP_ONLY_SIGN_ENTIRE_HEADERS_AND_BODY)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_ONLY_SIGN_ENTIRE_HEADERS_AND_BODY); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_KEY_IDENTIFIRE_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_KEY_IDENTIFIRE_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_ISSUER_SERIAL_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_ISSUER_SERIAL_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_EMBEDDED_TOKEN_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_EMBEDDED_TOKEN_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_THUMBPRINT_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_THUMBPRINT_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_X509_V1_TOKEN_10)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_X509_V1_TOKEN_10); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_X509_V3_TOKEN_10)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_X509_V3_TOKEN_10); + return assertion; + } + else if(!axutil_strcmp(localname, RP_ALGORITHM_SUITE)) + { + return rp_algorithmsuite_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_LAYOUT)) + { + return rp_layout_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_USERNAME_TOKEN)) + { + return rp_username_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SIGNED_SUPPORTING_TOKENS)) + { + return rp_supporting_tokens_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SUPPORTING_TOKENS)) + { + return rp_supporting_tokens_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_ENDORSING_SUPPORTING_TOKENS)) + { + return rp_supporting_tokens_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SIGNED_ENDORSING_SUPPORTING_TOKENS)) + { + return rp_supporting_tokens_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_WSS10)) + { + return rp_wss10_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_WSS11)) + { + return rp_wss11_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_TRUST10)) + { + return rp_trust10_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_TRUST13)) + { + /* we can still use rp_trust10 structures */ + return rp_trust10_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_INCLUDE_TIMESTAMP)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_INCLUDE_TIMESTAMP); + return assertion; + } + else if(!axutil_strcmp(localname, RP_HTTPS_TOKEN)) + { + return rp_https_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_WSS_USERNAME_TOKEN_10)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_USERNAME_TOKEN_10); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_USERNAME_TOKEN_11)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_USERNAME_TOKEN_11); + return assertion; + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_KEY_IDENTIFIER)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_KEY_IDENTIFIER); + return assertion; + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_ISSUER_SERIAL)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_ISSUER_SERIAL); + return assertion; + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_EXTERNAL_URI)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_EXTERNAL_URI); + return assertion; + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_EMBEDDED_TOKEN)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_EMBEDDED_TOKEN); + return assertion; + } + else if(!axutil_strcmp(localname, RP_SIGNED_PARTS)) + { + return rp_signed_encrypted_parts_builder_build(env, node, element, AXIS2_TRUE); + } + else if(!axutil_strcmp(localname, RP_ENCRYPTED_PARTS)) + { + return rp_signed_encrypted_parts_builder_build(env, node, element, AXIS2_FALSE); + } + else if(!axutil_strcmp(localname, RP_BOOTSTRAP_POLICY)) + { + return rp_bootstrap_policy_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_THUMBPRINT)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_THUMBPRINT); + return assertion; + } + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_REF_ENCRYPTED_KEY)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_REF_ENCRYPTED_KEY); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_SIGNATURE_CONFIRMATION)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_SIGNATURE_CONFIRMATION); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_CLIENT_CHALLENGE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_CLIENT_CHALLENGE); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_SERVER_CHALLENGE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_SERVER_CHALLENGE); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_REQUIRE_CLIENT_ENTROPY)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_REQUIRE_CLIENT_ENTROPY); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_REQUIRE_SERVER_ENTROPHY)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_REQUIRE_SERVER_ENTROPHY); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_MUST_SUPPORT_ISSUED_TOKENS)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_MUST_SUPPORT_ISSUED_TOKENS); + return assertion; + } + + else if(!axutil_strcmp(localname, RP_REQUIRE_DERIVED_KEYS)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + if(!axutil_strcmp(ns, RP_SP_NS_11)) + { + /* derived key should be as defined in WS-SecConversation 1.0 */ + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC10); + } + else + { + /* derived key should be as defined in WS-SecConversation 1.3 */ + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC13); + } + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_EXTERNAL_URI_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_REQUIRE_EXTERNAL_URI); + return assertion; + } + else if(!axutil_strcmp(localname, RP_SC10_SECURITY_CONTEXT_TOKEN)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_SC10_SECURITY_CONTEXT_TOKEN); + return assertion; + } + else if(!axutil_strcmp(localname, RP_SC13_SECURITY_CONTEXT_TOKEN)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_SC13_SECURITY_CONTEXT_TOKEN); + return assertion; + } + else if(!axutil_strcmp(localname, RP_ISSUER)) + { + neethi_assertion_t *assertion = NULL; + axis2_char_t *issuer = NULL; + + issuer = axiom_element_get_text(element, env, node); + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, issuer, ASSERTION_TYPE_ISSUER); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_EXTERNAL_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_EXTERNAL_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_REQUIRE_INTERNAL_REFERENCE)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_REQUIRE_INTERNAL_REFERENCE); + return assertion; + } + else if(!axutil_strcmp(localname, RP_ISSUED_TOKEN)) + { + return rp_issued_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_SAML_TOKEN)) + { + return rp_saml_token_builder_build(env, node, element); + } + else if(!axutil_strcmp(localname, RP_WSS_SAML_V10_TOKEN_V10)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_SAML_V10_TOKEN_V10); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_SAML_V10_TOKEN_V11)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_SAML_V10_TOKEN_V11); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_SAML_V11_TOKEN_V10)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_SAML_V11_TOKEN_V10); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_SAML_V11_TOKEN_V11)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_SAML_V11_TOKEN_V11); + return assertion; + } + else if(!axutil_strcmp(localname, RP_WSS_SAML_V20_TOKEN_V11)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, ASSERTION_TYPE_WSS_SAML_V20_TOKEN_V11); + return assertion; + } + } + else if(!axutil_strcmp(ns, RP_RAMPART_NS)) + { + /* if namespace is Rampart Namespace */ + if(!axutil_strcmp(localname, RP_RAMPART_CONFIG)) + { + return rp_rampart_config_builder_build(env, node, element); + } + } + else if(!axutil_strcmp(ns, AXIS2_MTOM_POLICY_NS)) + { + if(!axutil_strcmp(localname, AXIS2_OPTIMIZED_MIME_SERIALIZATION)) + { + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, NULL, + ASSERTION_TYPE_OPTIMIZED_MIME_SERIALIZATION); + return assertion; + } + } + else if((!axutil_strcmp(ns, AXIS2_RM_POLICY_10_NS)) || (!axutil_strcmp(ns, + AXIS2_RM_POLICY_11_NS))) + { + if(!axutil_strcmp(localname, AXIS2_RM_RMASSERTION)) + { + return axis2_rm_assertion_builder_build(env, node, element); + } + } + + /* This assertion cannot be processed */ + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_UNKNOWN_ASSERTION, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Unknown Assertion %s with namespace %s", + localname, ns); + return NULL; +} diff --git a/neethi/src/engine.c b/neethi/src/engine.c new file mode 100644 index 0000000..b925cea --- /dev/null +++ b/neethi/src/engine.c @@ -0,0 +1,1390 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +/*Private functions*/ + +static neethi_all_t * +neethi_engine_get_operator_all( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element); + +static neethi_exactlyone_t * +neethi_engine_get_operator_exactlyone( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element); + +static neethi_reference_t * +neethi_engine_get_operator_reference( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element); + +static neethi_policy_t * +neethi_engine_get_operator_neethi_policy( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element); + +static axis2_status_t +neethi_engine_process_operation_element( + const axutil_env_t *env, + neethi_operator_t *neethi_operator, + axiom_node_t *node, + axiom_element_t *element); + +static axis2_status_t +neethi_engine_add_policy_component( + const axutil_env_t *env, + neethi_operator_t *container_operator, + neethi_operator_t *component); + +static axis2_bool_t +neethi_engine_operator_is_empty( + neethi_operator_t *operator, + const axutil_env_t *env); + +static neethi_exactlyone_t * +neethi_engine_compute_resultant_component( + axutil_array_list_t *normalized_inner_components, + neethi_operator_type_t type, + const axutil_env_t *env); + +static axutil_array_list_t * +neethi_engine_operator_get_components( + neethi_operator_t *operator, + const axutil_env_t *env); + +static neethi_exactlyone_t * +neethi_engine_normalize_operator( + neethi_operator_t *operator, + neethi_registry_t *registry, + axis2_bool_t deep, + const axutil_env_t *env); + +static neethi_exactlyone_t * +neethi_engine_get_cross_product( + neethi_exactlyone_t *exactlyone1, + neethi_exactlyone_t *exactlyone2, + const axutil_env_t *env); + +static void +neethi_engine_clear_element_attributes( + axutil_hash_t *attr_hash, + const axutil_env_t *env); + +/*Implementations*/ + +/*This is the function which is called from outside*/ + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_engine_get_policy( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + /* This function will be called recursively */ + + return neethi_engine_get_operator_neethi_policy(env, node, element); +} + +static neethi_all_t * +neethi_engine_get_operator_all( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + neethi_all_t *all = NULL; + neethi_operator_t *neethi_operator = NULL; + axis2_status_t status = AXIS2_SUCCESS; + all = neethi_all_create(env); + + if(!all) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator = neethi_operator_create(env); + if(!neethi_operator) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(neethi_operator, env, all, OPERATOR_TYPE_ALL); + + status = neethi_engine_process_operation_element(env, neethi_operator, node, element); + + neethi_operator_set_value_null(neethi_operator, env); + neethi_operator_free(neethi_operator, env); + neethi_operator = NULL; + + if(status != AXIS2_SUCCESS) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] All creation failed"); + neethi_all_free(all, env); + all = NULL; + return NULL; + } + return all; +} + +static neethi_exactlyone_t * +neethi_engine_get_operator_exactlyone( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + neethi_exactlyone_t *exactlyone = NULL; + neethi_operator_t *neethi_operator = NULL; + axis2_status_t status = AXIS2_SUCCESS; + + exactlyone = neethi_exactlyone_create(env); + + if(!exactlyone) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + + return NULL; + } + neethi_operator = neethi_operator_create(env); + if(!neethi_operator) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + + return NULL; + } + neethi_operator_set_value(neethi_operator, env, exactlyone, OPERATOR_TYPE_EXACTLYONE); + status = neethi_engine_process_operation_element(env, neethi_operator, node, element); + + neethi_operator_set_value_null(neethi_operator, env); + neethi_operator_free(neethi_operator, env); + neethi_operator = NULL; + + if(status != AXIS2_SUCCESS) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Exactlyone creation failed."); + neethi_exactlyone_free(exactlyone, env); + exactlyone = NULL; + return NULL; + } + + return exactlyone; +} + +neethi_reference_t * +neethi_engine_get_operator_reference( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + neethi_reference_t *reference = NULL; + axutil_qname_t *qname = NULL; + axis2_char_t *attribute_value = NULL; + + reference = neethi_reference_create(env); + + if(!reference) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + + return NULL; + } + qname = axutil_qname_create(env, NEETHI_URI, NULL, NULL); + + if(!qname) + { + return NULL; + } + + attribute_value = axiom_element_get_attribute_value(element, env, qname); + if(attribute_value) + { + neethi_reference_set_uri(reference, env, attribute_value); + } + return reference; +} + +/* This function will be called when we encounter a wsp:Policy + * element */ + +static neethi_policy_t * +neethi_engine_get_operator_neethi_policy( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + neethi_policy_t *neethi_policy = NULL; + neethi_operator_t *neethi_operator = NULL; + axis2_status_t status = AXIS2_SUCCESS; + + /* Creates a policy struct */ + + neethi_policy = neethi_policy_create(env); + + if(!neethi_policy) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + /* Then we wrap it in a neethi_operator */ + + neethi_operator = neethi_operator_create(env); + if(!neethi_operator) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(neethi_operator, env, neethi_policy, OPERATOR_TYPE_POLICY); + + /* This function will do all the processing and build the + * policy object model */ + + status = neethi_engine_process_operation_element(env, neethi_operator, node, element); + + /* To prevent freeing the policy object from the operator + * we set it to null. This object will be freed from a parent + * or from an outsider who creates a policy object */ + + neethi_operator_set_value_null(neethi_operator, env); + neethi_operator_free(neethi_operator, env); + neethi_operator = NULL; + + if(status != AXIS2_SUCCESS) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED, AXIS2_FAILURE); + + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Policy creation failed."); + neethi_policy_free(neethi_policy, env); + neethi_policy = NULL; + return NULL; + } + return neethi_policy; +} + +/* This function will construct the policy objecy model by + * filling the component array_list inside the passing + * policy operator */ + +static axis2_status_t +neethi_engine_process_operation_element( + const axutil_env_t *env, + neethi_operator_t *neethi_operator, + axiom_node_t *node, + axiom_element_t *element) +{ + + neethi_operator_type_t type; + axiom_element_t *child_element = NULL; + axiom_node_t *child_node = NULL; + axiom_children_iterator_t *children_iter = NULL; + void *value = NULL; + + type = neethi_operator_get_type(neethi_operator, env); + value = neethi_operator_get_value(neethi_operator, env); + + if(type == OPERATOR_TYPE_POLICY) + { + /* wsp:Policy element can have any number of attributes + * we will store them in a hash from the uri and localname */ + + axutil_hash_t *attributes = axiom_element_extract_attributes(element, env, node); + + if(attributes) + { + axutil_hash_index_t *hi = NULL; + + /* When creating the policy object we created the hash */ + + axutil_hash_t *ht = neethi_policy_get_attributes((neethi_policy_t *)value, env); + + if(!ht) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Policy hash map creation failed."); + return AXIS2_FAILURE; + } + + for(hi = axutil_hash_first(attributes, env); hi; hi = axutil_hash_next(env, hi)) + { + axis2_char_t *key = NULL; + void *val = NULL; + axutil_qname_t *qname = NULL; + axis2_char_t *attr_val = NULL; + axiom_namespace_t *ns = NULL; + axis2_char_t *ns_uri = NULL; + axiom_attribute_t *om_attr = NULL; + + axutil_hash_this(hi, NULL, NULL, &val); + if(val) + { + om_attr = (axiom_attribute_t *)val; + ns = axiom_attribute_get_namespace(om_attr, env); + if(ns) + { + ns_uri = axiom_namespace_get_uri(ns, env); + } + + qname = axutil_qname_create(env, axiom_attribute_get_localname(om_attr, env), + ns_uri, NULL); + if(qname) + { + key = axutil_qname_to_string(qname, env); + if(key) + { + attr_val = axiom_attribute_get_value(om_attr, env); + if(attr_val) + { + /* axutil_qname_free will free the returned key + * of the qname so will duplicate it when storing */ + + axutil_hash_set(ht, axutil_strdup(env, key), AXIS2_HASH_KEY_STRING, + axutil_strdup(env, attr_val)); + } + } + axutil_qname_free(qname, env); + } + } + } + /* axiom_element_extract_attributes method will always returns + * a cloned copy, so we need to free it after we have done with it */ + + neethi_engine_clear_element_attributes(attributes, env); + attributes = NULL; + } + } + + children_iter = axiom_element_get_children(element, env, node); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + /* Extract the element and check the namespace. If the namespace + * is in ws_policy then we call the relevent operator builder + * otherwise we will call the assertion_builder */ + + child_node = axiom_children_iterator_next(children_iter, env); + if(child_node) + { + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + axiom_namespace_t *namespace = NULL; + axis2_char_t *uri = NULL; + axis2_char_t *local_name = NULL; + neethi_operator_t *operator = NULL; + local_name = axiom_element_get_localname(child_element, env); + + namespace = axiom_element_get_namespace(child_element, env, child_node); + if(!namespace) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_ELEMENT_WITH_NO_NAMESPACE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Element with no namespace"); + return AXIS2_FAILURE; + } + uri = axiom_namespace_get_uri(namespace, env); + if(!uri) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_EMPTY_NAMESPACE_URI, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Invalid Empty namespace uri."); + return AXIS2_FAILURE; + } + if((axutil_strcmp(uri, NEETHI_NAMESPACE) == 0) || (axutil_strcmp(uri, + NEETHI_POLICY_15_NAMESPACE) == 0)) + { + /* Looking at the localname we will call the relevent + * operator function. After that the newly created + * object is wrapped in a neethi_operator and stored in + * the parent's component list */ + + if(axutil_strcmp(local_name, NEETHI_POLICY) == 0) + { + neethi_policy_t *neethi_policy = NULL; + neethi_policy = neethi_engine_get_operator_neethi_policy(env, + child_node, child_element); + if(neethi_policy) + { + operator = neethi_operator_create(env); + neethi_operator_set_value(operator, env, neethi_policy, + OPERATOR_TYPE_POLICY); + neethi_engine_add_policy_component(env, neethi_operator, + operator); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_POLICY_CREATION_FAILED_FROM_ELEMENT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Policy creation failed from element."); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(local_name, NEETHI_ALL) == 0) + { + neethi_all_t *all = NULL; + all + = neethi_engine_get_operator_all(env, child_node, child_element); + if(all) + { + operator = neethi_operator_create(env); + neethi_operator_set_value(operator, env, all, OPERATOR_TYPE_ALL); + neethi_engine_add_policy_component(env, neethi_operator, + operator); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_ALL_CREATION_FAILED_FROM_ELEMENT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] All creation failed from element."); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(local_name, NEETHI_EXACTLYONE) == 0) + { + neethi_exactlyone_t *exactlyone = NULL; + exactlyone = neethi_engine_get_operator_exactlyone(env, child_node, + child_element); + if(exactlyone) + { + operator = neethi_operator_create(env); + neethi_operator_set_value(operator, env, exactlyone, + OPERATOR_TYPE_EXACTLYONE); + neethi_engine_add_policy_component(env, neethi_operator, + operator); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_EXACTLYONE_CREATION_FAILED_FROM_ELEMENT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Exactlyone creation failed from element."); + return AXIS2_FAILURE; + } + } + else if(axutil_strcmp(local_name, NEETHI_REFERENCE) == 0) + { + neethi_reference_t *reference = NULL; + reference = neethi_engine_get_operator_reference(env, child_node, + child_element); + if(reference) + { + operator = neethi_operator_create(env); + neethi_operator_set_value(operator, env, reference, + OPERATOR_TYPE_REFERENCE); + neethi_engine_add_policy_component(env, neethi_operator, + operator); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_REFERENCE_CREATION_FAILED_FROM_ELEMENT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Reference cretion failed from element."); + return AXIS2_FAILURE; + } + } + } + + else + { + /* This is an assertion in a different domain. Assertion builder + * should be called and that will call the relevent assertion builder + * after looking at the localname and the namespace */ + + neethi_assertion_t *assertion = NULL; + assertion = neethi_assertion_builder_build(env, child_node, + child_element); + if(assertion) + { + operator = neethi_operator_create(env); + neethi_operator_set_value(operator, env, assertion, + OPERATOR_TYPE_ASSERTION); + neethi_engine_add_policy_component(env, neethi_operator, operator); + neethi_assertion_set_node(assertion, env, child_node); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_ASSERTION_CREATION_FAILED_FROM_ELEMENT, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Assertion creation failed from element."); + return AXIS2_FAILURE; + } + } + } + } + } + } + return AXIS2_SUCCESS; + } + else + return AXIS2_FAILURE; +} + +/* After looking at the operator_type this function will + * call the relevent neethi operator's add operator + * function */ + +static axis2_status_t +neethi_engine_add_policy_component( + const axutil_env_t *env, + neethi_operator_t *container_operator, + neethi_operator_t *component) +{ + + neethi_operator_type_t type; + void *value = NULL; + neethi_policy_t *neethi_policy = NULL; + neethi_exactlyone_t *exactlyone = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + + type = neethi_operator_get_type(container_operator, env); + value = neethi_operator_get_value(container_operator, env); + + if(value) + { + switch(type) + { + case OPERATOR_TYPE_POLICY: + neethi_policy = (neethi_policy_t *)value; + neethi_policy_add_operator(neethi_policy, env, component); + break; + + case OPERATOR_TYPE_ALL: + all = (neethi_all_t *)value; + neethi_all_add_operator(all, env, component); + break; + + case OPERATOR_TYPE_EXACTLYONE: + exactlyone = (neethi_exactlyone_t *)value; + neethi_exactlyone_add_operator(exactlyone, env, component); + break; + + case OPERATOR_TYPE_UNKNOWN: + return AXIS2_FAILURE; + break; + + case OPERATOR_TYPE_ASSERTION: + assertion = (neethi_assertion_t *)value; + neethi_assertion_add_operator(assertion, env, component); + break; + + case OPERATOR_TYPE_REFERENCE: + break; + } + return AXIS2_SUCCESS; + } + else + return AXIS2_FAILURE; +} + +/***************************************/ + +/*This function is only for testing* + *Remove it later*/ +void +check_neethi_policy( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + axutil_array_list_t *list = NULL; + neethi_operator_t *op = NULL; + neethi_operator_type_t type; + + list = neethi_policy_get_policy_components(neethi_policy, env); + + if(axutil_array_list_size(list, env) > 1) + { + return; + } + op = (neethi_operator_t *)axutil_array_list_get(list, env, 0); + type = neethi_operator_get_type(op, env); + if(type == OPERATOR_TYPE_EXACTLYONE) + { + void *value = neethi_operator_get_value(op, env); + if(value) + { + return; + } + } + else + { + return; + } +} + +/************************************************/ +/* + + Following function will normalize accorading to the + WS-Policy spec. Normalize policy is in the following + format. + + + + ( ( … )* )* + + + + */ + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_engine_get_normalize( + const axutil_env_t *env, + axis2_bool_t deep, + neethi_policy_t *neethi_policy) +{ + /* In the first call we pass the registry as null.*/ + + return neethi_engine_normalize(env, neethi_policy, NULL, deep); +} + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_engine_normalize( + const axutil_env_t *env, + neethi_policy_t *neethi_policy, + neethi_registry_t *registry, + axis2_bool_t deep) +{ + neethi_policy_t *resultant_neethi_policy = NULL; + neethi_operator_t *operator = NULL; + neethi_operator_t *component = NULL; + neethi_exactlyone_t *exactlyone = NULL; + axis2_char_t *policy_name = NULL; + axis2_char_t *policy_id = NULL; + + /* Normalize policy will be contained in the new policy + * created below */ + + resultant_neethi_policy = neethi_policy_create(env); + if(!resultant_neethi_policy) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + policy_name = neethi_policy_get_name(neethi_policy, env); + if(policy_name) + { + neethi_policy_set_name(resultant_neethi_policy, env, policy_name); + } + policy_id = neethi_policy_get_id(neethi_policy, env); + if(policy_id) + { + neethi_policy_set_id(resultant_neethi_policy, env, policy_id); + } + + operator = neethi_operator_create(env); + if(!operator) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + neethi_operator_set_value(operator, env, neethi_policy, OPERATOR_TYPE_POLICY); + + /* When we call the normalization it should always return an exactlyone as the + * out put. */ + + exactlyone = neethi_engine_normalize_operator(operator, registry, deep, env); + + /* We are frreing the operator used to wrap the object */ + + neethi_operator_set_value_null(operator, env); + neethi_operator_free(operator, env); + operator = NULL; + + /* This exactlyone is set as the first component of the + * normalized policy */ + + if(exactlyone) + { + component = neethi_operator_create(env); + neethi_operator_set_value(component, env, exactlyone, OPERATOR_TYPE_EXACTLYONE); + neethi_policy_add_operator(resultant_neethi_policy, env, component); + + return resultant_neethi_policy; + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_NORMALIZATION_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Normalization failed."); + return NULL; + } +} + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_engine_merge( + const axutil_env_t *env, + neethi_policy_t *neethi_policy1, + neethi_policy_t *neethi_policy2) +{ + + neethi_exactlyone_t *exactlyone1 = NULL; + neethi_exactlyone_t *exactlyone2 = NULL; + neethi_exactlyone_t *exactlyone = NULL; + neethi_policy_t *neethi_policy = NULL; + neethi_operator_t *component = NULL; + + exactlyone1 = neethi_policy_get_exactlyone(neethi_policy1, env); + exactlyone2 = neethi_policy_get_exactlyone(neethi_policy2, env); + + if(!exactlyone1 || !exactlyone2) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_WRONG_INPUT_FOR_MERGE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Wrong input for merge."); + return NULL; + } + exactlyone = neethi_engine_get_cross_product(exactlyone1, exactlyone2, env); + if(exactlyone) + { + neethi_policy = neethi_policy_create(env); + component = neethi_operator_create(env); + if(!neethi_policy || !component) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(component, env, exactlyone, OPERATOR_TYPE_EXACTLYONE); + neethi_policy_add_operator(neethi_policy, env, component); + return neethi_policy; + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_CROSS_PRODUCT_FAILED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cross product failed."); + return NULL; + } +} + +static axis2_bool_t +neethi_engine_operator_is_empty( + neethi_operator_t *operator, + const axutil_env_t *env) +{ + + neethi_operator_type_t type; + void *value = NULL; + neethi_policy_t *neethi_policy = NULL; + neethi_exactlyone_t *exactlyone = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + + type = neethi_operator_get_type(operator, env); + value = neethi_operator_get_value(operator, env); + + if(value) + { + switch(type) + { + case OPERATOR_TYPE_POLICY: + neethi_policy = (neethi_policy_t *)value; + return neethi_policy_is_empty(neethi_policy, env); + break; + + case OPERATOR_TYPE_ALL: + all = (neethi_all_t *)value; + return neethi_all_is_empty(all, env); + break; + + case OPERATOR_TYPE_EXACTLYONE: + exactlyone = (neethi_exactlyone_t *)value; + return neethi_exactlyone_is_empty(exactlyone, env); + break; + + case OPERATOR_TYPE_UNKNOWN: + return AXIS2_FALSE; + break; + + case OPERATOR_TYPE_ASSERTION: + assertion = (neethi_assertion_t *)value; + return neethi_assertion_is_empty(assertion, env); + break; + + case OPERATOR_TYPE_REFERENCE: + break; + + } + return AXIS2_FALSE; + } + else + return AXIS2_FALSE; +} + +static axutil_array_list_t * +neethi_engine_operator_get_components( + neethi_operator_t *operator, + const axutil_env_t *env) +{ + + neethi_operator_type_t type; + void *value = NULL; + neethi_policy_t *neethi_policy = NULL; + neethi_exactlyone_t *exactlyone = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + + type = neethi_operator_get_type(operator, env); + value = neethi_operator_get_value(operator, env); + + if(value) + { + switch(type) + { + case OPERATOR_TYPE_POLICY: + neethi_policy = (neethi_policy_t *)value; + return neethi_policy_get_policy_components(neethi_policy, env); + break; + + case OPERATOR_TYPE_ALL: + all = (neethi_all_t *)value; + return neethi_all_get_policy_components(all, env); + break; + + case OPERATOR_TYPE_EXACTLYONE: + exactlyone = (neethi_exactlyone_t *)value; + return neethi_exactlyone_get_policy_components(exactlyone, env); + break; + + case OPERATOR_TYPE_UNKNOWN: + return NULL; + break; + + case OPERATOR_TYPE_ASSERTION: + assertion = (neethi_assertion_t *)value; + return neethi_assertion_get_policy_components(assertion, env); + break; + + case OPERATOR_TYPE_REFERENCE: + break; + } + } + + return NULL; +} + +static neethi_exactlyone_t * +neethi_engine_normalize_operator( + neethi_operator_t *operator, + neethi_registry_t *registry, + axis2_bool_t deep, + const axutil_env_t *env) +{ + axutil_array_list_t *child_component_list = NULL; + neethi_operator_t *child_component = NULL; + axutil_array_list_t *arraylist = NULL; + int i = 0; + + neethi_operator_type_t type = neethi_operator_get_type(operator, env); + + if(neethi_engine_operator_is_empty(operator, env)) + { + /* If this is an empty operator we just add + * an exactlyone and all */ + + neethi_exactlyone_t *exactlyone = NULL; + exactlyone = neethi_exactlyone_create(env); + if(!exactlyone) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + if(type != OPERATOR_TYPE_EXACTLYONE) + { + neethi_all_t *all = NULL; + neethi_operator_t *component = NULL; + all = neethi_all_create(env); + component = neethi_operator_create(env); + if(!all || !component) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(component, env, all, OPERATOR_TYPE_ALL); + neethi_exactlyone_add_operator(exactlyone, env, component); + } + return exactlyone; + } + + child_component_list = axutil_array_list_create(env, 0); + arraylist = neethi_engine_operator_get_components(operator, env); + + /* Here we are recursively normalize each and every component */ + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + neethi_operator_type_t component_type; + child_component = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + component_type = neethi_operator_get_type(child_component, env); + + if(component_type == OPERATOR_TYPE_ASSERTION) + { + /*Assertion normalization part comes here */ + if(deep) + { + return NULL; + } + else + { + neethi_exactlyone_t *exactlyone = NULL; + neethi_all_t *all = NULL; + neethi_operator_t *op = NULL; + + exactlyone = neethi_exactlyone_create(env); + all = neethi_all_create(env); + op = neethi_operator_create(env); + + if(!all || !op || !exactlyone) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + /* We wrap everything inside an exactlyone */ + + neethi_all_add_operator(all, env, child_component); + neethi_operator_set_value(op, env, all, OPERATOR_TYPE_ALL); + neethi_exactlyone_add_operator(exactlyone, env, op); + axutil_array_list_add(child_component_list, env, exactlyone); + } + } + else if(component_type == OPERATOR_TYPE_POLICY) + { + neethi_policy_t *neethi_policy = NULL; + neethi_all_t *all = NULL; + axutil_array_list_t *children = NULL; + neethi_operator_t *to_normalize = NULL; + neethi_exactlyone_t *exactlyone = NULL; + + all = neethi_all_create(env); + if(!all) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_policy = (neethi_policy_t *)neethi_operator_get_value(child_component, env); + if(neethi_policy) + { + children = neethi_policy_get_policy_components(neethi_policy, env); + if(children) + { + neethi_all_add_policy_components(all, children, env); + to_normalize = neethi_operator_create(env); + if(!to_normalize) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(to_normalize, env, all, OPERATOR_TYPE_ALL); + exactlyone + = neethi_engine_normalize_operator(to_normalize, registry, deep, env); + if(exactlyone) + { + axutil_array_list_add(child_component_list, env, exactlyone); + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_NO_CHILDREN_POLICY_COMPONENTS, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] No children policy components"); + return NULL; + } + } + } + + else if(component_type == OPERATOR_TYPE_REFERENCE) + { + + /* If the operator is a policy reference we will + * extract the relevent policy from the uri and + * normalize as we are doing for a neethi_policy + * object */ + + neethi_reference_t *policy_ref = NULL; + axis2_char_t *uri = NULL; + neethi_policy_t *policy = NULL; + neethi_all_t *all = NULL; + axutil_array_list_t *children = NULL; + neethi_operator_t *to_normalize = NULL; + neethi_exactlyone_t *exactlyone = NULL; + + policy_ref = (neethi_reference_t *)neethi_operator_get_value(child_component, env); + uri = neethi_reference_get_uri(policy_ref, env); + if(!uri) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_URI_NOT_SPECIFIED, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Uri not specified"); + return NULL; + } + + if(!registry) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot resolve the reference.Registry Not provided"); + return NULL; + } + + policy = neethi_registry_lookup(registry, env, uri); + if(!policy) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_NO_ENTRY_FOR_THE_GIVEN_URI, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] No entry for the given uri"); + return NULL; + } + neethi_operator_set_value(child_component, env, policy, OPERATOR_TYPE_POLICY); + + all = neethi_all_create(env); + if(!all) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + policy = (neethi_policy_t *)neethi_operator_get_value(child_component, env); + if(policy) + { + children = neethi_policy_get_policy_components(policy, env); + if(children) + { + neethi_all_add_policy_components(all, children, env); + to_normalize = neethi_operator_create(env); + if(!to_normalize) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(to_normalize, env, all, OPERATOR_TYPE_ALL); + exactlyone + = neethi_engine_normalize_operator(to_normalize, registry, deep, env); + if(exactlyone) + { + axutil_array_list_add(child_component_list, env, exactlyone); + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_NO_CHILDREN_POLICY_COMPONENTS, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] No children policy components"); + return NULL; + } + } + } + else + { + neethi_exactlyone_t *exactlyone = NULL; + exactlyone = neethi_engine_normalize_operator(child_component, registry, deep, env); + if(exactlyone) + { + axutil_array_list_add(child_component_list, env, exactlyone); + } + } + } + + /* So at this point we have set of exactlyones in the array_list, So we will + * compute one exactlyone out of those after the following call */ + + return neethi_engine_compute_resultant_component(child_component_list, type, env); +} + +/* This function will return a single exactlyone from all the + * components in the list */ + +static neethi_exactlyone_t * +neethi_engine_compute_resultant_component( + axutil_array_list_t * normalized_inner_components, + neethi_operator_type_t type, + const axutil_env_t * env) +{ + neethi_exactlyone_t *exactlyone = NULL; + int size = 0; + + if(normalized_inner_components) + { + size = axutil_array_list_size(normalized_inner_components, env); + } + + if(type == OPERATOR_TYPE_EXACTLYONE) + { + /* If the operator is an exactlyone then we get all the components + * in the exatlyones and add them to a newly created exactlyone */ + + int i = 0; + neethi_exactlyone_t *inner_exactlyone = NULL; + exactlyone = neethi_exactlyone_create(env); + + for(i = 0; i < size; i++) + { + inner_exactlyone = (neethi_exactlyone_t *)axutil_array_list_get( + normalized_inner_components, env, i); + if(inner_exactlyone) + { + neethi_exactlyone_add_policy_components(exactlyone, + neethi_exactlyone_get_policy_components(inner_exactlyone, env), env); + } + else + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_EXACTLYONE_NOT_FOUND_IN_NORMALIZED_POLICY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Exactlyone not found in normalized policy"); + return NULL; + } + } + } + else if(type == OPERATOR_TYPE_POLICY || type == OPERATOR_TYPE_ALL) + { + /* Here arry_list contains one exactlyone means this operator + * is already normalized. So we will return that. Otherwise we + * will get the crossproduct. */ + + if(size > 1) + { + /* Get the first one and do the cross product with other + * components */ + + int i = 0; + exactlyone = (neethi_exactlyone_t *)axutil_array_list_get(normalized_inner_components, + env, 0); + if(!exactlyone) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_EXACTLYONE_NOT_FOUND_IN_NORMALIZED_POLICY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Exactlyone not found in normalized policy"); + return NULL; + } + if(!neethi_exactlyone_is_empty(exactlyone, env)) + { + neethi_exactlyone_t *current_exactlyone = NULL; + i = 1; + for(i = 1; i < size; i++) + { + current_exactlyone = (neethi_exactlyone_t *)axutil_array_list_get( + normalized_inner_components, env, i); + if(!current_exactlyone) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_EXACTLYONE_NOT_FOUND_IN_NORMALIZED_POLICY, + AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Exactlyone not found in normalized policy"); + return NULL; + } + if(neethi_exactlyone_is_empty(current_exactlyone, env)) + { + exactlyone = current_exactlyone; + break; + } + else + { + neethi_exactlyone_t *temp = NULL; + neethi_exactlyone_t *temp1 = NULL; + temp = exactlyone; + temp1 = current_exactlyone; + exactlyone = neethi_engine_get_cross_product(exactlyone, + current_exactlyone, env); + neethi_exactlyone_free(temp, env); + neethi_exactlyone_free(temp1, env); + temp = NULL; + temp1 = NULL; + } + } + } + else + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_EXACTLYONE_IS_EMPTY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Exactlyone is Empty"); + return NULL; + } + } + else + { + exactlyone = (neethi_exactlyone_t *)axutil_array_list_get(normalized_inner_components, + env, 0); + } + } + axutil_array_list_free(normalized_inner_components, env); + normalized_inner_components = NULL; + + return exactlyone; +} + +/* The cross product will return all the different combinations + * of alternatives and put them into one exactlyone */ + +static neethi_exactlyone_t * +neethi_engine_get_cross_product( + neethi_exactlyone_t *exactlyone1, + neethi_exactlyone_t *exactlyone2, + const axutil_env_t *env) +{ + neethi_exactlyone_t *cross_product = NULL; + neethi_all_t *cross_product_all = NULL; + neethi_all_t *current_all1 = NULL; + neethi_all_t *current_all2 = NULL; + axutil_array_list_t *array_list1 = NULL; + axutil_array_list_t *array_list2 = NULL; + neethi_operator_t *component = NULL; + int i = 0; + int j = 0; + + cross_product = neethi_exactlyone_create(env); + if(!cross_product) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + array_list1 = neethi_exactlyone_get_policy_components(exactlyone1, env); + array_list2 = neethi_exactlyone_get_policy_components(exactlyone2, env); + + if(!array_list1 || !array_list2) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NEETHI_NO_CHILDREN_POLICY_COMPONENTS, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] No children policy components"); + return NULL; + } + + for(i = 0; i < axutil_array_list_size(array_list1, env); i++) + { + current_all1 = (neethi_all_t *)neethi_operator_get_value( + (neethi_operator_t *)axutil_array_list_get(array_list1, env, i), env); + + if(!current_all1) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_ALL_NOT_FOUND_WHILE_GETTING_CROSS_PRODUCT, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] All not found while getting cross product"); + return NULL; + } + + for(j = 0; j < axutil_array_list_size(array_list2, env); j++) + { + current_all2 = (neethi_all_t *)neethi_operator_get_value( + (neethi_operator_t *)axutil_array_list_get(array_list2, env, j), env); + + if(!current_all2) + { + AXIS2_ERROR_SET(env->error, + AXIS2_ERROR_NEETHI_ALL_NOT_FOUND_WHILE_GETTING_CROSS_PRODUCT, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] All not found while getting cross product"); + return NULL; + } + + cross_product_all = neethi_all_create(env); + if(!cross_product_all) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_all_add_policy_components(cross_product_all, neethi_all_get_policy_components( + current_all1, env), env); + + neethi_all_add_policy_components(cross_product_all, neethi_all_get_policy_components( + current_all2, env), env); + + component = neethi_operator_create(env); + if(!component) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator_set_value(component, env, cross_product_all, OPERATOR_TYPE_ALL); + neethi_exactlyone_add_operator(cross_product, env, component); + } + } + return cross_product; +} + +/*These functions are for serializing a policy object*/ + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +neethi_engine_serialize( + neethi_policy_t *policy, + const axutil_env_t *env) +{ + + return neethi_policy_serialize(policy, NULL, env); +} + +static void +neethi_engine_clear_element_attributes( + axutil_hash_t *attr_hash, + const axutil_env_t *env) +{ + axutil_hash_index_t *hi = NULL; + + for(hi = axutil_hash_first(attr_hash, env); hi; hi = axutil_hash_next(env, hi)) + { + void *val = NULL; + axutil_hash_this(hi, NULL, NULL, &val); + if(val) + { + axiom_attribute_free((axiom_attribute_t *)val, env); + val = NULL; + } + } + axutil_hash_free(attr_hash, env); + attr_hash = NULL; + + return; +} diff --git a/neethi/src/exactlyone.c b/neethi/src/exactlyone.c new file mode 100644 index 0000000..ad94fa2 --- /dev/null +++ b/neethi/src/exactlyone.c @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct neethi_exactlyone_t +{ + axutil_array_list_t *policy_components; +}; + +AXIS2_EXTERN neethi_exactlyone_t *AXIS2_CALL +neethi_exactlyone_create( + const axutil_env_t *env) +{ + neethi_exactlyone_t *neethi_exactlyone = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_exactlyone = (neethi_exactlyone_t *)AXIS2_MALLOC(env->allocator, + sizeof(neethi_exactlyone_t)); + + if(neethi_exactlyone == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_exactlyone->policy_components = NULL; + + neethi_exactlyone->policy_components = axutil_array_list_create(env, 0); + if(!(neethi_exactlyone->policy_components)) + { + neethi_exactlyone_free(neethi_exactlyone, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + return neethi_exactlyone; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_exactlyone_free( + neethi_exactlyone_t *neethi_exactlyone, + const axutil_env_t *env) +{ + if(neethi_exactlyone) + { + if(neethi_exactlyone->policy_components) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(neethi_exactlyone->policy_components, env); + + for(i = 0; i < size; i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get( + neethi_exactlyone->policy_components, env, i); + if(operator) + { + neethi_operator_free(operator, env); + operator = NULL; + } + } + axutil_array_list_free(neethi_exactlyone->policy_components, env); + neethi_exactlyone->policy_components = NULL; + } + AXIS2_FREE(env->allocator, neethi_exactlyone); + neethi_exactlyone = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +neethi_exactlyone_get_policy_components( + neethi_exactlyone_t *neethi_exactlyone, + const axutil_env_t *env) +{ + return neethi_exactlyone->policy_components; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_exactlyone_add_policy_components( + neethi_exactlyone_t *exactlyone, + axutil_array_list_t *arraylist, + const axutil_env_t *env) +{ + + int size = axutil_array_list_size(arraylist, env); + int i = 0; + + if(axutil_array_list_ensure_capacity(exactlyone->policy_components, env, size + 1) + != AXIS2_SUCCESS) + { + return AXIS2_FAILURE; + } + + for(i = 0; i < size; i++) + { + void *value = NULL; + value = axutil_array_list_get(arraylist, env, i); + neethi_operator_increment_ref((neethi_operator_t *)value, env); + axutil_array_list_add(exactlyone->policy_components, env, value); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_exactlyone_add_operator( + neethi_exactlyone_t *neethi_exactlyone, + const axutil_env_t *env, + neethi_operator_t *operator) +{ + neethi_operator_increment_ref(operator, env); + axutil_array_list_add(neethi_exactlyone->policy_components, env, operator); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_exactlyone_is_empty( + neethi_exactlyone_t *exactlyone, + const axutil_env_t *env) +{ + return axutil_array_list_is_empty(exactlyone->policy_components, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_exactlyone_serialize( + neethi_exactlyone_t *neethi_exactlyone, + axiom_node_t *parent, + const axutil_env_t *env) +{ + axiom_node_t *exactlyone_node = NULL; + axiom_element_t *exactlyone_ele = NULL; + axiom_namespace_t *policy_ns = NULL; + axutil_array_list_t *components = NULL; + + policy_ns = axiom_namespace_create(env, NEETHI_NAMESPACE, NEETHI_PREFIX); + exactlyone_ele = axiom_element_create(env, parent, NEETHI_EXACTLYONE, policy_ns, + &exactlyone_node); + if(!exactlyone_node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Cannot create 'ExactlyOne' node. Serialization of 'ExactlyOne' assertion failed"); + return AXIS2_FAILURE; + } + + components = neethi_exactlyone_get_policy_components(neethi_exactlyone, env); + if(components) + { + axis2_status_t status = AXIS2_FAILURE; + int i = 0; + for(i = 0; i < axutil_array_list_size(components, env); i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get(components, env, i); + if(operator) + { + status = neethi_operator_serialize(operator, env, exactlyone_node); + if(status != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Neethi operator serialization failed. " + "Cannot serialize 'ExactlyOne' assertion"); + return AXIS2_FAILURE; + } + } + } + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/mtom_assertion_checker.c b/neethi/src/mtom_assertion_checker.c new file mode 100644 index 0000000..77e5ff0 --- /dev/null +++ b/neethi/src/mtom_assertion_checker.c @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_is_mtom_required( + const axutil_env_t *env, + neethi_policy_t *policy) +{ + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_policy_t *normalized_policy = NULL; + neethi_operator_t *operator = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + int i = 0; + + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + + if(normalized_policy) + { + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + } + + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + /*if (value) + {*/ + if(type == ASSERTION_TYPE_OPTIMIZED_MIME_SERIALIZATION) + { + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + return AXIS2_TRUE; + } + /*}*/ + } + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return AXIS2_FALSE; +} diff --git a/neethi/src/operator.c b/neethi/src/operator.c new file mode 100644 index 0000000..68554dc --- /dev/null +++ b/neethi/src/operator.c @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +struct neethi_operator_t +{ + /* This may be a policy, all, exatlyone, reference + * or an assertion */ + void *value; + + /* The type */ + neethi_operator_type_t type; + + /* Ref count to prevent double frees*/ + int ref; +}; + +AXIS2_EXTERN neethi_operator_t *AXIS2_CALL +neethi_operator_create( + const axutil_env_t *env) +{ + neethi_operator_t *neethi_operator = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_operator = (neethi_operator_t *)AXIS2_MALLOC(env->allocator, sizeof(neethi_operator_t)); + + if(neethi_operator == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_operator->value = NULL; + neethi_operator->type = OPERATOR_TYPE_UNKNOWN; + neethi_operator->ref = 0; + return neethi_operator; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_operator_free( + neethi_operator_t *neethi_operator, + const axutil_env_t *env) +{ + if(neethi_operator) + { + if(--(neethi_operator->ref) > 0) + { + return; + } + + if(neethi_operator->value) + { + switch(neethi_operator->type) + { + case OPERATOR_TYPE_POLICY: + neethi_policy_free((neethi_policy_t *)neethi_operator->value, env); + neethi_operator->value = NULL; + break; + + case OPERATOR_TYPE_ALL: + neethi_all_free((neethi_all_t *)neethi_operator->value, env); + neethi_operator->value = NULL; + break; + + case OPERATOR_TYPE_EXACTLYONE: + neethi_exactlyone_free((neethi_exactlyone_t *)neethi_operator-> value, env); + neethi_operator->value = NULL; + break; + + case OPERATOR_TYPE_REFERENCE: + neethi_reference_free((neethi_reference_t *)neethi_operator-> value, env); + neethi_operator->value = NULL; + break; + + case OPERATOR_TYPE_ASSERTION: + neethi_assertion_free((neethi_assertion_t *)neethi_operator-> value, env); + neethi_operator->value = NULL; + break; + + case OPERATOR_TYPE_UNKNOWN: + break; + } + } + AXIS2_FREE(env->allocator, neethi_operator); + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN neethi_operator_type_t AXIS2_CALL +neethi_operator_get_type( + neethi_operator_t *neethi_operator, + const axutil_env_t *env) +{ + return neethi_operator->type; +} + +AXIS2_EXTERN void *AXIS2_CALL +neethi_operator_get_value( + neethi_operator_t *neethi_operator, + const axutil_env_t *env) +{ + return neethi_operator->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_operator_set_value( + neethi_operator_t *neethi_operator, + const axutil_env_t *env, + void *value, + neethi_operator_type_t type) +{ + neethi_operator->type = type; + neethi_operator->value = (void *)value; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_operator_serialize( + neethi_operator_t *neethi_operator, + const axutil_env_t *env, + axiom_node_t *parent) +{ + neethi_policy_t *policy = NULL; + neethi_all_t *all = NULL; + neethi_exactlyone_t *exactlyone = NULL; + neethi_reference_t *reference = NULL; + neethi_assertion_t *assertion = NULL; + + if(neethi_operator->value) + { + switch(neethi_operator->type) + { + case OPERATOR_TYPE_POLICY: + policy = (neethi_policy_t *)neethi_operator_get_value(neethi_operator, env); + if(!neethi_policy_serialize(policy, parent, env)) + { + return AXIS2_FAILURE; + } + else + { + return AXIS2_SUCCESS; + } + break; + + case OPERATOR_TYPE_ALL: + all = (neethi_all_t *)neethi_operator_get_value(neethi_operator, env); + return neethi_all_serialize(all, parent, env); + break; + + case OPERATOR_TYPE_EXACTLYONE: + exactlyone = (neethi_exactlyone_t *)neethi_operator_get_value(neethi_operator, env); + return neethi_exactlyone_serialize(exactlyone, parent, env); + break; + + case OPERATOR_TYPE_REFERENCE: + reference = (neethi_reference_t *)neethi_operator_get_value(neethi_operator, env); + return neethi_reference_serialize(reference, parent, env); + break; + + case OPERATOR_TYPE_ASSERTION: + assertion = (neethi_assertion_t *)neethi_operator_get_value(neethi_operator, env); + return neethi_assertion_serialize(assertion, parent, env); + break; + + case OPERATOR_TYPE_UNKNOWN: + break; + } + return AXIS2_SUCCESS; + } + else + return AXIS2_FAILURE; +} + +/* We need this method to prevent freeing the value of operator, because some times we wrap certain + * policy operators inside neethi_operator in order to call some functions.See engine.c in neethi + * for more info */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_operator_set_value_null( + neethi_operator_t *neethi_operator, + const axutil_env_t *env) +{ + neethi_operator->value = NULL; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_operator_increment_ref( + neethi_operator_t *operator, + const axutil_env_t *env) +{ + operator-> ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/policy.c b/neethi/src/policy.c new file mode 100644 index 0000000..af08222 --- /dev/null +++ b/neethi/src/policy.c @@ -0,0 +1,446 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +struct neethi_policy_t +{ + /* Contains the child components */ + axutil_array_list_t *policy_components; + + /* A wsp:Policy element can have any number of attributes + * This has will store those */ + axutil_hash_t *attributes; + + /* This is the node containing the policy */ + axiom_node_t *root_node; +}; + +static void +neethi_policy_clear_attributes( + axutil_hash_t *attributes, + const axutil_env_t *env); + +/* Creates a neethi_policy object */ +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_policy_create( + const axutil_env_t * env) +{ + neethi_policy_t *neethi_policy = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_policy = (neethi_policy_t *)AXIS2_MALLOC(env->allocator, sizeof(neethi_policy_t)); + + if(neethi_policy == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_policy->policy_components = NULL; + + neethi_policy->policy_components = axutil_array_list_create(env, 0); + if(!(neethi_policy->policy_components)) + { + neethi_policy_free(neethi_policy, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_policy->attributes = axutil_hash_make(env); + neethi_policy->root_node = NULL; + + return neethi_policy; +} + +/* Deallocate the memory for the neethi_policy object */ +AXIS2_EXTERN void AXIS2_CALL +neethi_policy_free( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + if(neethi_policy) + { + /* We first remove the component list */ + + if(neethi_policy->policy_components) + { + int i = 0; + int size = 0; + + size = axutil_array_list_size(neethi_policy->policy_components, env); + + for(i = 0; i < size; i++) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get( + neethi_policy->policy_components, env, i); + if(operator) + { + neethi_operator_free(operator, env); + } + operator = NULL; + } + axutil_array_list_free(neethi_policy->policy_components, env); + neethi_policy->policy_components = NULL; + } + if(neethi_policy->attributes) + { + neethi_policy_clear_attributes(neethi_policy->attributes, env); + neethi_policy->attributes = NULL; + } + if(neethi_policy->root_node) + { + axiom_node_free_tree(neethi_policy->root_node, env); + neethi_policy->root_node = NULL; + } + AXIS2_FREE(env->allocator, neethi_policy); + neethi_policy = NULL; + } + return; +} + +/* This will free the attribute hash and its content.*/ +static void +neethi_policy_clear_attributes( + axutil_hash_t *attributes, + const axutil_env_t *env) +{ + if(attributes) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + const void *key = NULL; + + for(hi = axutil_hash_first(attributes, env); hi; hi = axutil_hash_next(env, hi)) + { + axutil_hash_this(hi, &key, NULL, &val); + + if(key) + { + AXIS2_FREE(env->allocator, (axis2_char_t *)key); + key = NULL; + } + + if(val) + { + AXIS2_FREE(env->allocator, (axis2_char_t *)val); + val = NULL; + } + } + axutil_hash_free(attributes, env); + attributes = NULL; + } +} +/* Implementations */ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +neethi_policy_get_policy_components( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + return neethi_policy->policy_components; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_policy_add_policy_components( + neethi_policy_t *neethi_policy, + axutil_array_list_t *arraylist, + const axutil_env_t *env) +{ + int size = axutil_array_list_size(arraylist, env); + int i = 0; + + if(axutil_array_list_ensure_capacity(neethi_policy->policy_components, env, size + 1) + != AXIS2_SUCCESS) + { + return AXIS2_FAILURE; + } + + for(i = 0; i < size; i++) + { + void *value = NULL; + value = axutil_array_list_get(arraylist, env, i); + /* The ref count is incremented in order to prevent double frees.*/ + neethi_operator_increment_ref((neethi_operator_t *)value, env); + axutil_array_list_add(neethi_policy->policy_components, env, value); + } + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_policy_add_operator( + neethi_policy_t *neethi_policy, + const axutil_env_t *env, + neethi_operator_t *operator) +{ + neethi_operator_increment_ref(operator, env); + axutil_array_list_add(neethi_policy->policy_components, env, operator); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +neethi_policy_is_empty( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + return axutil_array_list_is_empty(neethi_policy->policy_components, env); +} + +/* A normalized policy always has just one child and it is an exactlyone + * first child. So this method */ +AXIS2_EXTERN neethi_exactlyone_t *AXIS2_CALL +neethi_policy_get_exactlyone( + neethi_policy_t *normalized_neethi_policy, + const axutil_env_t *env) +{ + neethi_exactlyone_t *exactlyone = NULL; + axutil_array_list_t *list = NULL; + + list = neethi_policy_get_policy_components(normalized_neethi_policy, env); + if(list) + { + if(axutil_array_list_size(list, env) == 1) + { + neethi_operator_t *op = NULL; + op = (neethi_operator_t *)axutil_array_list_get(list, env, 0); + if(!op) + { + return NULL; + } + if(neethi_operator_get_type(op, env) != OPERATOR_TYPE_EXACTLYONE) + { + return NULL; + } + exactlyone = (neethi_exactlyone_t *)neethi_operator_get_value(op, env); + return exactlyone; + } + else + return NULL; + } + else + return NULL; +} + +/* This function is called for a normalized policy So it will return the components of the only + * child. That should be an exactlyone The children of that exactlyone are all.*/ +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +neethi_policy_get_alternatives( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + neethi_exactlyone_t *exactlyone = NULL; + exactlyone = neethi_policy_get_exactlyone(neethi_policy, env); + if(!exactlyone) + return NULL; + + return neethi_exactlyone_get_policy_components(exactlyone, env); + +} + +/* This will return any attribute which has the local name of Name */ +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +neethi_policy_get_name( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + if(neethi_policy->attributes) + { + axutil_qname_t *qname = NULL; + axis2_char_t *name = NULL; + qname = axutil_qname_create(env, NEETHI_NAME, NULL, NULL); + + if(qname) + { + axis2_char_t *key = axutil_qname_to_string(qname, env); + if(key) + { + name = (axis2_char_t *)axutil_hash_get(neethi_policy->attributes, key, + AXIS2_HASH_KEY_STRING); + } + axutil_qname_free(qname, env); + qname = NULL; + return name; + } + else + { + return NULL; + } + } + else + { + return NULL; + } +} + +/* This method will return the attribute value of wsu:Id if there are any such attributes */ +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +neethi_policy_get_id( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + if(neethi_policy->attributes) + { + axis2_char_t *id = NULL; + axutil_qname_t *qname = NULL; + qname = axutil_qname_create(env, NEETHI_ID, NEETHI_WSU_NS, NULL); + + if(qname) + { + axis2_char_t *key = axutil_qname_to_string(qname, env); + if(key) + { + id = (axis2_char_t *)axutil_hash_get(neethi_policy->attributes, key, + AXIS2_HASH_KEY_STRING); + } + axutil_qname_free(qname, env); + qname = NULL; + return id; + } + else + { + return NULL; + } + } + else + { + return NULL; + } +} + +/* When we encounter an attribute with wsu:Id we will store it in the hash. We are not + * considering the prefix. Just the namespace and the local_name. */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_policy_set_id( + neethi_policy_t * neethi_policy, + const axutil_env_t * env, + axis2_char_t * id) +{ + axutil_qname_t *qname = NULL; + axis2_char_t *key = NULL; + + qname = axutil_qname_create(env, NEETHI_ID, NEETHI_WSU_NS, NULL); + + if(qname) + { + key = axutil_qname_to_string(qname, env); + if(key) + { + axutil_hash_set(neethi_policy->attributes, axutil_strdup(env, key), + AXIS2_HASH_KEY_STRING, axutil_strdup(env, id)); + } + axutil_qname_free(qname, env); + return AXIS2_SUCCESS; + } + else + { + return AXIS2_FAILURE; + } +} + +/* When we encounter an attribute with Name we will store it in the hash. This has no Namespace.*/ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_policy_set_name( + neethi_policy_t * neethi_policy, + const axutil_env_t * env, + axis2_char_t * name) +{ + axutil_qname_t *qname = NULL; + axis2_char_t *key = NULL; + + qname = axutil_qname_create(env, NEETHI_NAME, NULL, NULL); + + if(qname) + { + key = axutil_qname_to_string(qname, env); + if(key) + { + axutil_hash_set(neethi_policy->attributes, axutil_strdup(env, key), + AXIS2_HASH_KEY_STRING, axutil_strdup(env, name)); + } + axutil_qname_free(qname, env); + return AXIS2_SUCCESS; + } + else + { + return AXIS2_FAILURE; + } +} + +AXIS2_EXTERN axutil_hash_t *AXIS2_CALL +neethi_policy_get_attributes( + neethi_policy_t *neethi_policy, + const axutil_env_t *env) +{ + return neethi_policy->attributes; +} + +/*This function is for serializing*/ +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +neethi_policy_serialize( + neethi_policy_t *neethi_policy, + axiom_node_t *parent, + const axutil_env_t *env) +{ + axiom_node_t *policy_node = NULL; + axiom_element_t *policy_ele = NULL; + axiom_namespace_t *policy_ns = NULL; + axutil_array_list_t *components = NULL; + + policy_ns = axiom_namespace_create(env, NEETHI_NAMESPACE, NEETHI_PREFIX); + policy_ele = axiom_element_create(env, parent, NEETHI_POLICY, policy_ns, &policy_node); + if(!policy_ele) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "Cannot create policy node. Policy serialization failed"); + return NULL; + } + + components = neethi_policy_get_policy_components(neethi_policy, env); + if(components) + { + int i = 0; + axis2_status_t status = AXIS2_FAILURE; + for(i = 0; i < axutil_array_list_size(components, env); ++i) + { + neethi_operator_t *operator = NULL; + operator = (neethi_operator_t *)axutil_array_list_get(components, env, i); + if(operator) + { + status = neethi_operator_serialize(operator, env, policy_node); + if(status != AXIS2_SUCCESS) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Neethi operator serialization failed."); + return NULL; + } + } + } + } + return policy_node; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_policy_set_root_node( + neethi_policy_t *policy, + const axutil_env_t *env, + axiom_node_t *root_node) +{ + policy->root_node = root_node; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/reference.c b/neethi/src/reference.c new file mode 100644 index 0000000..8b52a26 --- /dev/null +++ b/neethi/src/reference.c @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct neethi_reference_t +{ + axis2_char_t *uri; +}; + +AXIS2_EXTERN neethi_reference_t *AXIS2_CALL +neethi_reference_create( + const axutil_env_t *env) +{ + neethi_reference_t *neethi_reference = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_reference = (neethi_reference_t *)AXIS2_MALLOC(env->allocator, + sizeof(neethi_reference_t)); + + if(neethi_reference == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_reference->uri = NULL; + + return neethi_reference; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_reference_free( + neethi_reference_t *neethi_reference, + const axutil_env_t *env) +{ + if(neethi_reference) + { + AXIS2_FREE(env->allocator, neethi_reference); + neethi_reference = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +neethi_reference_get_uri( + neethi_reference_t *neethi_reference, + const axutil_env_t *env) +{ + return neethi_reference->uri; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_reference_set_uri( + neethi_reference_t *neethi_reference, + const axutil_env_t *env, + axis2_char_t *uri) +{ + neethi_reference->uri = uri; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_reference_serialize( + neethi_reference_t *neethi_reference, + axiom_node_t *parent, + const axutil_env_t *env) +{ + axiom_node_t *ref_node = NULL; + axiom_element_t *ref_ele = NULL; + axiom_namespace_t *policy_ns = NULL; + axiom_attribute_t *att_uri = NULL; + + policy_ns = axiom_namespace_create(env, NEETHI_NAMESPACE, NEETHI_PREFIX); + ref_ele = axiom_element_create(env, parent, NEETHI_REFERENCE, policy_ns, &ref_node); + if(!ref_node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "'reference' node creation failed. Cannot serialize 'reference' assertion"); + return AXIS2_FAILURE; + } + + att_uri = axiom_attribute_create(env, NEETHI_URI, neethi_reference->uri, NULL); + axiom_element_add_attribute(ref_ele, env, att_uri, ref_node); + + return AXIS2_SUCCESS; +} diff --git a/neethi/src/registry.c b/neethi/src/registry.c new file mode 100644 index 0000000..4ba0851 --- /dev/null +++ b/neethi/src/registry.c @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct neethi_registry_t +{ + axutil_hash_t *registry; + neethi_registry_t *parent; +}; + +AXIS2_EXTERN neethi_registry_t *AXIS2_CALL +neethi_registry_create( + const axutil_env_t *env) +{ + neethi_registry_t *neethi_registry = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + neethi_registry = (neethi_registry_t *)AXIS2_MALLOC(env->allocator, sizeof(neethi_registry_t)); + + if(neethi_registry == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_registry->registry = NULL; + + neethi_registry->registry = axutil_hash_make(env); + if(!(neethi_registry->registry)) + { + neethi_registry_free(neethi_registry, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + neethi_registry->parent = NULL; + + return neethi_registry; +} + +AXIS2_EXTERN neethi_registry_t *AXIS2_CALL +neethi_registry_create_with_parent( + const axutil_env_t *env, + neethi_registry_t *parent) +{ + neethi_registry_t *neethi_registry = NULL; + + neethi_registry = neethi_registry_create(env); + if(!neethi_registry) + return NULL; + + neethi_registry->parent = parent; + return neethi_registry; +} + +AXIS2_EXTERN void AXIS2_CALL +neethi_registry_free( + neethi_registry_t *neethi_registry, + const axutil_env_t *env) +{ + if(neethi_registry->registry) + { + axutil_hash_index_t *hi = NULL; + void *val = NULL; + for(hi = axutil_hash_first(neethi_registry->registry, env); hi; hi = axutil_hash_next(env, + hi)) + { + neethi_policy_t *neethi_policy = NULL; + axutil_hash_this(hi, NULL, NULL, &val); + neethi_policy = (neethi_policy_t *)val; + if(neethi_policy) + neethi_policy_free(neethi_policy, env); + val = NULL; + neethi_policy = NULL; + + } + axutil_hash_free(neethi_registry->registry, env); + } + if(neethi_registry->parent) + { + neethi_registry->parent = NULL; + } + AXIS2_FREE(env->allocator, neethi_registry); +} + +/* Implementations */ + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +neethi_registry_register( + neethi_registry_t *neethi_registry, + const axutil_env_t *env, + axis2_char_t *key, + neethi_policy_t *value) +{ + axutil_hash_set(neethi_registry->registry, key, AXIS2_HASH_KEY_STRING, value); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_registry_lookup( + neethi_registry_t *neethi_registry, + const axutil_env_t *env, + axis2_char_t *key) +{ + neethi_policy_t *policy = NULL; + + policy = (neethi_policy_t *)axutil_hash_get(neethi_registry->registry, key, + AXIS2_HASH_KEY_STRING); + + if(!policy && neethi_registry->parent) + { + return neethi_registry_lookup(neethi_registry->parent, env, key); + } + return policy; +} diff --git a/neethi/src/rmpolicy/Makefile.am b/neethi/src/rmpolicy/Makefile.am new file mode 100644 index 0000000..1b46d73 --- /dev/null +++ b/neethi/src/rmpolicy/Makefile.am @@ -0,0 +1,13 @@ +TESTS = + +noinst_LTLIBRARIES = librm_policy.la + +librm_policy_la_SOURCES = rm_assertion.c rm_assertion_builder.c + +librm_policy_la_LIBADD = ../../../util/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../include \ + -I ../../../util/include \ + -I ../../../axiom/include \ + -I ../../../include diff --git a/neethi/src/rmpolicy/rm_assertion.c b/neethi/src/rmpolicy/rm_assertion.c new file mode 100644 index 0000000..42f0fd4 --- /dev/null +++ b/neethi/src/rmpolicy/rm_assertion.c @@ -0,0 +1,511 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +struct axis2_rm_assertion_t +{ + /* RM Policy 1.1 assertions */ + axis2_bool_t is_sequence_str; + axis2_bool_t is_sequence_transport_security; + axis2_bool_t is_exactly_once; + axis2_bool_t is_atleast_once; + axis2_bool_t is_atmost_once; + axis2_bool_t is_inorder; + + /* RM Policy 1.0 assertions */ + axis2_char_t *inactivity_timeout; + axis2_char_t *retrans_interval; + axis2_char_t *ack_interval; + axis2_bool_t is_exp_backoff; + + /* Sandesha2 specific assrtions */ + axis2_char_t *storage_mgr; + axis2_char_t *message_types_to_drop; + axis2_char_t *max_retrans_count; + axis2_char_t *sender_sleep_time; + axis2_char_t *invoker_sleep_time; + axis2_char_t *polling_wait_time; + axis2_char_t *terminate_delay; + axis2_char_t *sandesha2_db; + axis2_char_t *spec_version; +}; + +AXIS2_EXTERN axis2_rm_assertion_t *AXIS2_CALL +axis2_rm_assertion_create( + const axutil_env_t * env) +{ + axis2_rm_assertion_t *rm_assertion; + + rm_assertion = (axis2_rm_assertion_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_rm_assertion_t)); + + if(rm_assertion == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + rm_assertion->is_sequence_str = AXIS2_FALSE; + rm_assertion->is_sequence_transport_security = AXIS2_FALSE; + rm_assertion->is_exactly_once = AXIS2_TRUE; + rm_assertion->is_atleast_once = AXIS2_FALSE; + rm_assertion->is_atmost_once = AXIS2_FALSE; + rm_assertion->is_inorder = AXIS2_FALSE; + + /* RM Policy 1.0 assertions */ + rm_assertion->inactivity_timeout = NULL; + rm_assertion->retrans_interval = NULL; + rm_assertion->ack_interval = NULL; + rm_assertion->is_exp_backoff = AXIS2_FALSE; + + /* Sandesha2 specific assrtions */ + rm_assertion->storage_mgr = NULL; + rm_assertion->message_types_to_drop = NULL; + rm_assertion->max_retrans_count = NULL; + rm_assertion->sender_sleep_time = NULL; + rm_assertion->invoker_sleep_time = NULL; + rm_assertion->polling_wait_time = NULL; + rm_assertion->terminate_delay = NULL; + rm_assertion->sandesha2_db = NULL; + rm_assertion->spec_version = NULL; + + return rm_assertion; +} + +AXIS2_EXTERN void AXIS2_CALL +axis2_rm_assertion_free( + axis2_rm_assertion_t * rm_assertion, + const axutil_env_t * env) +{ + if(rm_assertion) + { + AXIS2_FREE(env->allocator, rm_assertion); + rm_assertion = NULL; + } + + return; +} + +/* Implementations. + * Following functions are getters and setters + * for rm_assertion struct */ + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_sequence_str( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_sequence_str; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_sequence_str( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_sequence_str) +{ + rm_assertion->is_sequence_str = is_sequence_str; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_sequence_transport_security( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_sequence_transport_security; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_sequence_transport_security( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_sequence_transport_security) +{ + rm_assertion->is_sequence_transport_security = is_sequence_transport_security; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_exactly_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_exactly_once; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_exactly_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_exactly_once) +{ + rm_assertion->is_exactly_once = is_exactly_once; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_atleast_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_atleast_once; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_atleast_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_atleast_once) +{ + rm_assertion->is_atleast_once = is_atleast_once; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_atmost_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_atmost_once; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_atmost_once( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_atmost_once) +{ + rm_assertion->is_atmost_once = is_atmost_once; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_inorder( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_inorder; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_inorder( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_inorder) +{ + rm_assertion->is_inorder = is_inorder; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_inactivity_timeout( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->inactivity_timeout; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_inactivity_timeout( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* inactivity_timeout) +{ + rm_assertion->inactivity_timeout = inactivity_timeout; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_retrans_interval( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->retrans_interval; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_retrans_interval( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* retrans_interval) +{ + rm_assertion->retrans_interval = retrans_interval; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_ack_interval( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->ack_interval; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_ack_interval( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* ack_interval) +{ + rm_assertion->ack_interval = ack_interval; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +axis2_rm_assertion_get_is_exp_backoff( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->is_exp_backoff; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_is_exp_backoff( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_bool_t is_exp_backoff) +{ + rm_assertion->is_exp_backoff = is_exp_backoff; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_storage_mgr( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->storage_mgr; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_storage_mgr( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* storage_mgr) +{ + rm_assertion->storage_mgr = storage_mgr; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_message_types_to_drop( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->message_types_to_drop; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_message_types_to_drop( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* message_types_to_drop) +{ + rm_assertion->message_types_to_drop = message_types_to_drop; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_max_retrans_count( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->max_retrans_count; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_max_retrans_count( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* max_retrans_count) +{ + rm_assertion->max_retrans_count = max_retrans_count; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_sender_sleep_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->sender_sleep_time; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_sender_sleep_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* sender_sleep_time) +{ + rm_assertion->sender_sleep_time = sender_sleep_time; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_invoker_sleep_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->invoker_sleep_time; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_invoker_sleep_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* invoker_sleep_time) +{ + rm_assertion->invoker_sleep_time = invoker_sleep_time; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_polling_wait_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->polling_wait_time; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_polling_wait_time( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* polling_wait_time) +{ + rm_assertion->polling_wait_time = polling_wait_time; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_terminate_delay( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->terminate_delay; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_terminate_delay( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* terminate_delay) +{ + rm_assertion->terminate_delay = terminate_delay; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_sandesha2_db( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->sandesha2_db; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_sandesha2_db( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* sandesha2_db) +{ + rm_assertion->sandesha2_db = sandesha2_db; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t* AXIS2_CALL +axis2_rm_assertion_get_spec_version( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env) +{ + return rm_assertion->spec_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axis2_rm_assertion_set_spec_version( + axis2_rm_assertion_t *rm_assertion, + const axutil_env_t * env, + axis2_char_t* spec_version) +{ + rm_assertion->spec_version = spec_version; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_rm_assertion_t* AXIS2_CALL +axis2_rm_assertion_get_from_policy( + const axutil_env_t *env, + neethi_policy_t *policy) +{ + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_operator_t *operator = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + int i = 0; + + alternatives = neethi_policy_get_alternatives(policy, env); + + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_RM_ASSERTION) + { + return (axis2_rm_assertion_t *)value; + } + } + } + + return NULL; +} + diff --git a/neethi/src/rmpolicy/rm_assertion_builder.c b/neethi/src/rmpolicy/rm_assertion_builder.c new file mode 100644 index 0000000..9b92fd7 --- /dev/null +++ b/neethi/src/rmpolicy/rm_assertion_builder.c @@ -0,0 +1,562 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/*private functions*/ + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_process_sandesha2_assertions( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *node, + axiom_element_t *element); + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_populate_for_10( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *rm_assertion_node, + axiom_element_t *rm_assertion_element); + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_populate_for_11( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *rm_assertion_node, + axiom_element_t *rm_assertion_element); + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_process_delivery_assuarance( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *da_node, + axiom_element_t *da_element); + +/* This functions retrives a rm_assertion axiom_node + * which may be 1.0 or 1.1 and return a rm_assertion + * struct */ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +axis2_rm_assertion_builder_build( + const axutil_env_t *env, + axiom_node_t *rm_assertion_node, + axiom_element_t *rm_assertion_ele) +{ + axis2_rm_assertion_t *rm_assertion = NULL; + axis2_status_t status = AXIS2_SUCCESS; + axiom_children_iterator_t *children_iter = NULL; + neethi_assertion_t *assertion = NULL; + axis2_char_t *ns = NULL; + axutil_qname_t *node_qname = NULL; + + node_qname = axiom_element_get_qname(rm_assertion_ele, env, rm_assertion_node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get qname from element"); + return NULL; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get namespace from element."); + return NULL; + } + + rm_assertion = axis2_rm_assertion_create(env); + if(!rm_assertion) + { + return NULL; + } + + /* First we check whether this is in 1.0 or 1.1 + * namespace. Then we called the appropriate builder */ + + children_iter = axiom_element_get_children(rm_assertion_ele, env, rm_assertion_node); + + if(!axutil_strcmp(ns, AXIS2_RM_POLICY_10_NS)) + { + status = axis2_rm_assertion_builder_populate_for_10(env, rm_assertion, rm_assertion_node, + rm_assertion_ele); + + axiom_children_iterator_reset(children_iter, env); + + } + else if(!axutil_strcmp(ns, AXIS2_RM_POLICY_11_NS)) + { + status = axis2_rm_assertion_builder_populate_for_11(env, rm_assertion, rm_assertion_node, + rm_assertion_ele); + } + + if(status == AXIS2_FAILURE) + { + axis2_rm_assertion_free(rm_assertion, env); + rm_assertion = NULL; + return NULL; + } + + /*children_iter = axiom_element_get_children(rm_assertion_ele, env, rm_assertion_node);*/ + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + axutil_qname_t *node_qname = NULL; + + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + node_qname = axiom_element_get_qname(ele, env, node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get qname from element %s.", local_name); + return NULL; + } + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get namespace from element %s.", local_name); + return NULL; + } + if(!axutil_strcmp(ns, AXIS2_SANDESHA2_NS)) + { + status = axis2_rm_assertion_builder_process_sandesha2_assertions(env, + rm_assertion, node, ele); + if(status == AXIS2_FAILURE) + { + axis2_rm_assertion_free(rm_assertion, env); + rm_assertion = NULL; + return NULL; + } + } + } + } + } + } + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)axis2_rm_assertion_free, rm_assertion, ASSERTION_TYPE_RM_ASSERTION); + return assertion; +} + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_populate_for_10( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *rm_assertion_node, + axiom_element_t *rm_assertion_element) +{ + axiom_children_iterator_t *children_iter = NULL; + axis2_status_t status = AXIS2_FAILURE; + + /* In rm 1.0 it is just child elements which inside + * rm_assertion contains all the properties. */ + + status = axis2_rm_assertion_set_spec_version(rm_assertion, env, RM_SPEC_VERSION_1_0); + + children_iter = axiom_element_get_children(rm_assertion_element, env, rm_assertion_node); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + if(ele) + { + axutil_qname_t *node_qname = NULL; + axis2_char_t *ns = NULL; + node_qname = axiom_element_get_qname(ele, env, node); + if(!node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get qname from element"); + return AXIS2_FAILURE; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get namespace from element."); + return AXIS2_FAILURE; + } + + if(axutil_strcmp(ns, AXIS2_RM_POLICY_10_NS)) + { + continue; + } + + local_name = axiom_element_get_localname(ele, env); + if(local_name) + { + + if(!axutil_strcmp(local_name, AXIS2_RM_INACTIVITY_TIMEOUT)) + { + axis2_char_t *inactivity_timeout = NULL; + axutil_qname_t *qname = NULL; + + qname = axutil_qname_create(env, "Milliseconds", NULL, NULL); + + inactivity_timeout = axiom_element_get_attribute_value(ele, env, + qname); + if(qname) + { + axutil_qname_free(qname, env); + qname = NULL; + } + status = axis2_rm_assertion_set_inactivity_timeout(rm_assertion, + env, inactivity_timeout); + } + else if(!axutil_strcmp(local_name, + AXIS2_RM_BASE_RETRANSMISSION_INTERVAL)) + { + axis2_char_t *rti = NULL; + axutil_qname_t *qname = NULL; + qname = axutil_qname_create(env, "Milliseconds", NULL, NULL); + + rti = axiom_element_get_attribute_value(ele, env, qname); + if(qname) + { + axutil_qname_free(qname, env); + qname = NULL; + } + status = axis2_rm_assertion_set_retrans_interval(rm_assertion, env, + rti); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_EXPONENTIAL_BACK_OFF)) + { + status = axis2_rm_assertion_set_is_exp_backoff(rm_assertion, env, + AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_ACKNOWLEDGEMENT_INTERVAL)) + { + axis2_char_t *ack_interval = NULL; + axutil_qname_t *qname = NULL; + + qname = axutil_qname_create(env, "Milliseconds", NULL, NULL); + + ack_interval = axiom_element_get_attribute_value(ele, env, qname); + if(qname) + { + axutil_qname_free(qname, env); + qname = NULL; + } + status = axis2_rm_assertion_set_ack_interval(rm_assertion, env, + ack_interval); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Unknown Assertion %s ", local_name); + return AXIS2_FAILURE; + } + } + } + } + } + } + } + return status; +} + +/* In rm 1.1 rm_assertion contains a policy element as + * a child element. We are not creating a policy object + * for policy element. Becasue then the processing become + * complex.So we just parse the axiom model */ + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_populate_for_11( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *rm_assertion_node, + axiom_element_t *rm_assertion_element) +{ + axiom_children_iterator_t *children_iter = NULL; + axis2_status_t status = AXIS2_FAILURE; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + + status = axis2_rm_assertion_set_spec_version(rm_assertion, env, RM_SPEC_VERSION_1_1); + + child_node = axiom_node_get_first_element(rm_assertion_node, env); + if(child_node) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + children_iter = axiom_element_get_children(child_element, env, child_node); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + if(ele) + { + axutil_qname_t *node_qname = NULL; + axis2_char_t *ns = NULL; + node_qname = axiom_element_get_qname(ele, env, node); + if(!node) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get qname from element"); + return AXIS2_FAILURE; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get namespace from element."); + return AXIS2_FAILURE; + } + + if(axutil_strcmp(ns, AXIS2_RM_POLICY_11_NS)) + { + continue; + } + local_name = axiom_element_get_localname(ele, env); + if(local_name) + { + if(!axutil_strcmp(local_name, AXIS2_RM_SEQUENCE_STR)) + { + status = axis2_rm_assertion_set_is_sequence_str( + rm_assertion, env, AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, + AXIS2_RM_SEQUENCE_TRANSPORT_SECURITY)) + { + status + = axis2_rm_assertion_set_is_sequence_transport_security( + rm_assertion, env, AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_DELIVERY_ASSURANCE)) + { + status + = axis2_rm_assertion_builder_process_delivery_assuarance( + env, rm_assertion, node, ele); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Unknown Assertion %s ", local_name); + return AXIS2_FAILURE; + } + } + } + } + } + } + } + } + } + + return status; +} + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_process_delivery_assuarance( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *da_node, + axiom_element_t *da_element) +{ + axiom_children_iterator_t *children_iter = NULL; + axis2_status_t status = AXIS2_FAILURE; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + + child_node = axiom_node_get_first_element(da_node, env); + if(child_node) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + children_iter = axiom_element_get_children(child_element, env, child_node); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + if(ele) + { + local_name = axiom_element_get_localname(ele, env); + if(local_name) + { + if(!axutil_strcmp(local_name, AXIS2_RM_EXACTLY_ONCE)) + { + status = axis2_rm_assertion_set_is_exactly_once( + rm_assertion, env, AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_AT_LEAST_ONCE)) + { + status = axis2_rm_assertion_set_is_atleast_once( + rm_assertion, env, AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_AT_MOST_ONCE)) + { + status = axis2_rm_assertion_set_is_atmost_once( + rm_assertion, env, AXIS2_TRUE); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_IN_ORDER)) + { + status = axis2_rm_assertion_set_is_inorder(rm_assertion, + env, AXIS2_TRUE); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Unknown Assertion %s ", local_name); + return AXIS2_FAILURE; + } + } + } + } + } + } + } + } + } + return status; +} + +static axis2_status_t AXIS2_CALL +axis2_rm_assertion_builder_process_sandesha2_assertions( + const axutil_env_t *env, + axis2_rm_assertion_t *rm_assertion, + axiom_node_t *node, + axiom_element_t *element) +{ + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *local_name = NULL; + + if(element) + { + local_name = axiom_element_get_localname(element, env); + if(local_name) + { + if(!axutil_strcmp(local_name, AXIS2_RM_BASE_RETRANSMISSION_INTERVAL)) + { + axis2_char_t *rti = NULL; + rti = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_retrans_interval(rm_assertion, env, rti); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_INACTIVITY_TIMEOUT)) + { + axis2_char_t *inactivity_timeout = NULL; + inactivity_timeout = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_inactivity_timeout(rm_assertion, env, + inactivity_timeout); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_ACKNOWLEDGEMENT_INTERVAL)) + { + axis2_char_t *ack_interval = NULL; + ack_interval = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_ack_interval(rm_assertion, env, ack_interval); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_STORAGE_MANAGER)) + { + axis2_char_t *storage_mgr = NULL; + storage_mgr = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_storage_mgr(rm_assertion, env, storage_mgr); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_SANDESHA2_DB)) + { + axis2_char_t *sandesha2_db = NULL; + sandesha2_db = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_sandesha2_db(rm_assertion, env, sandesha2_db); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_MESSAGE_TYPES_TO_DROP)) + { + axis2_char_t *message_types_to_drop = NULL; + message_types_to_drop = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_message_types_to_drop(rm_assertion, env, + message_types_to_drop); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_MAX_RETRANS_COUNT)) + { + axis2_char_t *retrans_count = NULL; + retrans_count = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_max_retrans_count(rm_assertion, env, retrans_count); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_SENDER_SLEEP_TIME)) + { + axis2_char_t *sender_sleep_time = NULL; + sender_sleep_time = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_sender_sleep_time(rm_assertion, env, + sender_sleep_time); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_INVOKER_SLEEP_TIME)) + { + axis2_char_t *invoker_sleep_time = NULL; + invoker_sleep_time = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_invoker_sleep_time(rm_assertion, env, + invoker_sleep_time); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_POLLING_WAIT_TIME)) + { + axis2_char_t *polling_wait_time = NULL; + polling_wait_time = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_polling_wait_time(rm_assertion, env, + polling_wait_time); + } + else if(!axutil_strcmp(local_name, AXIS2_RM_TERMINATE_DELAY)) + { + axis2_char_t *terminate_delay = NULL; + terminate_delay = axiom_element_get_text(element, env, node); + return axis2_rm_assertion_set_terminate_delay(rm_assertion, env, terminate_delay); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Unknown Assertion %s ", + local_name); + return AXIS2_FAILURE; + } + } + } + return status; +} + diff --git a/neethi/src/samples/test1.xml b/neethi/src/samples/test1.xml new file mode 100644 index 0000000..6cf1539 --- /dev/null +++ b/neethi/src/samples/test1.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/neethi/src/samples/test10.xml b/neethi/src/samples/test10.xml new file mode 100644 index 0000000..0c16d15 --- /dev/null +++ b/neethi/src/samples/test10.xml @@ -0,0 +1 @@ + diff --git a/neethi/src/samples/test11.xml b/neethi/src/samples/test11.xml new file mode 100644 index 0000000..453688a --- /dev/null +++ b/neethi/src/samples/test11.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test12.xml b/neethi/src/samples/test12.xml new file mode 100644 index 0000000..322d865 --- /dev/null +++ b/neethi/src/samples/test12.xml @@ -0,0 +1 @@ +sec:X509v3wsp:Body() \ No newline at end of file diff --git a/neethi/src/samples/test13.xml b/neethi/src/samples/test13.xml new file mode 100644 index 0000000..7817caf --- /dev/null +++ b/neethi/src/samples/test13.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test14.xml b/neethi/src/samples/test14.xml new file mode 100644 index 0000000..00dcab5 --- /dev/null +++ b/neethi/src/samples/test14.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test15.xml b/neethi/src/samples/test15.xml new file mode 100644 index 0000000..d8b2e20 --- /dev/null +++ b/neethi/src/samples/test15.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test16.xml b/neethi/src/samples/test16.xml new file mode 100644 index 0000000..7304862 --- /dev/null +++ b/neethi/src/samples/test16.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test17.xml b/neethi/src/samples/test17.xml new file mode 100644 index 0000000..fc995b1 --- /dev/null +++ b/neethi/src/samples/test17.xml @@ -0,0 +1 @@ +sec:X509v3sec:Kerberosv5TGTsec:Kerberosv5ST \ No newline at end of file diff --git a/neethi/src/samples/test18.xml b/neethi/src/samples/test18.xml new file mode 100644 index 0000000..0c6f9dc --- /dev/null +++ b/neethi/src/samples/test18.xml @@ -0,0 +1 @@ + diff --git a/neethi/src/samples/test19.xml b/neethi/src/samples/test19.xml new file mode 100644 index 0000000..243054a --- /dev/null +++ b/neethi/src/samples/test19.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test2.xml b/neethi/src/samples/test2.xml new file mode 100644 index 0000000..13d7a1b --- /dev/null +++ b/neethi/src/samples/test2.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test20.xml b/neethi/src/samples/test20.xml new file mode 100644 index 0000000..be83fae --- /dev/null +++ b/neethi/src/samples/test20.xml @@ -0,0 +1 @@ + diff --git a/neethi/src/samples/test21.xml b/neethi/src/samples/test21.xml new file mode 100644 index 0000000..aecc311 --- /dev/null +++ b/neethi/src/samples/test21.xml @@ -0,0 +1,10 @@ + + + + sec:X509v3 + + + + wsp:Body() + + \ No newline at end of file diff --git a/neethi/src/samples/test22.xml b/neethi/src/samples/test22.xml new file mode 100644 index 0000000..8942352 --- /dev/null +++ b/neethi/src/samples/test22.xml @@ -0,0 +1 @@ +sec:X509v3 \ No newline at end of file diff --git a/neethi/src/samples/test23.xml b/neethi/src/samples/test23.xml new file mode 100644 index 0000000..e0c1bf8 --- /dev/null +++ b/neethi/src/samples/test23.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test24.xml b/neethi/src/samples/test24.xml new file mode 100644 index 0000000..2aa5b09 --- /dev/null +++ b/neethi/src/samples/test24.xml @@ -0,0 +1 @@ +wsp:Body() \ No newline at end of file diff --git a/neethi/src/samples/test25.xml b/neethi/src/samples/test25.xml new file mode 100644 index 0000000..378051d --- /dev/null +++ b/neethi/src/samples/test25.xml @@ -0,0 +1,7 @@ + + A + B + C + \ No newline at end of file diff --git a/neethi/src/samples/test3.xml b/neethi/src/samples/test3.xml new file mode 100644 index 0000000..a3bc427 --- /dev/null +++ b/neethi/src/samples/test3.xml @@ -0,0 +1,20 @@ + + + + + + sec:X509v3 + + + + + sec:X509v3 + + + + + sec:Kerberosv5TGT + + + + \ No newline at end of file diff --git a/neethi/src/samples/test4.xml b/neethi/src/samples/test4.xml new file mode 100644 index 0000000..a6af9f4 --- /dev/null +++ b/neethi/src/samples/test4.xml @@ -0,0 +1 @@ +sec:X509v3sec:X509v3 \ No newline at end of file diff --git a/neethi/src/samples/test5.xml b/neethi/src/samples/test5.xml new file mode 100644 index 0000000..7c72aff --- /dev/null +++ b/neethi/src/samples/test5.xml @@ -0,0 +1 @@ +sec:X509v3sec:X509v3sec:Kerberosv5TGT \ No newline at end of file diff --git a/neethi/src/samples/test6.xml b/neethi/src/samples/test6.xml new file mode 100644 index 0000000..4003b62 --- /dev/null +++ b/neethi/src/samples/test6.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/samples/test7.xml b/neethi/src/samples/test7.xml new file mode 100644 index 0000000..cee2f03 --- /dev/null +++ b/neethi/src/samples/test7.xml @@ -0,0 +1 @@ +sec:X509v3wsp:Body() \ No newline at end of file diff --git a/neethi/src/samples/test8.xml b/neethi/src/samples/test8.xml new file mode 100644 index 0000000..31d9377 --- /dev/null +++ b/neethi/src/samples/test8.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/neethi/src/samples/test9.xml b/neethi/src/samples/test9.xml new file mode 100644 index 0000000..9f57428 --- /dev/null +++ b/neethi/src/samples/test9.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/neethi/src/secpolicy/Makefile.am b/neethi/src/secpolicy/Makefile.am new file mode 100644 index 0000000..28fd650 --- /dev/null +++ b/neethi/src/secpolicy/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = model builder diff --git a/neethi/src/secpolicy/builder/Makefile.am b/neethi/src/secpolicy/builder/Makefile.am new file mode 100644 index 0000000..d189e16 --- /dev/null +++ b/neethi/src/secpolicy/builder/Makefile.am @@ -0,0 +1,25 @@ +TESTS = + +noinst_LTLIBRARIES = librp_builder.la + +librp_builder_la_SOURCES = algorithmsuite_builder.c \ + layout_builder.c \ + supporting_tokens_builder.c \ + transport_binding_builder.c username_token_builder.c \ + wss10_builder.c transport_token_builder.c \ + token_identifier.c https_token_builder.c rampart_config_builder.c \ + asymmetric_binding_builder.c x509_token_builder.c initiator_token_builder.c \ + recipient_token_builder.c signed_encrypted_parts_builder.c secpolicy_builder.c \ + symmetric_binding_builder.c protection_token_builder.c signature_token_builder.c \ + encryption_token_builder.c wss11_builder.c trust10_builder.c \ + bootstrap_policy_builder.c security_context_token_builder.c \ + issued_token_builder.c saml_token_builder.c + +librp_builder_la_LIBADD = ../../../../axiom/src/om/libaxis2_axiom.la \ + ../../../../util/src/libaxutil.la + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../include \ + -I ../../../../util/include \ + -I ../../../../axiom/include \ + -I ../../../../include diff --git a/neethi/src/secpolicy/builder/algorithmsuite_builder.c b/neethi/src/secpolicy/builder/algorithmsuite_builder.c new file mode 100644 index 0000000..3f42baf --- /dev/null +++ b/neethi/src/secpolicy/builder/algorithmsuite_builder.c @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_algorithmsuite_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_algorithmsuite_t *algorithmsuite = NULL; + axiom_node_t *child_node = NULL; + axiom_node_t *algo_node = NULL; + axiom_element_t *algo_element = NULL; + neethi_assertion_t *assertion = NULL; + + algorithmsuite = rp_algorithmsuite_create(env); + + child_node = axiom_node_get_first_element(node, env); + + if(child_node) + { + algo_node = axiom_node_get_first_element(child_node, env); + if(!algo_node) + { + return NULL; + } + } + else + { + return NULL; + } + + if(axiom_node_get_node_type(algo_node, env) == AXIOM_ELEMENT) + { + algo_element = (axiom_element_t *)axiom_node_get_data_element(algo_node, env); + if(algo_element) + { + axis2_status_t status = AXIS2_FAILURE; + axis2_char_t *algosuite_string = NULL; + + algosuite_string = axiom_element_get_localname(algo_element, env); + if(!algosuite_string) + { + return NULL; + } + status = rp_algorithmsuite_set_algosuite(algorithmsuite, env, algosuite_string); + if(AXIS2_FAILURE == status) + { + return NULL; + } + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_algorithmsuite_free, algorithmsuite, + ASSERTION_TYPE_ALGORITHM_SUITE); + return assertion; + } + else + return NULL; + } + else + return NULL; +} diff --git a/neethi/src/secpolicy/builder/asymmetric_binding_builder.c b/neethi/src/secpolicy/builder/asymmetric_binding_builder.c new file mode 100644 index 0000000..3a2f889 --- /dev/null +++ b/neethi/src/secpolicy/builder/asymmetric_binding_builder.c @@ -0,0 +1,234 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +asymmetric_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_asymmetric_binding_t *asymmetric_binding); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_asymmetric_binding_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_asymmetric_binding_t *asymmetric_binding = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + asymmetric_binding = rp_asymmetric_binding_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + neethi_policy_free(policy, env); + policy = NULL; + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + asymmetric_binding_process_alternatives(env, all, asymmetric_binding); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_asymmetric_binding_free, asymmetric_binding, + ASSERTION_TYPE_ASSYMMETRIC_BINDING); + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +asymmetric_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_asymmetric_binding_t * asymmetric_binding) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + rp_binding_commons_t *commons = NULL; + rp_symmetric_asymmetric_binding_commons_t *as_commons = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + commons = rp_binding_commons_create(env); + as_commons = rp_symmetric_asymmetric_binding_commons_create(env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_INITIATOR_TOKEN) + { + rp_property_t *initiator_token = NULL; + initiator_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(initiator_token) + { + rp_asymmetric_binding_set_initiator_token(asymmetric_binding, env, initiator_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_RECIPIENT_TOKEN) + { + rp_property_t *recipient_token = NULL; + recipient_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(recipient_token) + { + rp_asymmetric_binding_set_recipient_token(asymmetric_binding, env, recipient_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ALGORITHM_SUITE) + { + rp_algorithmsuite_t *algorithmsuite = NULL; + algorithmsuite = (rp_algorithmsuite_t *)neethi_assertion_get_value(assertion, env); + if(algorithmsuite) + { + rp_binding_commons_set_algorithmsuite(commons, env, algorithmsuite); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_INCLUDE_TIMESTAMP) + { + rp_binding_commons_set_include_timestamp(commons, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_LAYOUT) + { + rp_layout_t *layout = NULL; + layout = (rp_layout_t *)neethi_assertion_get_value(assertion, env); + if(layout) + { + rp_binding_commons_set_layout(commons, env, layout); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ENCRYPT_BEFORE_SIGNING) + { + rp_symmetric_asymmetric_binding_commons_set_protection_order(as_commons, env, + RP_ENCRYPT_BEFORE_SIGNING); + } + else if(type == ASSERTION_TYPE_SIGN_BEFORE_ENCRYPTING) + { + rp_symmetric_asymmetric_binding_commons_set_protection_order(as_commons, env, + RP_SIGN_BEFORE_ENCRYPTING); + } + else if(type == ASSERTION_TYPE_ENCRYPT_SIGNATURE) + { + rp_symmetric_asymmetric_binding_commons_set_signature_protection(as_commons, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_PROTECT_TOKENS) + { + rp_symmetric_asymmetric_binding_commons_set_token_protection(as_commons, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_ONLY_SIGN_ENTIRE_HEADERS_AND_BODY) + { + rp_symmetric_asymmetric_binding_commons_set_entire_headers_and_body_signatures( + as_commons, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_SUPPORTING_TOKENS) + { + rp_supporting_tokens_t *supporting_tokens = NULL; + supporting_tokens + = (rp_supporting_tokens_t *)neethi_assertion_get_value(assertion, env); + if(supporting_tokens) + { + rp_property_type_t type; + type = rp_supporting_tokens_get_type(supporting_tokens, env); + if(type == RP_PROPERTY_SIGNED_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else if(type == RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + rp_symmetric_asymmetric_binding_commons_set_binding_commons(as_commons, env, commons); + rp_asymmetric_binding_set_symmetric_asymmetric_binding_commons(asymmetric_binding, env, + as_commons); + + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/bootstrap_policy_builder.c b/neethi/src/secpolicy/builder/bootstrap_policy_builder.c new file mode 100644 index 0000000..df8c23e --- /dev/null +++ b/neethi/src/secpolicy/builder/bootstrap_policy_builder.c @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_bootstrap_policy_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + neethi_assertion_t *assertion = NULL; + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + assertion = neethi_assertion_create_with_args(env, NULL, /*this policy should not be deleted*/ + policy, ASSERTION_TYPE_BOOTSTRAP_POLICY); + return assertion; + } + else + return NULL; + } + else + return NULL; +} diff --git a/neethi/src/secpolicy/builder/encryption_token_builder.c b/neethi/src/secpolicy/builder/encryption_token_builder.c new file mode 100644 index 0000000..5896ac3 --- /dev/null +++ b/neethi/src/secpolicy/builder/encryption_token_builder.c @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +encryption_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *encryption_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_encryption_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_property_t *encryption_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + encryption_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + encryption_token_process_alternatives(env, all, encryption_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, encryption_token, + ASSERTION_TYPE_ENCRYPTION_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +encryption_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *encryption_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)neethi_assertion_get_value(assertion, env); + if(x509_token) + { + rp_property_set_value(encryption_token, env, x509_token, RP_PROPERTY_X509_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + rp_issued_token_t *issued_token = NULL; + issued_token = (rp_issued_token_t *)neethi_assertion_get_value(assertion, env); + if(issued_token) + { + rp_property_set_value(encryption_token, env, issued_token, + RP_PROPERTY_ISSUED_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + rp_saml_token_t *saml_token = NULL; + saml_token = (rp_saml_token_t *)neethi_assertion_get_value(assertion, env); + if(saml_token) + { + rp_property_set_value(encryption_token, env, saml_token, RP_PROPERTY_SAML_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_t *security_context_token = NULL; + security_context_token = (rp_security_context_token_t *)neethi_assertion_get_value( + assertion, env); + + if(security_context_token) + { + rp_property_set_value(encryption_token, env, security_context_token, + RP_PROPERTY_SECURITY_CONTEXT_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/https_token_builder.c b/neethi/src/secpolicy/builder/https_token_builder.c new file mode 100644 index 0000000..9406d19 --- /dev/null +++ b/neethi/src/secpolicy/builder/https_token_builder.c @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_https_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_https_token_t *https_token = NULL; + neethi_assertion_t *assertion = NULL; + axis2_char_t *value = NULL; + + https_token = rp_https_token_create(env); + + value = axiom_element_get_attribute_value_by_name(element, env, RP_REQUIRE_CLIENT_CERTIFICATE); + + if(value) + { + if(axutil_strcmp(value, "true") == 0) + { + rp_https_token_set_require_client_certificate(https_token, env, AXIS2_TRUE); + } + else if(axutil_strcmp(value, "false") == 0) + { + rp_https_token_set_require_client_certificate(https_token, env, AXIS2_FALSE); + } + else + return NULL; + } + + assertion = neethi_assertion_create_with_args(env, (AXIS2_FREE_VOID_ARG)rp_https_token_free, + https_token, ASSERTION_TYPE_HTTPS_TOKEN); + return assertion; +} diff --git a/neethi/src/secpolicy/builder/initiator_token_builder.c b/neethi/src/secpolicy/builder/initiator_token_builder.c new file mode 100644 index 0000000..28b6497 --- /dev/null +++ b/neethi/src/secpolicy/builder/initiator_token_builder.c @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +initiator_token_process_alternatives( + const axutil_env_t * env, + neethi_all_t * all, + rp_property_t * initiator_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_initiator_token_builder_build( + const axutil_env_t * env, + axiom_node_t * node, + axiom_element_t * element) +{ + rp_property_t *initiator_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + initiator_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + initiator_token_process_alternatives(env, all, initiator_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, initiator_token, + ASSERTION_TYPE_INITIATOR_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +initiator_token_process_alternatives( + const axutil_env_t * env, + neethi_all_t * all, + rp_property_t * initiator_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)neethi_assertion_get_value(assertion, env); + if(x509_token) + { + rp_property_set_value(initiator_token, env, x509_token, RP_PROPERTY_X509_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/issued_token_builder.c b/neethi/src/secpolicy/builder/issued_token_builder.c new file mode 100644 index 0000000..2cfc09f --- /dev/null +++ b/neethi/src/secpolicy/builder/issued_token_builder.c @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +AXIS2_EXTERN neethi_assertion_t * AXIS2_CALL +rp_issued_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_issued_token_t *issued_token = NULL; + neethi_policy_t *policy = NULL; + neethi_policy_t *normalized_policy = NULL; + neethi_all_t *all = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + axis2_char_t *inclusion_value = NULL; + axutil_qname_t *qname = NULL; + axiom_node_t *issuer_node = NULL; + axiom_element_t *issuer_ele = NULL; + axiom_element_t *issuer_first_child_ele = NULL; + axiom_node_t *issuer_first_child_node = NULL; + axiom_node_t *req_sec_tok_template_node = NULL; + axiom_element_t *req_sec_tok_template_ele = NULL; + axiom_node_t *policy_node = NULL; + axiom_element_t *policy_ele = NULL; + neethi_assertion_t *assertion = NULL; + + issued_token = rp_issued_token_create(env); + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_11, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + + if(!inclusion_value) + { + /* we can try whether WS-SP1.2 specific inclusion value */ + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_12, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + } + + if(inclusion_value) + { + rp_issued_token_set_inclusion(issued_token, env, inclusion_value); + } + + qname = axutil_qname_create(env, RP_ISSUER, RP_SP_NS_11, RP_SP_PREFIX); + issuer_ele = axiom_element_get_first_child_with_qname(element, env, qname, node, &issuer_node); + if(issuer_ele) + { + issuer_first_child_ele = axiom_element_get_first_element(issuer_ele, env, issuer_node, + &issuer_first_child_node); + if(issuer_first_child_ele) + { + rp_issued_token_set_issuer_epr(issued_token, env, issuer_first_child_node); + } + } + axutil_qname_free(qname, env); + qname = NULL; + + qname = axutil_qname_create(env, RP_REQUEST_SEC_TOKEN_TEMPLATE, RP_SP_NS_11, RP_SP_PREFIX); + req_sec_tok_template_ele = axiom_element_get_first_child_with_qname(element, env, qname, node, + &req_sec_tok_template_node); + if(req_sec_tok_template_ele) + { + rp_issued_token_set_requested_sec_token_template(issued_token, env, + req_sec_tok_template_node); + } + else + { + return NULL; + } + + axutil_qname_free(qname, env); + qname = NULL; + + qname = axutil_qname_create(env, RP_POLICY, RP_POLICY_NS, RP_POLICY_PREFIX); + policy_ele = axiom_element_get_first_child_with_qname(element, env, qname, node, &policy_node); + if(policy_ele) + { + policy = neethi_engine_get_policy(env, policy_node, policy_ele); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + if(AXIS2_FAILURE == rp_issued_token_builder_process_alternatives(env, all, issued_token)) + return NULL; + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_issued_token_free, issued_token, ASSERTION_TYPE_ISSUED_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, issued_token, ASSERTION_TYPE_ISSUED_TOKEN); + + return assertion; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_builder_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_issued_token_t *issued_token) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC10) + { + rp_issued_token_set_derivedkeys(issued_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_EXTERNAL_REFERENCE) + { + rp_issued_token_set_require_exernal_reference(issued_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_INTERNAL_REFERENCE) + { + rp_issued_token_set_require_internal_reference(issued_token, env, AXIS2_TRUE); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + diff --git a/neethi/src/secpolicy/builder/layout_builder.c b/neethi/src/secpolicy/builder/layout_builder.c new file mode 100644 index 0000000..9be9ad9 --- /dev/null +++ b/neethi/src/secpolicy/builder/layout_builder.c @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_layout_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_layout_t *layout = NULL; + axiom_node_t *child_node = NULL; + axiom_node_t *layout_node = NULL; + axiom_element_t *layout_element = NULL; + neethi_assertion_t *assertion = NULL; + + layout = rp_layout_create(env); + + child_node = axiom_node_get_first_element(node, env); + + if(child_node) + { + layout_node = axiom_node_get_first_element(child_node, env); + if(!layout_node) + { + return NULL; + } + } + else + { + return NULL; + } + + if(axiom_node_get_node_type(layout_node, env) == AXIOM_ELEMENT) + { + layout_element = (axiom_element_t *)axiom_node_get_data_element(layout_node, env); + if(layout_element) + { + axis2_char_t *local_name = NULL; + + local_name = axiom_element_get_localname(layout_element, env); + if(!local_name) + return NULL; + rp_layout_set_value(layout, env, local_name); + assertion = neethi_assertion_create_with_args(env, (AXIS2_FREE_VOID_ARG)rp_layout_free, + layout, ASSERTION_TYPE_LAYOUT); + return assertion; + } + else + return NULL; + } + else + return NULL; +} diff --git a/neethi/src/secpolicy/builder/protection_token_builder.c b/neethi/src/secpolicy/builder/protection_token_builder.c new file mode 100644 index 0000000..8ea02f2 --- /dev/null +++ b/neethi/src/secpolicy/builder/protection_token_builder.c @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +protection_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *protection_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_protection_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_property_t *protection_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + protection_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + protection_token_process_alternatives(env, all, protection_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, protection_token, + ASSERTION_TYPE_PROTECTION_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +protection_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *protection_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)neethi_assertion_get_value(assertion, env); + if(x509_token) + { + rp_property_set_value(protection_token, env, x509_token, RP_PROPERTY_X509_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + rp_issued_token_t *issued_token = NULL; + issued_token = (rp_issued_token_t *)neethi_assertion_get_value(assertion, env); + if(issued_token) + { + rp_property_set_value(protection_token, env, issued_token, + RP_PROPERTY_ISSUED_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + rp_saml_token_t *saml_token = NULL; + saml_token = (rp_saml_token_t *)neethi_assertion_get_value(assertion, env); + if(saml_token) + { + rp_property_set_value(protection_token, env, saml_token, RP_PROPERTY_SAML_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_t *security_context_token = NULL; + security_context_token = (rp_security_context_token_t *)neethi_assertion_get_value( + assertion, env); + + if(security_context_token) + { + rp_property_set_value(protection_token, env, security_context_token, + RP_PROPERTY_SECURITY_CONTEXT_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/rampart_config_builder.c b/neethi/src/secpolicy/builder/rampart_config_builder.c new file mode 100644 index 0000000..1c569b3 --- /dev/null +++ b/neethi/src/secpolicy/builder/rampart_config_builder.c @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +rp_rampart_config_builder_populate( + const axutil_env_t *env, + rp_rampart_config_t *rampart_config, + axiom_node_t *node, + axiom_element_t *element, + axis2_char_t *local_name); + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_rampart_config_builder_build( + const axutil_env_t *env, + axiom_node_t *config, + axiom_element_t *config_ele) +{ + rp_rampart_config_t *rampart_config = NULL; + axis2_status_t status = AXIS2_SUCCESS; + axiom_children_iterator_t *children_iter = NULL; + neethi_assertion_t *assertion = NULL; + + rampart_config = rp_rampart_config_create(env); + if(!rampart_config) + { + return NULL; + } + + children_iter = axiom_element_get_children(config_ele, env, config); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + if(ele) + { + local_name = axiom_element_get_localname(ele, env); + if(local_name) + { + status = rp_rampart_config_builder_populate(env, rampart_config, node, + ele, local_name); + if(status != AXIS2_SUCCESS) + { + return NULL; + } + } + } + } + } + } + } + assertion = neethi_assertion_create_with_args(env, (AXIS2_FREE_VOID_ARG)rp_rampart_config_free, + rampart_config, ASSERTION_TYPE_RAMPART_CONFIG); + return assertion; +} + +axis2_status_t AXIS2_CALL +rp_rampart_config_builder_populate( + const axutil_env_t *env, + rp_rampart_config_t *rampart_config, + axiom_node_t *node, + axiom_element_t *element, + axis2_char_t *local_name) +{ + axis2_char_t *ns = NULL; + axutil_qname_t *node_qname = NULL; + + node_qname = axiom_element_get_qname(element, env, node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get qname from element %s.", + local_name); + return AXIS2_FAILURE; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get namespace from element %s.", + local_name); + return AXIS2_FAILURE; + } + + if(!axutil_strcmp(ns, RP_RAMPART_NS)) + { + if(!axutil_strcmp(local_name, RP_USER)) + { + axis2_char_t *user = NULL; + user = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_user(rampart_config, env, user); + } + else if(!axutil_strcmp(local_name, RP_ENCRYPTION_USER)) + { + axis2_char_t *encryption_user = NULL; + encryption_user = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_encryption_user(rampart_config, env, encryption_user); + } + else if(!axutil_strcmp(local_name, RP_PASSWORD_CALLBACK_CLASS)) + { + axis2_char_t *password_callback_class = NULL; + password_callback_class = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_password_callback_class(rampart_config, env, + password_callback_class); + } + else if(!axutil_strcmp(local_name, RP_AUTHN_MODULE_NAME)) + { + axis2_char_t *authenticate_module = NULL; + authenticate_module = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_authenticate_module(rampart_config, env, + authenticate_module); + } + else if(!axutil_strcmp(local_name, RP_RD_MODULE)) + { + axis2_char_t *replay_detector = NULL; + replay_detector = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_replay_detector(rampart_config, env, replay_detector); + } + else if(!axutil_strcmp(local_name, RP_SCT_MODULE)) + { + axis2_char_t *sct_module = NULL; + sct_module = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_sct_provider(rampart_config, env, sct_module); + } + else if(!axutil_strcmp(local_name, RP_PASSWORD_TYPE)) + { + axis2_char_t *password_type = NULL; + password_type = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_password_type(rampart_config, env, password_type); + } + else if(!axutil_strcmp(local_name, RP_CERTIFICATE)) + { + axis2_char_t *certificate_file = NULL; + certificate_file = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_certificate_file(rampart_config, env, certificate_file); + } + else if(!axutil_strcmp(local_name, RP_RECEIVER_CERTIFICATE)) + { + axis2_char_t *receiver_certificate_file = NULL; + receiver_certificate_file = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_receiver_certificate_file(rampart_config, env, + receiver_certificate_file); + } + else if(!axutil_strcmp(local_name, RP_PRIVATE_KEY)) + { + axis2_char_t *private_key_file = NULL; + private_key_file = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_private_key_file(rampart_config, env, private_key_file); + } + else if(!axutil_strcmp(local_name, RP_PKCS12_KEY_STORE)) + { + axis2_char_t *pkcs12_key_store = NULL; + pkcs12_key_store = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_pkcs12_file(rampart_config, env, pkcs12_key_store); + } + else if(!axutil_strcmp(local_name, RP_TIME_TO_LIVE)) + { + axis2_char_t *time_to_live = NULL; + time_to_live = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_time_to_live(rampart_config, env, time_to_live); + } + else if(!axutil_strcmp(local_name, RP_CLOCK_SKEW_BUFFER)) + { + axis2_char_t *clock_skew_buffer = NULL; + clock_skew_buffer = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_clock_skew_buffer(rampart_config, env, clock_skew_buffer); + } + else if(!axutil_strcmp(local_name, RP_NEED_MILLISECOND_PRECISION)) + { + axis2_char_t *need_ms_precision = NULL; + need_ms_precision = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_need_millisecond_precision(rampart_config, env, + need_ms_precision); + } + else if(!axutil_strcmp(local_name, RP_RD)) + { + axis2_char_t *rd_val = NULL; + rd_val = axiom_element_get_text(element, env, node); + return rp_rampart_config_set_rd_val(rampart_config, env, rd_val); + } + } + + /* either the assertion or the namespace is not identified */ + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Unknown Assertion %s with namespace %s", + local_name, ns); + return AXIS2_FAILURE; + +} diff --git a/neethi/src/secpolicy/builder/recipient_token_builder.c b/neethi/src/secpolicy/builder/recipient_token_builder.c new file mode 100644 index 0000000..d29537d --- /dev/null +++ b/neethi/src/secpolicy/builder/recipient_token_builder.c @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +recipient_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *recipient_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_recipient_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_property_t *recipient_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + recipient_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + recipient_token_process_alternatives(env, all, recipient_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, recipient_token, + ASSERTION_TYPE_RECIPIENT_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +recipient_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *recipient_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)neethi_assertion_get_value(assertion, env); + if(x509_token) + { + rp_property_set_value(recipient_token, env, x509_token, RP_PROPERTY_X509_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/saml_token_builder.c b/neethi/src/secpolicy/builder/saml_token_builder.c new file mode 100644 index 0000000..6550d80 --- /dev/null +++ b/neethi/src/secpolicy/builder/saml_token_builder.c @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +axis2_status_t AXIS2_CALL +saml_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_saml_token_t *saml_token); + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_saml_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_saml_token_t *saml_token = NULL; + axis2_char_t *inclusion_value = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axutil_qname_t *qname = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + saml_token = rp_saml_token_create(env); + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_11, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + + if(!inclusion_value) + { + /* we can try whether WS-SP1.2 specific inclusion value */ + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_12, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + } + + rp_saml_token_set_inclusion(saml_token, env, inclusion_value); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, saml_token, ASSERTION_TYPE_SAML_TOKEN); + return assertion; + } + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + saml_token_process_alternatives(env, all, saml_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_saml_token_free, saml_token, ASSERTION_TYPE_SAML_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +saml_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_saml_token_t *saml_token) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC10) + { + rp_saml_token_set_derivedkeys(saml_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_KEY_IDENTIFIRE_REFERENCE) + { + rp_saml_token_set_require_key_identifier_reference(saml_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_WSS_SAML_V10_TOKEN_V10) + { + rp_saml_token_set_token_version_and_type(saml_token, env, RP_WSS_SAML_V10_TOKEN_V10); + } + else if(type == ASSERTION_TYPE_WSS_SAML_V10_TOKEN_V11) + { + rp_saml_token_set_token_version_and_type(saml_token, env, RP_WSS_SAML_V10_TOKEN_V11); + } + else if(type == ASSERTION_TYPE_WSS_SAML_V11_TOKEN_V10) + { + rp_saml_token_set_token_version_and_type(saml_token, env, RP_WSS_SAML_V11_TOKEN_V10); + } + else if(type == ASSERTION_TYPE_WSS_SAML_V11_TOKEN_V11) + { + rp_saml_token_set_token_version_and_type(saml_token, env, RP_WSS_SAML_V11_TOKEN_V11); + } + else if(type == ASSERTION_TYPE_WSS_SAML_V20_TOKEN_V11) + { + rp_saml_token_set_token_version_and_type(saml_token, env, RP_WSS_SAML_V20_TOKEN_V11); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + diff --git a/neethi/src/secpolicy/builder/secpolicy_builder.c b/neethi/src/secpolicy/builder/secpolicy_builder.c new file mode 100644 index 0000000..8548403 --- /dev/null +++ b/neethi/src/secpolicy/builder/secpolicy_builder.c @@ -0,0 +1,241 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +secpolicy_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_secpolicy_t *secpolicy); + +/***********************************/ + +AXIS2_EXTERN rp_secpolicy_t *AXIS2_CALL +rp_secpolicy_builder_build( + const axutil_env_t *env, + neethi_policy_t *policy) +{ + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + rp_secpolicy_t *secpolicy = NULL; + + secpolicy = rp_secpolicy_create(env); + + alternatives = neethi_policy_get_alternatives(policy, env); + + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + + if(secpolicy_process_alternatives(env, all, secpolicy) == AXIS2_FAILURE) + { + return NULL; + } + return secpolicy; +} + +axis2_status_t AXIS2_CALL +secpolicy_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_secpolicy_t *secpolicy) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_TRANSPORT_BINDING) + { + rp_property_t *binding = NULL; + rp_transport_binding_t *transport_binding = NULL; + + transport_binding = (rp_transport_binding_t *)neethi_assertion_get_value(assertion, + env); + if(!transport_binding) + { + return AXIS2_FAILURE; + } + binding = rp_property_create(env); + rp_property_set_value(binding, env, transport_binding, + RP_PROPERTY_TRANSPORT_BINDING); + rp_secpolicy_set_binding(secpolicy, env, binding); + } + else if(type == ASSERTION_TYPE_ASSYMMETRIC_BINDING) + { + rp_property_t *binding = NULL; + rp_asymmetric_binding_t *asymmetric_binding = NULL; + + asymmetric_binding = (rp_asymmetric_binding_t *)neethi_assertion_get_value( + assertion, env); + if(!asymmetric_binding) + { + return AXIS2_FAILURE; + } + binding = rp_property_create(env); + rp_property_set_value(binding, env, asymmetric_binding, + RP_PROPERTY_ASYMMETRIC_BINDING); + rp_secpolicy_set_binding(secpolicy, env, binding); + } + else if(type == ASSERTION_TYPE_SYMMETRIC_BINDING) + { + rp_property_t *binding = NULL; + rp_symmetric_binding_t *symmetric_binding = NULL; + + symmetric_binding = (rp_symmetric_binding_t *)neethi_assertion_get_value(assertion, + env); + if(!symmetric_binding) + { + return AXIS2_FAILURE; + } + binding = rp_property_create(env); + rp_property_set_value(binding, env, symmetric_binding, + RP_PROPERTY_SYMMETRIC_BINDING); + rp_secpolicy_set_binding(secpolicy, env, binding); + } + else if(type == ASSERTION_TYPE_SUPPORTING_TOKENS) + { + rp_supporting_tokens_t *supporting_tokens = NULL; + supporting_tokens = (rp_supporting_tokens_t *)neethi_assertion_get_value(assertion, + env); + if(supporting_tokens) + { + rp_property_type_t type; + type = rp_supporting_tokens_get_type(supporting_tokens, env); + if(type == RP_PROPERTY_SIGNED_SUPPORTING_TOKEN) + { + rp_secpolicy_set_signed_supporting_tokens(secpolicy, env, supporting_tokens); + } + else if(type == RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN) + { + rp_secpolicy_set_signed_endorsing_supporting_tokens(secpolicy, env, + supporting_tokens); + } + else if(type == RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN) + { + rp_secpolicy_set_supporting_tokens(secpolicy, env, supporting_tokens); + } + else if(type == RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN) + { + rp_secpolicy_set_endorsing_supporting_tokens(secpolicy, env, + supporting_tokens); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_WSS10) + { + rp_wss10_t *wss10 = NULL; + rp_property_t *wss = NULL; + wss10 = (rp_wss10_t *)neethi_assertion_get_value(assertion, env); + if(!wss10) + { + return AXIS2_FAILURE; + } + wss = rp_property_create(env); + rp_property_set_value(wss, env, wss10, RP_PROPERTY_WSS10); + rp_secpolicy_set_wss(secpolicy, env, wss); + } + else if(type == ASSERTION_TYPE_WSS11) + { + rp_wss11_t *wss11 = NULL; + rp_property_t *wss = NULL; + wss11 = (rp_wss11_t *)neethi_assertion_get_value(assertion, env); + if(!wss11) + { + return AXIS2_FAILURE; + } + wss = rp_property_create(env); + rp_property_set_value(wss, env, wss11, RP_PROPERTY_WSS11); + rp_secpolicy_set_wss(secpolicy, env, wss); + } + else if(type == ASSERTION_TYPE_TRUST10) + { + rp_trust10_t *trust10 = NULL; + trust10 = (rp_trust10_t *)neethi_assertion_get_value(assertion, env); + if(!trust10) + { + return AXIS2_FAILURE; + } + rp_secpolicy_set_trust10(secpolicy, env, trust10); + } + else if(type == ASSERTION_TYPE_SIGNED_ENCRYPTED_PARTS) + { + rp_signed_encrypted_parts_t *signed_encrypted_parts = NULL; + signed_encrypted_parts = (rp_signed_encrypted_parts_t *)neethi_assertion_get_value( + assertion, env); + if(signed_encrypted_parts) + { + if(rp_signed_encrypted_parts_get_signedparts(signed_encrypted_parts, env)) + { + rp_secpolicy_set_signed_parts(secpolicy, env, signed_encrypted_parts); + } + else + { + rp_secpolicy_set_encrypted_parts(secpolicy, env, signed_encrypted_parts); + } + } + else + return AXIS2_FAILURE; + + } + else if(type == ASSERTION_TYPE_RAMPART_CONFIG) + { + rp_rampart_config_t *rampart_config = NULL; + rampart_config = (rp_rampart_config_t *)neethi_assertion_get_value(assertion, env); + if(!rampart_config) + { + return AXIS2_FAILURE; + } + rp_secpolicy_set_rampart_config(secpolicy, env, rampart_config); + } + else + { + continue; + } + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/security_context_token_builder.c b/neethi/src/secpolicy/builder/security_context_token_builder.c new file mode 100644 index 0000000..b4ad8e8 --- /dev/null +++ b/neethi/src/secpolicy/builder/security_context_token_builder.c @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +security_context_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_security_context_token_t * security_context_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_security_context_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element, + axis2_char_t *sp_ns_uri, + axis2_bool_t is_secure_conversation_token) +{ + rp_security_context_token_t *security_context_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axiom_children_iterator_t *children_iter = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axis2_char_t *inclusion_value = NULL; + axutil_qname_t *qname = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + security_context_token = rp_security_context_token_create(env); + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, sp_ns_uri, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + + rp_security_context_token_set_inclusion(security_context_token, env, inclusion_value); + rp_security_context_token_set_is_secure_conversation_token(security_context_token, env, + is_secure_conversation_token); + + if(!axutil_strcmp(sp_ns_uri, RP_SP_NS_11)) + { + rp_security_context_token_set_sc10_security_context_token(security_context_token, env, + AXIS2_TRUE); + } + else + { + rp_security_context_token_set_sc10_security_context_token(security_context_token, env, + AXIS2_FALSE); + } + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + children_iter = axiom_element_get_children(element, env, node); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + child_node = axiom_children_iterator_next(children_iter, env); + if(child_node) + { + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + axis2_char_t *localname = NULL; + localname = axiom_element_get_localname(child_element, env); + if(axutil_strcmp(localname, RP_ISSUER) == 0) + { + axis2_char_t *ns = NULL; + axutil_qname_t *node_qname = NULL; + + node_qname = axiom_element_get_qname(child_element, env, child_node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get qname from element %s.", localname); + return NULL; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot get namespace from element %s.", localname); + return NULL; + } + if(!(axutil_strcmp(ns, RP_SP_NS_11) && axutil_strcmp(ns, RP_SP_NS_12))) + { + axis2_char_t *issuer = NULL; + issuer = axiom_element_get_text(child_element, env, child_node); + rp_security_context_token_set_issuer(security_context_token, env, + issuer); + } + else + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Unknown Assertion %s with namespace %s", localname, + ns); + return NULL; + } + } + else + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, + policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, + env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + security_context_token_process_alternatives(env, all, + security_context_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_security_context_token_free, + security_context_token, ASSERTION_TYPE_SECURITY_CONTEXT_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + } + } + } + } + } + } + return assertion; +} + +axis2_status_t AXIS2_CALL +security_context_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_security_context_token_t * security_context_token) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC10) + { + rp_security_context_token_set_derivedkey(security_context_token, env, DERIVEKEY_NEEDED); + rp_security_context_token_set_derivedkey_version(security_context_token, env, + DERIVEKEY_VERSION_SC10); + } + else if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC13) + { + rp_security_context_token_set_derivedkey(security_context_token, env, DERIVEKEY_NEEDED); + rp_security_context_token_set_derivedkey_version(security_context_token, env, + DERIVEKEY_VERSION_SC13); + } + else if(type == ASSERTION_TYPE_REQUIRE_EXTERNAL_URI) + { + rp_security_context_token_set_require_external_uri_ref(security_context_token, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_SC10_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_set_sc10_security_context_token(security_context_token, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_SC13_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_set_sc10_security_context_token(security_context_token, env, + AXIS2_FALSE); + } + else if(type == ASSERTION_TYPE_ISSUER) + { + axis2_char_t *issuer = NULL; + issuer = (axis2_char_t *)neethi_assertion_get_value(assertion, env); + rp_security_context_token_set_issuer(security_context_token, env, issuer); + } + else if(type == ASSERTION_TYPE_BOOTSTRAP_POLICY) + { + neethi_policy_t *bootstrap_policy = NULL; + bootstrap_policy = (neethi_policy_t *)neethi_assertion_get_value(assertion, env); + rp_security_context_token_set_bootstrap_policy(security_context_token, env, + bootstrap_policy); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/signature_token_builder.c b/neethi/src/secpolicy/builder/signature_token_builder.c new file mode 100644 index 0000000..0c1c0c7 --- /dev/null +++ b/neethi/src/secpolicy/builder/signature_token_builder.c @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +signature_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *signature_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_signature_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_property_t *signature_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + signature_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + signature_token_process_alternatives(env, all, signature_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, signature_token, + ASSERTION_TYPE_SIGNATURE_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +signature_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_property_t *signature_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)neethi_assertion_get_value(assertion, env); + if(x509_token) + { + rp_property_set_value(signature_token, env, x509_token, RP_PROPERTY_X509_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + rp_issued_token_t *issued_token = NULL; + issued_token = (rp_issued_token_t *)neethi_assertion_get_value(assertion, env); + if(issued_token) + { + rp_property_set_value(signature_token, env, issued_token, + RP_PROPERTY_ISSUED_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + rp_saml_token_t *saml_token = NULL; + saml_token = (rp_saml_token_t *)neethi_assertion_get_value(assertion, env); + if(saml_token) + { + rp_property_set_value(signature_token, env, saml_token, RP_PROPERTY_SAML_TOKEN); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_t *security_context_token = NULL; + security_context_token = (rp_security_context_token_t *)neethi_assertion_get_value( + assertion, env); + + if(security_context_token) + { + rp_property_set_value(signature_token, env, security_context_token, + RP_PROPERTY_SECURITY_CONTEXT_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/signed_encrypted_parts_builder.c b/neethi/src/secpolicy/builder/signed_encrypted_parts_builder.c new file mode 100644 index 0000000..be5008e --- /dev/null +++ b/neethi/src/secpolicy/builder/signed_encrypted_parts_builder.c @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +static rp_header_t *AXIS2_CALL +rp_signed_encrypted_parts_builder_build_header( + axiom_element_t *element, + const axutil_env_t *env); + +static axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_builder_set_properties( + axiom_node_t *node, + axiom_element_t *element, + axis2_char_t *local_name, + rp_signed_encrypted_parts_t *signed_encrypted_parts, + const axutil_env_t *env); + +/** + * Builts EncryptedParts or SignedParts assertion + * @param env Pointer to environment struct + * @param node Assertion node + * @param element Assertion element + * @param is_signed boolean showing whether signing or encryption + * @returns neethi assertion created. NULL if failure. + */ +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_signed_encrypted_parts_builder_build( + const axutil_env_t *env, + axiom_node_t *parts, + axiom_element_t *parts_ele, + axis2_bool_t is_signed) +{ + rp_signed_encrypted_parts_t *signed_encrypted_parts = NULL; + axiom_children_iterator_t *children_iter = NULL; + neethi_assertion_t *assertion = NULL; + axis2_status_t status = AXIS2_SUCCESS; + + signed_encrypted_parts = rp_signed_encrypted_parts_create(env); + if(!signed_encrypted_parts) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot create signed_encrypted_parts."); + return NULL; + } + + rp_signed_encrypted_parts_set_signedparts(signed_encrypted_parts, env, is_signed); + + children_iter = axiom_element_get_children(parts_ele, env, parts); + if(children_iter) + { + while(axiom_children_iterator_has_next(children_iter, env)) + { + axiom_node_t *node = NULL; + axiom_element_t *ele = NULL; + axis2_char_t *local_name = NULL; + node = axiom_children_iterator_next(children_iter, env); + if(node) + { + if(axiom_node_get_node_type(node, env) == AXIOM_ELEMENT) + { + ele = (axiom_element_t *)axiom_node_get_data_element(node, env); + if(ele) + { + local_name = axiom_element_get_localname(ele, env); + if(local_name) + { + status = rp_signed_encrypted_parts_builder_set_properties(node, ele, + local_name, signed_encrypted_parts, env); + if(status != AXIS2_SUCCESS) + { + rp_signed_encrypted_parts_free(signed_encrypted_parts, env); + signed_encrypted_parts = NULL; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot create signed_encrypted_parts. " + "Error in processing child element %s", local_name); + return NULL; + } + } + } + } + } + } + } + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_signed_encrypted_parts_free, signed_encrypted_parts, + ASSERTION_TYPE_SIGNED_ENCRYPTED_PARTS); + return assertion; +} + +static axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_builder_set_properties( + axiom_node_t *node, + axiom_element_t *element, + axis2_char_t *local_name, + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t *env) +{ + axis2_char_t *ns = NULL; + axutil_qname_t *node_qname = NULL; + + node_qname = axiom_element_get_qname(element, env, node); + if(!node_qname) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get qname from element %s.", + local_name); + return AXIS2_FAILURE; + } + + ns = axutil_qname_get_uri(node_qname, env); + if(!ns) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Cannot get namespace from element %s.", + local_name); + return AXIS2_FAILURE; + } + + /* process assertions common for WS-SecPolicy 1.1 and 1.2 */ + if(!(axutil_strcmp(ns, RP_SP_NS_11) && axutil_strcmp(ns, RP_SP_NS_12))) + { + /* this assertion is in WS-SecurityPolicy namespace */ + if(!strcmp(local_name, RP_BODY)) + { + rp_signed_encrypted_parts_set_body(signed_encrypted_parts, env, AXIS2_TRUE); + return AXIS2_SUCCESS; + } + else if(!strcmp(local_name, RP_HEADER)) + { + rp_header_t *header = NULL; + header = rp_signed_encrypted_parts_builder_build_header(element, env); + if(!header) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Failed to process Header Assertion."); + return AXIS2_FAILURE; + } + + return rp_signed_encrypted_parts_add_header(signed_encrypted_parts, env, header); + } + } + + /* process assertions specific to WS-SecPolicy 1.2 */ + if(!axutil_strcmp(ns, RP_SP_NS_12)) + { + if(!strcmp(local_name, RP_ATTACHMENTS)) + { + rp_signed_encrypted_parts_set_attachments(signed_encrypted_parts, env, AXIS2_TRUE); + return AXIS2_SUCCESS; + } + } + + /* either namespace or assertion is not understood */ + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] Unknown Assertion %s with namespace %s", + local_name, ns); + return AXIS2_FAILURE; +} + +static rp_header_t *AXIS2_CALL +rp_signed_encrypted_parts_builder_build_header( + axiom_element_t *element, + const axutil_env_t *env) +{ + rp_header_t *header = NULL; + axis2_char_t *name = NULL; + axis2_char_t *nspace = NULL; + + name = axiom_element_get_attribute_value_by_name(element, env, RP_NAME); + nspace = axiom_element_get_attribute_value_by_name(element, env, RP_NAMESPACE); + if(!nspace) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Header assertion should have namespace associated with it."); + return NULL; + } + + header = rp_header_create(env); + if(!header) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot create rp_header structure. Insufficient memory."); + return NULL; + } + + if(name) + { + rp_header_set_name(header, env, name); + } + + rp_header_set_namespace(header, env, nspace); + return header; +} diff --git a/neethi/src/secpolicy/builder/supporting_tokens_builder.c b/neethi/src/secpolicy/builder/supporting_tokens_builder.c new file mode 100644 index 0000000..7482144 --- /dev/null +++ b/neethi/src/secpolicy/builder/supporting_tokens_builder.c @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +supporting_tokens_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_supporting_tokens_t *supporting_tokens); + +axis2_bool_t AXIS2_CALL +is_token_assertion( + const axutil_env_t *env, + neethi_assertion_type_t type); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_supporting_tokens_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_supporting_tokens_t *supporting_tokens = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + axis2_char_t *local_name = NULL; + neethi_policy_t *normalized_policy = NULL; + + supporting_tokens = rp_supporting_tokens_create(env); + local_name = axiom_element_get_localname(element, env); + + if(local_name) + { + if(axutil_strcmp(local_name, RP_SIGNED_SUPPORTING_TOKENS) == 0) + { + rp_supporting_tokens_set_type(supporting_tokens, env, + RP_PROPERTY_SIGNED_SUPPORTING_TOKEN); + } + else if(axutil_strcmp(local_name, RP_SIGNED_ENDORSING_SUPPORTING_TOKENS) == 0) + { + rp_supporting_tokens_set_type(supporting_tokens, env, + RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN); + } + else if(axutil_strcmp(local_name, RP_SUPPORTING_TOKENS) == 0) + { + rp_supporting_tokens_set_type(supporting_tokens, env, + RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN); + } + else if(axutil_strcmp(local_name, RP_ENDORSING_SUPPORTING_TOKENS) == 0) + { + rp_supporting_tokens_set_type(supporting_tokens, env, + RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN); + } + else + return NULL; + } + else + return NULL; + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + neethi_policy_free(policy, env); + policy = NULL; + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + supporting_tokens_process_alternatives(env, all, supporting_tokens); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_supporting_tokens_free, supporting_tokens, + ASSERTION_TYPE_SUPPORTING_TOKENS); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +supporting_tokens_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_supporting_tokens_t *supporting_tokens) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_ALGORITHM_SUITE) + { + rp_algorithmsuite_t *algorithmsuite = NULL; + algorithmsuite = (rp_algorithmsuite_t *)neethi_assertion_get_value(assertion, env); + if(algorithmsuite) + { + rp_supporting_tokens_set_algorithmsuite(supporting_tokens, env, algorithmsuite); + } + else + return AXIS2_FAILURE; + } + else if(is_token_assertion(env, type)) + { + rp_property_t *token = NULL; + token = rp_property_create(env); + rp_token_identifier_set_token(token, assertion, env); + rp_supporting_tokens_add_token(supporting_tokens, env, token); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_bool_t AXIS2_CALL +is_token_assertion( + const axutil_env_t *env, + neethi_assertion_type_t type) +{ + if(type == ASSERTION_TYPE_USERNAME_TOKEN) + { + return AXIS2_TRUE; + } + else if(type == ASSERTION_TYPE_X509_TOKEN) + { + return AXIS2_TRUE; + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + return AXIS2_TRUE; + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + return AXIS2_TRUE; + } + else + return AXIS2_FALSE; +} diff --git a/neethi/src/secpolicy/builder/symmetric_binding_builder.c b/neethi/src/secpolicy/builder/symmetric_binding_builder.c new file mode 100644 index 0000000..1338963 --- /dev/null +++ b/neethi/src/secpolicy/builder/symmetric_binding_builder.c @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +symmetric_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_symmetric_binding_t *symmetric_binding); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_symmetric_binding_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_symmetric_binding_t *symmetric_binding = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + symmetric_binding = rp_symmetric_binding_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + neethi_policy_free(policy, env); + policy = NULL; + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + symmetric_binding_process_alternatives(env, all, symmetric_binding); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_symmetric_binding_free, symmetric_binding, + ASSERTION_TYPE_SYMMETRIC_BINDING); + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +symmetric_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_symmetric_binding_t * symmetric_binding) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + rp_binding_commons_t *commons = NULL; + rp_symmetric_asymmetric_binding_commons_t *as_commons = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + commons = rp_binding_commons_create(env); + as_commons = rp_symmetric_asymmetric_binding_commons_create(env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_PROTECTION_TOKEN) + { + rp_property_t *protection_token = NULL; + protection_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(protection_token) + { + rp_symmetric_binding_set_protection_token(symmetric_binding, env, protection_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ENCRYPTION_TOKEN) + { + rp_property_t *encryption_token = NULL; + encryption_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(encryption_token) + { + rp_symmetric_binding_set_encryption_token(symmetric_binding, env, encryption_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SIGNATURE_TOKEN) + { + rp_property_t *signature_token = NULL; + signature_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(signature_token) + { + rp_symmetric_binding_set_signature_token(symmetric_binding, env, signature_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ALGORITHM_SUITE) + { + rp_algorithmsuite_t *algorithmsuite = NULL; + algorithmsuite = (rp_algorithmsuite_t *)neethi_assertion_get_value(assertion, env); + if(algorithmsuite) + { + rp_binding_commons_set_algorithmsuite(commons, env, algorithmsuite); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_INCLUDE_TIMESTAMP) + { + rp_binding_commons_set_include_timestamp(commons, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_LAYOUT) + { + rp_layout_t *layout = NULL; + layout = (rp_layout_t *)neethi_assertion_get_value(assertion, env); + if(layout) + { + rp_binding_commons_set_layout(commons, env, layout); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ENCRYPT_BEFORE_SIGNING) + { + rp_symmetric_asymmetric_binding_commons_set_protection_order(as_commons, env, + RP_ENCRYPT_BEFORE_SIGNING); + } + else if(type == ASSERTION_TYPE_SIGN_BEFORE_ENCRYPTING) + { + rp_symmetric_asymmetric_binding_commons_set_protection_order(as_commons, env, + RP_SIGN_BEFORE_ENCRYPTING); + } + else if(type == ASSERTION_TYPE_ENCRYPT_SIGNATURE) + { + rp_symmetric_asymmetric_binding_commons_set_signature_protection(as_commons, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_PROTECT_TOKENS) + { + rp_symmetric_asymmetric_binding_commons_set_token_protection(as_commons, env, + AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_ONLY_SIGN_ENTIRE_HEADERS_AND_BODY) + { + rp_symmetric_asymmetric_binding_commons_set_entire_headers_and_body_signatures( + as_commons, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_SUPPORTING_TOKENS) + { + rp_supporting_tokens_t *supporting_tokens = NULL; + supporting_tokens + = (rp_supporting_tokens_t *)neethi_assertion_get_value(assertion, env); + if(supporting_tokens) + { + rp_property_type_t type; + type = rp_supporting_tokens_get_type(supporting_tokens, env); + if(type == RP_PROPERTY_SIGNED_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else if(type == RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + rp_symmetric_asymmetric_binding_commons_set_binding_commons(as_commons, env, commons); + rp_symmetric_binding_set_symmetric_asymmetric_binding_commons(symmetric_binding, env, + as_commons); + + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/token_identifier.c b/neethi/src/secpolicy/builder/token_identifier.c new file mode 100644 index 0000000..938627e --- /dev/null +++ b/neethi/src/secpolicy/builder/token_identifier.c @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +/***********************************/ + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_identifier_set_token( + rp_property_t *token, + neethi_assertion_t *assertion, + const axutil_env_t *env) +{ + void *value = NULL; + neethi_assertion_type_t type; + + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_USERNAME_TOKEN) + { + rp_username_token_t *username_token = NULL; + username_token = (rp_username_token_t *)value; + rp_property_set_value(token, env, username_token, RP_PROPERTY_USERNAME_TOKEN); + return AXIS2_SUCCESS; + } + else if(type == ASSERTION_TYPE_X509_TOKEN) + { + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)value; + rp_property_set_value(token, env, x509_token, RP_PROPERTY_X509_TOKEN); + return AXIS2_SUCCESS; + } + else if(type == ASSERTION_TYPE_SAML_TOKEN) + { + rp_saml_token_t *saml_token = NULL; + saml_token = (rp_saml_token_t *)value; + rp_property_set_value(token, env, saml_token, RP_PROPERTY_SAML_TOKEN); + return AXIS2_SUCCESS; + } + else if(type == ASSERTION_TYPE_ISSUED_TOKEN) + { + rp_issued_token_t *issued_token = NULL; + issued_token = (rp_issued_token_t *)value; + rp_property_set_value(token, env, issued_token, RP_PROPERTY_ISSUED_TOKEN); + return AXIS2_SUCCESS; + } + else + return AXIS2_FAILURE; + } + + return AXIS2_FAILURE; +} + diff --git a/neethi/src/secpolicy/builder/transport_binding_builder.c b/neethi/src/secpolicy/builder/transport_binding_builder.c new file mode 100644 index 0000000..be84119 --- /dev/null +++ b/neethi/src/secpolicy/builder/transport_binding_builder.c @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +transport_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_transport_binding_t *transport_binding); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_transport_binding_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_transport_binding_t *transport_binding = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + transport_binding = rp_transport_binding_create(env); + + child_node = axiom_node_get_first_element(node, env); + + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + transport_binding_process_alternatives(env, all, transport_binding); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_transport_binding_free, transport_binding, + ASSERTION_TYPE_TRANSPORT_BINDING); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +transport_binding_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_transport_binding_t *transport_binding) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + rp_binding_commons_t *commons = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + commons = rp_binding_commons_create(env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_TRANSPORT_TOKEN) + { + rp_property_t *transport_token = NULL; + transport_token = (rp_property_t *)neethi_assertion_get_value(assertion, env); + if(transport_token) + { + rp_transport_binding_set_transport_token(transport_binding, env, transport_token); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_ALGORITHM_SUITE) + { + rp_algorithmsuite_t *algorithmsuite = NULL; + algorithmsuite = (rp_algorithmsuite_t *)neethi_assertion_get_value(assertion, env); + if(algorithmsuite) + { + rp_binding_commons_set_algorithmsuite(commons, env, algorithmsuite); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_INCLUDE_TIMESTAMP) + { + rp_binding_commons_set_include_timestamp(commons, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_LAYOUT) + { + rp_layout_t *layout = NULL; + layout = (rp_layout_t *)neethi_assertion_get_value(assertion, env); + if(layout) + { + rp_binding_commons_set_layout(commons, env, layout); + } + else + return AXIS2_FAILURE; + } + else if(type == ASSERTION_TYPE_SUPPORTING_TOKENS) + { + rp_supporting_tokens_t *supporting_tokens = NULL; + supporting_tokens + = (rp_supporting_tokens_t *)neethi_assertion_get_value(assertion, env); + if(supporting_tokens) + { + rp_property_type_t type; + type = rp_supporting_tokens_get_type(supporting_tokens, env); + if(type == RP_PROPERTY_SIGNED_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_signed_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else if(type == RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_supporting_tokens(commons, env, supporting_tokens); + } + else if(type == RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN) + { + rp_binding_commons_set_endorsing_supporting_tokens(commons, env, + supporting_tokens); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + + rp_transport_binding_set_binding_commons(transport_binding, env, commons); + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/transport_token_builder.c b/neethi/src/secpolicy/builder/transport_token_builder.c new file mode 100644 index 0000000..f50183d --- /dev/null +++ b/neethi/src/secpolicy/builder/transport_token_builder.c @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +transport_token_process_alternatives( + const axutil_env_t * env, + neethi_all_t * all, + rp_property_t * transport_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_transport_token_builder_build( + const axutil_env_t * env, + axiom_node_t * node, + axiom_element_t * element) +{ + rp_property_t *transport_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + transport_token = rp_property_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + transport_token_process_alternatives(env, all, transport_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_property_free, transport_token, + ASSERTION_TYPE_TRANSPORT_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +transport_token_process_alternatives( + const axutil_env_t * env, + neethi_all_t * all, + rp_property_t * transport_token) +{ + + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_HTTPS_TOKEN) + { + rp_https_token_t *https_token = NULL; + https_token = (rp_https_token_t *)neethi_assertion_get_value(assertion, env); + if(https_token) + { + rp_property_set_value(transport_token, env, https_token, + RP_PROPERTY_HTTPS_TOKEN); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/trust10_builder.c b/neethi/src/secpolicy/builder/trust10_builder.c new file mode 100644 index 0000000..e97f0f7 --- /dev/null +++ b/neethi/src/secpolicy/builder/trust10_builder.c @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +trust10_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_trust10_t *trust10); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_trust10_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_trust10_t *trust10 = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + trust10 = rp_trust10_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + trust10_process_alternatives(env, all, trust10); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_trust10_free, trust10, ASSERTION_TYPE_TRUST10); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +trust10_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_trust10_t *trust10) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_MUST_SUPPORT_CLIENT_CHALLENGE) + { + rp_trust10_set_must_support_client_challenge(trust10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_SERVER_CHALLENGE) + { + rp_trust10_set_must_support_server_challenge(trust10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_CLIENT_ENTROPY) + { + rp_trust10_set_require_client_entropy(trust10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_SERVER_ENTROPHY) + { + rp_trust10_set_require_server_entropy(trust10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_ISSUED_TOKENS) + { + rp_trust10_set_must_support_issued_token(trust10, env, AXIS2_TRUE); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/username_token_builder.c b/neethi/src/secpolicy/builder/username_token_builder.c new file mode 100644 index 0000000..b8ac02b --- /dev/null +++ b/neethi/src/secpolicy/builder/username_token_builder.c @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +static axis2_status_t AXIS2_CALL username_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_username_token_t *username_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_username_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_username_token_t *username_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axis2_char_t *inclusion_value = NULL; + axutil_qname_t *qname = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + username_token = rp_username_token_create(env); + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_11, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + if(!inclusion_value) + { + /* we can try whether WS-SP1.2 specific inclusion value */ + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_12, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + } + + rp_username_token_set_inclusion(username_token, env, inclusion_value); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + assertion = neethi_assertion_create(env); + neethi_assertion_set_value(assertion, env, username_token, ASSERTION_TYPE_USERNAME_TOKEN); + return assertion; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + username_token_process_alternatives(env, all, username_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_username_token_free, username_token, + ASSERTION_TYPE_USERNAME_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +static axis2_status_t AXIS2_CALL +username_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_username_token_t *username_token) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(value) + { + if(type == ASSERTION_TYPE_WSS_USERNAME_TOKEN_10) + { + rp_username_token_set_useUTprofile10(username_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_WSS_USERNAME_TOKEN_11) + { + rp_username_token_set_useUTprofile11(username_token, env, AXIS2_TRUE); + } + else + return AXIS2_FAILURE; + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/wss10_builder.c b/neethi/src/secpolicy/builder/wss10_builder.c new file mode 100644 index 0000000..6dd10ae --- /dev/null +++ b/neethi/src/secpolicy/builder/wss10_builder.c @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +wss10_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_wss10_t *wss10); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_wss10_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_wss10_t *wss10 = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + wss10 = rp_wss10_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + wss10_process_alternatives(env, all, wss10); + + assertion = neethi_assertion_create_with_args(env, (AXIS2_FREE_VOID_ARG)rp_wss10_free, + wss10, ASSERTION_TYPE_WSS10); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +wss10_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_wss10_t *wss10) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_KEY_IDENTIFIER) + { + rp_wss10_set_must_support_ref_key_identifier(wss10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_ISSUER_SERIAL) + { + rp_wss10_set_must_support_ref_issuer_serial(wss10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_EXTERNAL_URI) + { + rp_wss10_set_must_support_ref_external_uri(wss10, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_EMBEDDED_TOKEN) + { + rp_wss10_set_must_support_ref_embedded_token(wss10, env, AXIS2_TRUE); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/wss11_builder.c b/neethi/src/secpolicy/builder/wss11_builder.c new file mode 100644 index 0000000..6249181 --- /dev/null +++ b/neethi/src/secpolicy/builder/wss11_builder.c @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +wss11_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_wss11_t *wss11); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_wss11_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_wss11_t *wss11 = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + wss11 = rp_wss11_create(env); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + wss11_process_alternatives(env, all, wss11); + + assertion = neethi_assertion_create_with_args(env, (AXIS2_FREE_VOID_ARG)rp_wss11_free, + wss11, ASSERTION_TYPE_WSS11); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +wss11_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_wss11_t *wss11) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + void *value = NULL; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + value = neethi_assertion_get_value(assertion, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_KEY_IDENTIFIER) + { + rp_wss11_set_must_support_ref_key_identifier(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_ISSUER_SERIAL) + { + rp_wss11_set_must_support_ref_issuer_serial(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_EXTERNAL_URI) + { + rp_wss11_set_must_support_ref_external_uri(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_EMBEDDED_TOKEN) + { + rp_wss11_set_must_support_ref_embedded_token(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_THUMBPRINT) + { + rp_wss11_set_must_support_ref_thumbprint(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_MUST_SUPPORT_REF_ENCRYPTED_KEY) + { + rp_wss11_set_must_support_ref_encryptedkey(wss11, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_SIGNATURE_CONFIRMATION) + { + rp_wss11_set_require_signature_confirmation(wss11, env, AXIS2_TRUE); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/builder/x509_token_builder.c b/neethi/src/secpolicy/builder/x509_token_builder.c new file mode 100644 index 0000000..fa8d8f9 --- /dev/null +++ b/neethi/src/secpolicy/builder/x509_token_builder.c @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +/*private functions*/ + +axis2_status_t AXIS2_CALL +x509_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_x509_token_t *x509_token); + +/***********************************/ + +AXIS2_EXTERN neethi_assertion_t *AXIS2_CALL +rp_x509_token_builder_build( + const axutil_env_t *env, + axiom_node_t *node, + axiom_element_t *element) +{ + rp_x509_token_t *x509_token = NULL; + neethi_policy_t *policy = NULL; + axiom_node_t *child_node = NULL; + axiom_element_t *child_element = NULL; + axutil_array_list_t *alternatives = NULL; + neethi_operator_t *component = NULL; + neethi_all_t *all = NULL; + axis2_char_t *inclusion_value = NULL; + axutil_qname_t *qname = NULL; + neethi_assertion_t *assertion = NULL; + neethi_policy_t *normalized_policy = NULL; + + x509_token = rp_x509_token_create(env); + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_11, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + + if(!inclusion_value) + { + /* we can try whether WS-SP1.2 specific inclusion value */ + qname = axutil_qname_create(env, RP_INCLUDE_TOKEN, RP_SP_NS_12, RP_SP_PREFIX); + inclusion_value = axiom_element_get_attribute_value(element, env, qname); + axutil_qname_free(qname, env); + qname = NULL; + } + + rp_x509_token_set_inclusion(x509_token, env, inclusion_value); + + child_node = axiom_node_get_first_element(node, env); + if(!child_node) + { + return NULL; + } + + if(axiom_node_get_node_type(child_node, env) == AXIOM_ELEMENT) + { + child_element = (axiom_element_t *)axiom_node_get_data_element(child_node, env); + if(child_element) + { + policy = neethi_engine_get_policy(env, child_node, child_element); + if(!policy) + { + return NULL; + } + normalized_policy = neethi_engine_get_normalize(env, AXIS2_FALSE, policy); + neethi_policy_free(policy, env); + policy = NULL; + alternatives = neethi_policy_get_alternatives(normalized_policy, env); + component = (neethi_operator_t *)axutil_array_list_get(alternatives, env, 0); + all = (neethi_all_t *)neethi_operator_get_value(component, env); + x509_token_process_alternatives(env, all, x509_token); + + assertion = neethi_assertion_create_with_args(env, + (AXIS2_FREE_VOID_ARG)rp_x509_token_free, x509_token, ASSERTION_TYPE_X509_TOKEN); + + neethi_policy_free(normalized_policy, env); + normalized_policy = NULL; + + return assertion; + } + else + return NULL; + } + else + return NULL; +} + +axis2_status_t AXIS2_CALL +x509_token_process_alternatives( + const axutil_env_t *env, + neethi_all_t *all, + rp_x509_token_t *x509_token) +{ + neethi_operator_t *operator = NULL; + axutil_array_list_t *arraylist = NULL; + neethi_assertion_t *assertion = NULL; + neethi_assertion_type_t type; + + int i = 0; + + arraylist = neethi_all_get_policy_components(all, env); + + for(i = 0; i < axutil_array_list_size(arraylist, env); i++) + { + operator = (neethi_operator_t *)axutil_array_list_get(arraylist, env, i); + assertion = (neethi_assertion_t *)neethi_operator_get_value(operator, env); + type = neethi_assertion_get_type(assertion, env); + + if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC10) + { + rp_x509_token_set_derivedkey(x509_token, env, DERIVEKEY_NEEDED); + rp_x509_token_set_derivedkey_version(x509_token, env, DERIVEKEY_VERSION_SC10); + } + else if(type == ASSERTION_TYPE_REQUIRE_DERIVED_KEYS_SC13) + { + rp_x509_token_set_derivedkey(x509_token, env, DERIVEKEY_NEEDED); + rp_x509_token_set_derivedkey_version(x509_token, env, DERIVEKEY_VERSION_SC13); + } + else if(type == ASSERTION_TYPE_REQUIRE_KEY_IDENTIFIRE_REFERENCE) + { + rp_x509_token_set_require_key_identifier_reference(x509_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_ISSUER_SERIAL_REFERENCE) + { + rp_x509_token_set_require_issuer_serial_reference(x509_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_EMBEDDED_TOKEN_REFERENCE) + { + rp_x509_token_set_require_embedded_token_reference(x509_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_REQUIRE_THUMBPRINT_REFERENCE) + { + rp_x509_token_set_require_thumb_print_reference(x509_token, env, AXIS2_TRUE); + } + else if(type == ASSERTION_TYPE_WSS_X509_V1_TOKEN_10) + { + rp_x509_token_set_token_version_and_type(x509_token, env, RP_WSS_X509_V1_TOKEN_10); + } + else if(type == ASSERTION_TYPE_WSS_X509_V3_TOKEN_10) + { + rp_x509_token_set_token_version_and_type(x509_token, env, RP_WSS_X509_V3_TOKEN_10); + } + else + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/Makefile.am b/neethi/src/secpolicy/model/Makefile.am new file mode 100644 index 0000000..b24ddb7 --- /dev/null +++ b/neethi/src/secpolicy/model/Makefile.am @@ -0,0 +1,21 @@ +TESTS = + +noinst_LTLIBRARIES = librp_model.la + +librp_model_la_SOURCES = algorithmsuite.c asymmetric_binding.c \ + binding_commons.c header.c element.c https_token.c layout.c \ + property.c rampart_config.c secpolicy.c security_context_token.c \ + signed_encrypted_elements.c signed_encrypted_parts.c signed_encrypted_items.c \ + supporting_tokens.c symmetric_asymmetric_binding_commons.c \ + symmetric_binding.c transport_binding.c ut.c wss10.c wss11.c x509_token.c \ + trust10.c issued_token.c saml_token.c token.c + + +librp_model_la_LIBADD = ../../../../util/src/libaxutil.la + + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../include \ + -I ../../../../util/include \ + -I ../../../../axiom/include \ + -I ../../../../include diff --git a/neethi/src/secpolicy/model/algorithmsuite.c b/neethi/src/secpolicy/model/algorithmsuite.c new file mode 100644 index 0000000..db3426c --- /dev/null +++ b/neethi/src/secpolicy/model/algorithmsuite.c @@ -0,0 +1,627 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_algorithmsuite_t +{ + axis2_char_t *algosuite_string; + axis2_char_t *symmetric_signature; + axis2_char_t *asymmetric_signature; + axis2_char_t *computed_key; + int max_symmetric_keylength; + int min_asymmetric_keylength; + int max_asymmetric_keylength; + axis2_char_t *digest; + axis2_char_t *encryption; + axis2_char_t *symmetrickeywrap; + axis2_char_t *asymmetrickeywrap; + axis2_char_t *encryption_key_derivation; + axis2_char_t *signature_key_derivation; + int encryption_key_derivation_keylength; + int signature_key_derivation_keylength; + int min_symmetric_keylength; + axis2_char_t *c14n; + axis2_char_t *soap_normalization; + axis2_char_t *str_transformation; + axis2_char_t *xpath; + int ref; + +}; + +AXIS2_EXTERN rp_algorithmsuite_t *AXIS2_CALL +rp_algorithmsuite_create( + const axutil_env_t *env) +{ + rp_algorithmsuite_t *algorithmsuite = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + algorithmsuite = (rp_algorithmsuite_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_algorithmsuite_t)); + + if(algorithmsuite == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + algorithmsuite->algosuite_string = NULL; + algorithmsuite->symmetric_signature = RP_HMAC_SHA1; + algorithmsuite->asymmetric_signature = RP_RSA_SHA1; + algorithmsuite->computed_key = RP_P_SHA1; + algorithmsuite->max_symmetric_keylength = 256; + algorithmsuite->min_asymmetric_keylength = 1024; + algorithmsuite->max_asymmetric_keylength = 4096; + algorithmsuite->digest = NULL; + algorithmsuite->encryption = NULL; + algorithmsuite->symmetrickeywrap = NULL; + algorithmsuite->asymmetrickeywrap = NULL; + algorithmsuite->encryption_key_derivation = NULL; + algorithmsuite->signature_key_derivation = NULL; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + algorithmsuite->min_symmetric_keylength = 0; + ; + algorithmsuite->c14n = RP_EX_C14N; + algorithmsuite->soap_normalization = NULL; + algorithmsuite->str_transformation = NULL; + algorithmsuite->xpath = NULL; + algorithmsuite->ref = 0; + return algorithmsuite; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_algorithmsuite_free( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + if(algorithmsuite) + { + if(--(algorithmsuite->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, algorithmsuite); + algorithmsuite = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_algosuite_string( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + if(!algorithmsuite) + return NULL; + else + return algorithmsuite->algosuite_string; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_algosuite( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *algosuite_string) +{ + AXIS2_PARAM_CHECK(env->error, algosuite_string, AXIS2_FAILURE); + + algorithmsuite->algosuite_string = algosuite_string; + + if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC256) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES256; + algorithmsuite->symmetrickeywrap = RP_KW_AES256; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L256; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 256; + algorithmsuite->encryption_key_derivation_keylength = 256; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC192) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES192; + algorithmsuite->symmetrickeywrap = RP_KW_AES192; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC128) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES128; + algorithmsuite->symmetrickeywrap = RP_KW_AES128; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L128; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L128; + algorithmsuite->min_symmetric_keylength = 128; + algorithmsuite->encryption_key_derivation_keylength = 128; + algorithmsuite->signature_key_derivation_keylength = 128; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_TRIPLE_DES) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_TRIPLE_DES; + algorithmsuite->symmetrickeywrap = RP_KW_TRIPLE_DES; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC256_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES256; + algorithmsuite->symmetrickeywrap = RP_KW_AES256; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L256; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 256; + algorithmsuite->encryption_key_derivation_keylength = 256; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC192_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES192; + algorithmsuite->symmetrickeywrap = RP_KW_AES192; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC128_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_AES128; + algorithmsuite->symmetrickeywrap = RP_KW_AES128; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L128; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L128; + algorithmsuite->min_symmetric_keylength = 128; + algorithmsuite->encryption_key_derivation_keylength = 128; + algorithmsuite->signature_key_derivation_keylength = 128; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_TRIPLE_DES_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA1; + algorithmsuite->encryption = RP_TRIPLE_DES; + algorithmsuite->symmetrickeywrap = RP_KW_TRIPLE_DES; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC256_SHA256) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES256; + algorithmsuite->symmetrickeywrap = RP_KW_AES256; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L256; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 256; + algorithmsuite->encryption_key_derivation_keylength = 256; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC192_SHA256) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES192; + algorithmsuite->symmetrickeywrap = RP_KW_AES192; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC128_SHA256) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES128; + algorithmsuite->symmetrickeywrap = RP_KW_AES128; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L128; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L128; + algorithmsuite->min_symmetric_keylength = 128; + algorithmsuite->encryption_key_derivation_keylength = 128; + algorithmsuite->signature_key_derivation_keylength = 128; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_TRIPLE_DES_SHA256) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_TRIPLE_DES; + algorithmsuite->symmetrickeywrap = RP_KW_TRIPLE_DES; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA_OAEP; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC256_SHA256_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES256; + algorithmsuite->symmetrickeywrap = RP_KW_AES256; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L256; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 256; + algorithmsuite->encryption_key_derivation_keylength = 256; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC192_SHA256_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES192; + algorithmsuite->symmetrickeywrap = RP_KW_AES192; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_BASIC128_SHA256_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_AES128; + algorithmsuite->symmetrickeywrap = RP_KW_AES128; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L128; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L128; + algorithmsuite->min_symmetric_keylength = 128; + algorithmsuite->encryption_key_derivation_keylength = 128; + algorithmsuite->signature_key_derivation_keylength = 128; + + return AXIS2_SUCCESS; + } + else if(axutil_strcmp(algosuite_string, RP_ALGO_SUITE_TRIPLE_DES_SHA256_RSA15) == 0) + { + algorithmsuite->digest = RP_SHA256; + algorithmsuite->encryption = RP_TRIPLE_DES; + algorithmsuite->symmetrickeywrap = RP_KW_TRIPLE_DES; + algorithmsuite->asymmetrickeywrap = RP_KW_RSA15; + algorithmsuite->encryption_key_derivation = RP_P_SHA1_L192; + algorithmsuite->signature_key_derivation = RP_P_SHA1_L192; + algorithmsuite->min_symmetric_keylength = 192; + algorithmsuite->encryption_key_derivation_keylength = 192; + algorithmsuite->signature_key_derivation_keylength = 192; + + return AXIS2_SUCCESS; + } + else + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_symmetric_signature( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->symmetric_signature; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_symmetric_signature( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *symmetric_signature) +{ + AXIS2_PARAM_CHECK(env->error, symmetric_signature, AXIS2_FAILURE); + + algorithmsuite->symmetric_signature = symmetric_signature; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_asymmetric_signature( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->asymmetric_signature; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_asymmetric_signature( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *asymmetric_signature) +{ + AXIS2_PARAM_CHECK(env->error, asymmetric_signature, AXIS2_FAILURE); + + algorithmsuite->asymmetric_signature = asymmetric_signature; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_computed_key( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->computed_key; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_computed_key( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *computed_key) +{ + AXIS2_PARAM_CHECK(env->error, computed_key, AXIS2_FAILURE); + + algorithmsuite->computed_key = computed_key; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_digest( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->digest; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_encryption( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->encryption; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_max_symmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->max_symmetric_keylength; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_max_symmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + int max_symmetric_keylength) +{ + algorithmsuite->max_symmetric_keylength = max_symmetric_keylength; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_min_symmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->min_symmetric_keylength; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_encryption_derivation_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->encryption_key_derivation_keylength; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_signature_derivation_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->signature_key_derivation_keylength; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_max_asymmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->max_asymmetric_keylength; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_max_asymmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + int max_asymmetric_keylength) +{ + algorithmsuite->max_asymmetric_keylength = max_asymmetric_keylength; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_algorithmsuite_get_min_asymmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->min_asymmetric_keylength; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_min_asymmetric_keylength( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + int min_asymmetric_keylength) +{ + algorithmsuite->min_asymmetric_keylength = min_asymmetric_keylength; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_symmetrickeywrap( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->symmetrickeywrap; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_asymmetrickeywrap( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->asymmetrickeywrap; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_signature_key_derivation( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->signature_key_derivation; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_encryption_key_derivation( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->encryption_key_derivation; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_soap_normalization( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->soap_normalization; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_soap_normalization( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *soap_normalization) +{ + AXIS2_PARAM_CHECK(env->error, soap_normalization, AXIS2_FAILURE); + algorithmsuite->soap_normalization = soap_normalization; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_str_transformation( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->str_transformation; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_str_transformation( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *str_transformation) +{ + AXIS2_PARAM_CHECK(env->error, str_transformation, AXIS2_FAILURE); + algorithmsuite->str_transformation = str_transformation; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_c14n( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->c14n; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_c14n( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *c14n) +{ + AXIS2_PARAM_CHECK(env->error, c14n, AXIS2_FAILURE); + algorithmsuite->c14n = c14n; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_algorithmsuite_get_xpath( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + return algorithmsuite->xpath; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_set_xpath( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env, + axis2_char_t *xpath) +{ + AXIS2_PARAM_CHECK(env->error, xpath, AXIS2_FAILURE); + algorithmsuite->xpath = xpath; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_algorithmsuite_increment_ref( + rp_algorithmsuite_t *algorithmsuite, + const axutil_env_t *env) +{ + algorithmsuite->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/asymmetric_binding.c b/neethi/src/secpolicy/model/asymmetric_binding.c new file mode 100644 index 0000000..0e57dce --- /dev/null +++ b/neethi/src/secpolicy/model/asymmetric_binding.c @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_asymmetric_binding_t +{ + rp_symmetric_asymmetric_binding_commons_t *symmetric_asymmetric_binding_commons; + rp_property_t *initiator_token; + rp_property_t *recipient_token; + int ref; +}; + +AXIS2_EXTERN rp_asymmetric_binding_t *AXIS2_CALL +rp_asymmetric_binding_create( + const axutil_env_t *env) +{ + rp_asymmetric_binding_t *asymmetric_binding = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + asymmetric_binding = (rp_asymmetric_binding_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_asymmetric_binding_t)); + + if(asymmetric_binding == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + asymmetric_binding->symmetric_asymmetric_binding_commons = NULL; + asymmetric_binding->initiator_token = NULL; + asymmetric_binding->recipient_token = NULL; + asymmetric_binding->ref = 0; + + return asymmetric_binding; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_asymmetric_binding_free( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env) +{ + if(asymmetric_binding) + { + + if(--(asymmetric_binding->ref) > 0) + { + return; + } + + if(asymmetric_binding->symmetric_asymmetric_binding_commons) + { + rp_symmetric_asymmetric_binding_commons_free( + asymmetric_binding-> symmetric_asymmetric_binding_commons, env); + asymmetric_binding->symmetric_asymmetric_binding_commons = NULL; + } + if(asymmetric_binding->initiator_token) + { + rp_property_free(asymmetric_binding->initiator_token, env); + asymmetric_binding->initiator_token = NULL; + } + if(asymmetric_binding->recipient_token) + { + rp_property_free(asymmetric_binding->recipient_token, env); + asymmetric_binding->recipient_token = NULL; + } + AXIS2_FREE(env->allocator, asymmetric_binding); + } + + return; +} + +/* Implementations */ + +AXIS2_EXTERN rp_symmetric_asymmetric_binding_commons_t *AXIS2_CALL +rp_asymmetric_binding_get_symmetric_asymmetric_binding_commons( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env) +{ + return asymmetric_binding->symmetric_asymmetric_binding_commons; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_asymmetric_binding_set_symmetric_asymmetric_binding_commons( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env, + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons) +{ + AXIS2_PARAM_CHECK(env->error, symmetric_asymmetric_binding_commons, AXIS2_FAILURE); + + asymmetric_binding->symmetric_asymmetric_binding_commons = symmetric_asymmetric_binding_commons; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_asymmetric_binding_get_initiator_token( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env) +{ + return asymmetric_binding->initiator_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_asymmetric_binding_set_initiator_token( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env, + rp_property_t *initiator_token) +{ + AXIS2_PARAM_CHECK(env->error, initiator_token, AXIS2_FAILURE); + + rp_property_increment_ref(initiator_token, env); + asymmetric_binding->initiator_token = initiator_token; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_asymmetric_binding_set_recipient_token( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env, + rp_property_t *recipient_token) +{ + AXIS2_PARAM_CHECK(env->error, recipient_token, AXIS2_FAILURE); + + rp_property_increment_ref(recipient_token, env); + asymmetric_binding->recipient_token = recipient_token; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_asymmetric_binding_get_recipient_token( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env) +{ + return asymmetric_binding->recipient_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_asymmetric_binding_increment_ref( + rp_asymmetric_binding_t *asymmetric_binding, + const axutil_env_t *env) +{ + asymmetric_binding->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/binding_commons.c b/neethi/src/secpolicy/model/binding_commons.c new file mode 100644 index 0000000..9795c78 --- /dev/null +++ b/neethi/src/secpolicy/model/binding_commons.c @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_binding_commons_t +{ + rp_algorithmsuite_t *algorithmsuite; + axis2_bool_t include_timestamp; + rp_layout_t *layout; + rp_supporting_tokens_t *signed_supporting_tokens; + rp_supporting_tokens_t *signed_endorsing_supporting_tokens; + rp_supporting_tokens_t *endorsing_supporting_tokens; + rp_supporting_tokens_t *supporting_tokens; +}; + +AXIS2_EXTERN rp_binding_commons_t *AXIS2_CALL +rp_binding_commons_create( + const axutil_env_t *env) +{ + rp_binding_commons_t *binding_commons = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + binding_commons = (rp_binding_commons_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_binding_commons_t)); + + if(binding_commons == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + binding_commons->algorithmsuite = NULL; + binding_commons->include_timestamp = AXIS2_FALSE; + binding_commons->layout = NULL; + binding_commons->signed_supporting_tokens = NULL; + binding_commons->signed_endorsing_supporting_tokens = NULL; + binding_commons->endorsing_supporting_tokens = NULL; + binding_commons->supporting_tokens = NULL; + + return binding_commons; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_binding_commons_free( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + if(binding_commons) + { + if(binding_commons->algorithmsuite) + { + rp_algorithmsuite_free(binding_commons->algorithmsuite, env); + binding_commons->algorithmsuite = NULL; + } + if(binding_commons->layout) + { + rp_layout_free(binding_commons->layout, env); + binding_commons->layout = NULL; + } + if(binding_commons->signed_supporting_tokens) + { + rp_supporting_tokens_free(binding_commons->signed_supporting_tokens, env); + binding_commons->signed_supporting_tokens = NULL; + } + if(binding_commons->signed_endorsing_supporting_tokens) + { + rp_supporting_tokens_free(binding_commons-> signed_endorsing_supporting_tokens, env); + binding_commons->signed_endorsing_supporting_tokens = NULL; + } + if(binding_commons->endorsing_supporting_tokens) + { + rp_supporting_tokens_free(binding_commons-> endorsing_supporting_tokens, env); + binding_commons->endorsing_supporting_tokens = NULL; + } + if(binding_commons->supporting_tokens) + { + rp_supporting_tokens_free(binding_commons->supporting_tokens, env); + binding_commons->supporting_tokens = NULL; + } + AXIS2_FREE(env->allocator, binding_commons); + binding_commons = NULL; + + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_binding_commons_get_include_timestamp( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->include_timestamp; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_include_timestamp( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + axis2_bool_t include_timestamp) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, include_timestamp, AXIS2_FAILURE); + + binding_commons->include_timestamp = include_timestamp; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_algorithmsuite_t *AXIS2_CALL +rp_binding_commons_get_algorithmsuite( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->algorithmsuite; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_algorithmsuite( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_algorithmsuite_t *algorithmsuite) +{ + AXIS2_PARAM_CHECK(env->error, algorithmsuite, AXIS2_FAILURE); + + rp_algorithmsuite_increment_ref(algorithmsuite, env); + binding_commons->algorithmsuite = algorithmsuite; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_layout_t *AXIS2_CALL +rp_binding_commons_get_layout( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->layout; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_layout( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_layout_t *layout) +{ + AXIS2_PARAM_CHECK(env->error, layout, AXIS2_FAILURE); + rp_layout_increment_ref(layout, env); + binding_commons->layout = layout; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_binding_commons_get_signed_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->signed_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_signed_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_supporting_tokens_t *signed_supporting_tokens) +{ + AXIS2_PARAM_CHECK(env->error, signed_supporting_tokens, AXIS2_FAILURE); + binding_commons->signed_supporting_tokens = signed_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_binding_commons_get_signed_endorsing_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->signed_endorsing_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_signed_endorsing_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_supporting_tokens_t *signed_endorsing_supporting_tokens) +{ + AXIS2_PARAM_CHECK(env->error, signed_endorsing_supporting_tokens, AXIS2_FAILURE); + + binding_commons->signed_endorsing_supporting_tokens = signed_endorsing_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_binding_commons_get_endorsing_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->endorsing_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_endorsing_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_supporting_tokens_t *endorsing_supporting_tokens) +{ + AXIS2_PARAM_CHECK(env->error, endorsing_supporting_tokens, AXIS2_FAILURE); + binding_commons->endorsing_supporting_tokens = endorsing_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_binding_commons_get_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env) +{ + return binding_commons->supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_binding_commons_set_supporting_tokens( + rp_binding_commons_t *binding_commons, + const axutil_env_t *env, + rp_supporting_tokens_t *supporting_tokens) +{ + AXIS2_PARAM_CHECK(env->error, supporting_tokens, AXIS2_FAILURE); + binding_commons->supporting_tokens = supporting_tokens; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/element.c b/neethi/src/secpolicy/model/element.c new file mode 100644 index 0000000..125fef3 --- /dev/null +++ b/neethi/src/secpolicy/model/element.c @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_element_t +{ + axis2_char_t *name; + axis2_char_t *nspace; +}; + +AXIS2_EXTERN rp_element_t *AXIS2_CALL +rp_element_create( + const axutil_env_t * env) +{ + rp_element_t *element = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + element = (rp_element_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_element_t)); + + if(element == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + element->name = NULL; + element->nspace = NULL; + + return element; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_element_free( + rp_element_t * element, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(element) + { + AXIS2_FREE(env->allocator, element); + element = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_element_get_name( + rp_element_t * element, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return element->name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_element_set_name( + rp_element_t * element, + const axutil_env_t * env, + axis2_char_t * name) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); + + element->name = name; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_element_get_namespace( + rp_element_t * element, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return element->nspace; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_element_set_namespace( + rp_element_t * element, + const axutil_env_t * env, + axis2_char_t * nspace) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, nspace, AXIS2_FAILURE); + + element->nspace = nspace; + + return AXIS2_SUCCESS; + +} diff --git a/neethi/src/secpolicy/model/header.c b/neethi/src/secpolicy/model/header.c new file mode 100644 index 0000000..9aab978 --- /dev/null +++ b/neethi/src/secpolicy/model/header.c @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_header_t +{ + axis2_char_t *name; + axis2_char_t *nspace; +}; + +AXIS2_EXTERN rp_header_t *AXIS2_CALL +rp_header_create( + const axutil_env_t * env) +{ + rp_header_t *header = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + header = (rp_header_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_header_t)); + + if(header == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + header->name = NULL; + header->nspace = NULL; + + return header; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_header_free( + rp_header_t * header, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(header) + { + if(header->name) + { + AXIS2_FREE(env->allocator, header->name); + header->name = NULL; + } + if(header->nspace) + { + AXIS2_FREE(env->allocator, header->nspace); + header->nspace = NULL; + } + + AXIS2_FREE(env->allocator, header); + header = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_header_get_name( + rp_header_t * header, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return header->name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_header_set_name( + rp_header_t * header, + const axutil_env_t * env, + axis2_char_t * name) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); + + header->name = axutil_strdup(env, name); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_header_get_namespace( + rp_header_t * header, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return header->nspace; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_header_set_namespace( + rp_header_t * header, + const axutil_env_t * env, + axis2_char_t * nspace) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, nspace, AXIS2_FAILURE); + + header->nspace = axutil_strdup(env, nspace); + + return AXIS2_SUCCESS; + +} diff --git a/neethi/src/secpolicy/model/https_token.c b/neethi/src/secpolicy/model/https_token.c new file mode 100644 index 0000000..100af45 --- /dev/null +++ b/neethi/src/secpolicy/model/https_token.c @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_https_token_t +{ + axis2_char_t *inclusion; + axis2_bool_t derivedkeys; + axis2_bool_t require_client_certificate; + int ref; +}; + +AXIS2_EXTERN rp_https_token_t *AXIS2_CALL +rp_https_token_create( + const axutil_env_t * env) +{ + rp_https_token_t *https_token = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + https_token = (rp_https_token_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_https_token_t)); + + if(https_token == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + https_token->inclusion = RP_INCLUDE_ALWAYS; + https_token->derivedkeys = AXIS2_FALSE; + https_token->require_client_certificate = AXIS2_FALSE; + https_token->ref = 0; + + return https_token; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_https_token_free( + rp_https_token_t * https_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(https_token) + { + if(--(https_token->ref) > 0) + { + return; + } + AXIS2_FREE(env->allocator, https_token); + https_token = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_https_token_get_inclusion( + rp_https_token_t * https_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return https_token->inclusion; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_https_token_set_inclusion( + rp_https_token_t * https_token, + const axutil_env_t * env, + axis2_char_t * inclusion) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, inclusion, AXIS2_FAILURE); + + https_token->inclusion = inclusion; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_https_token_get_derivedkeys( + rp_https_token_t * https_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return https_token->derivedkeys; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_https_token_set_derivedkeys( + rp_https_token_t * https_token, + const axutil_env_t * env, + axis2_bool_t derivedkeys) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, derivedkeys, AXIS2_FAILURE); + + https_token->derivedkeys = derivedkeys; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_https_token_get_require_client_certificate( + rp_https_token_t * https_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return https_token->require_client_certificate; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_https_token_set_require_client_certificate( + rp_https_token_t * https_token, + const axutil_env_t * env, + axis2_bool_t require_client_certificate) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, require_client_certificate, AXIS2_FAILURE) + https_token->require_client_certificate = require_client_certificate; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_https_token_increment_ref( + rp_https_token_t * https_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + https_token->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/issued_token.c b/neethi/src/secpolicy/model/issued_token.c new file mode 100644 index 0000000..00948f2 --- /dev/null +++ b/neethi/src/secpolicy/model/issued_token.c @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_issued_token +{ + axis2_char_t *inclusion; + axiom_node_t *issuer_epr; + axiom_node_t *requested_sec_token_template; + axis2_bool_t derivedkeys; + axis2_bool_t require_external_reference; + axis2_bool_t require_internal_reference; + int ref; +}; + +AXIS2_EXTERN rp_issued_token_t * AXIS2_CALL +rp_issued_token_create( + const axutil_env_t *env) +{ + rp_issued_token_t *issued_token = NULL; + + issued_token = (rp_issued_token_t*)AXIS2_MALLOC(env->allocator, sizeof(rp_issued_token_t)); + + if(issued_token == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + issued_token->inclusion = NULL; + issued_token->issuer_epr = NULL; + issued_token->requested_sec_token_template = NULL; + issued_token->derivedkeys = AXIS2_FALSE; + issued_token->require_external_reference = AXIS2_FALSE; + issued_token->require_internal_reference = AXIS2_FALSE; + issued_token->ref = 0; + + return issued_token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_issued_token_free( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + if(issued_token) + { + if(--(issued_token->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, issued_token); + issued_token = NULL; + } + return; +} + +AXIS2_EXTERN axis2_char_t * AXIS2_CALL +rp_issued_token_get_inclusion( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->inclusion; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_inclusion( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axis2_char_t *inclusion) +{ + if(inclusion) + { + issued_token->inclusion = inclusion; + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_node_t * AXIS2_CALL +rp_issued_token_get_issuer_epr( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->issuer_epr; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_issuer_epr( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axiom_node_t *issuer_epr) +{ + if(issuer_epr) + { + issued_token->issuer_epr = issuer_epr; + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axiom_node_t * AXIS2_CALL +rp_issued_token_get_requested_sec_token_template( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->requested_sec_token_template; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_requested_sec_token_template( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axiom_node_t *req_sec_token_template) +{ + if(req_sec_token_template) + { + issued_token->requested_sec_token_template = req_sec_token_template; + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_issued_token_get_derivedkeys( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->derivedkeys; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_derivedkeys( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axis2_bool_t derivedkeys) +{ + AXIS2_PARAM_CHECK(env->error, derivedkeys, AXIS2_FAILURE); + issued_token->derivedkeys = derivedkeys; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_issued_token_get_require_external_reference( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->require_external_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_require_exernal_reference( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axis2_bool_t require_external_reference) +{ + AXIS2_PARAM_CHECK(env->error, require_external_reference, AXIS2_FAILURE); + issued_token->require_external_reference = require_external_reference; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_issued_token_get_require_internal_reference( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + return issued_token->require_internal_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_set_require_internal_reference( + rp_issued_token_t *issued_token, + const axutil_env_t *env, + axis2_bool_t require_internal_reference) +{ + AXIS2_PARAM_CHECK(env->error, require_internal_reference, AXIS2_FAILURE); + issued_token->require_internal_reference = require_internal_reference; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_issued_token_increment_ref( + rp_issued_token_t *issued_token, + const axutil_env_t *env) +{ + issued_token->ref++; + return AXIS2_SUCCESS; +} + diff --git a/neethi/src/secpolicy/model/layout.c b/neethi/src/secpolicy/model/layout.c new file mode 100644 index 0000000..b4591c4 --- /dev/null +++ b/neethi/src/secpolicy/model/layout.c @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_layout_t +{ + axis2_char_t *value; + int ref; +}; + +AXIS2_EXTERN rp_layout_t *AXIS2_CALL +rp_layout_create( + const axutil_env_t * env) +{ + rp_layout_t *layout = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + layout = (rp_layout_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_layout_t)); + + if(layout == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + layout->value = RP_LAYOUT_STRICT; + layout->ref = 0; + return layout; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_layout_free( + rp_layout_t * layout, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(layout) + { + if(--(layout->ref) > 0) + { + return; + } + AXIS2_FREE(env->allocator, layout); + layout = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_layout_get_value( + rp_layout_t * layout, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return layout->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_layout_set_value( + rp_layout_t * layout, + const axutil_env_t * env, + axis2_char_t * value) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + + layout->value = value; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_layout_increment_ref( + rp_layout_t * layout, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + layout->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/property.c b/neethi/src/secpolicy/model/property.c new file mode 100644 index 0000000..a8d806c --- /dev/null +++ b/neethi/src/secpolicy/model/property.c @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +struct rp_property_t +{ + rp_property_type_t type; + void *value; + int ref; +}; + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_property_create( + const axutil_env_t * env) +{ + rp_property_t *property = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + property = (rp_property_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_property_t)); + + if(property == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + property->type = RP_PROPERTY_UNKNOWN; + property->value = NULL; + property->ref = 0; + + return property; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_property_free( + rp_property_t * property, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(property) + { + if(--(property->ref) > 0) + { + return; + } + + if(property->value) + { + switch(property->type) + { + case RP_PROPERTY_USERNAME_TOKEN: + rp_username_token_free((rp_username_token_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_X509_TOKEN: + rp_x509_token_free((rp_x509_token_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_ISSUED_TOKEN: + rp_issued_token_free((rp_issued_token_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SAML_TOKEN: + rp_saml_token_free((rp_saml_token_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SECURITY_CONTEXT_TOKEN: + rp_security_context_token_free((rp_security_context_token_t *)property->value, + env); + property->value = NULL; + break; + + case RP_PROPERTY_HTTPS_TOKEN: + rp_https_token_free((rp_https_token_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SYMMETRIC_BINDING: + rp_symmetric_binding_free((rp_symmetric_binding_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_ASYMMETRIC_BINDING: + rp_asymmetric_binding_free((rp_asymmetric_binding_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_TRANSPORT_BINDING: + rp_transport_binding_free((rp_transport_binding_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SIGNED_SUPPORTING_TOKEN: + rp_supporting_tokens_free((rp_supporting_tokens_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN: + rp_supporting_tokens_free((rp_supporting_tokens_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN: + rp_supporting_tokens_free((rp_supporting_tokens_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN: + rp_supporting_tokens_free((rp_supporting_tokens_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_SUPPORTING_TOKEN: + rp_supporting_tokens_free((rp_supporting_tokens_t *)property-> value, env); + property->value = NULL; + break; + + case RP_PROPERTY_WSS10: + rp_wss10_free((rp_wss10_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_WSS11: + rp_wss11_free((rp_wss11_t *)property->value, env); + property->value = NULL; + break; + + case RP_PROPERTY_UNKNOWN: + break; + } + } + AXIS2_FREE(env->allocator, property); + } + + return; +} + +/* Implementations */ +AXIS2_EXTERN void *AXIS2_CALL +rp_property_get_value( + rp_property_t * property, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return property->value; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_property_set_value( + rp_property_t * property, + const axutil_env_t * env, + void *value, + rp_property_type_t type) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + + property->type = type; + + if(type == RP_PROPERTY_X509_TOKEN) + { + rp_x509_token_increment_ref((rp_x509_token_t *)value, env); + } + else if(type == RP_PROPERTY_SECURITY_CONTEXT_TOKEN) + { + rp_security_context_token_increment_ref((rp_security_context_token_t *)value, env); + } + else if(type == RP_PROPERTY_WSS10) + { + rp_wss10_increment_ref((rp_wss10_t *)value, env); + } + else if(type == RP_PROPERTY_WSS11) + { + rp_wss11_increment_ref((rp_wss11_t *)value, env); + } + else if(type == RP_PROPERTY_USERNAME_TOKEN) + { + rp_username_token_increment_ref((rp_username_token_t *)value, env); + } + + else if(type == RP_PROPERTY_HTTPS_TOKEN) + { + rp_https_token_increment_ref((rp_https_token_t *)value, env); + } + + else if(type == RP_PROPERTY_SIGNED_SUPPORTING_TOKEN) + { + rp_supporting_tokens_increment_ref((rp_supporting_tokens_t *)value, env); + } + else if(type == RP_PROPERTY_SUPPORTING_SUPPORTING_TOKEN) + { + rp_supporting_tokens_increment_ref((rp_supporting_tokens_t *)value, env); + } + else if(type == RP_PROPERTY_SIGNED_ENDORSING_SUPPORTING_TOKEN) + { + rp_supporting_tokens_increment_ref((rp_supporting_tokens_t *)value, env); + } + else if(type == RP_PROPERTY_ENDORSING_SUPPORTING_TOKEN) + { + rp_supporting_tokens_increment_ref((rp_supporting_tokens_t *)value, env); + } + else if(type == RP_PROPERTY_ASYMMETRIC_BINDING) + { + rp_asymmetric_binding_increment_ref((rp_asymmetric_binding_t *)value, env); + } + else if(type == RP_PROPERTY_TRANSPORT_BINDING) + { + rp_transport_binding_increment_ref((rp_transport_binding_t *)value, env); + } + else if(type == RP_PROPERTY_SYMMETRIC_BINDING) + { + rp_symmetric_binding_increment_ref((rp_symmetric_binding_t *)value, env); + } + property->value = (void *)value; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_property_type_t AXIS2_CALL +rp_property_get_type( + rp_property_t * property, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return property->type; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_property_increment_ref( + rp_property_t * property, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + property->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/rampart_config.c b/neethi/src/secpolicy/model/rampart_config.c new file mode 100644 index 0000000..ba8bebd --- /dev/null +++ b/neethi/src/secpolicy/model/rampart_config.c @@ -0,0 +1,446 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_rampart_config_t +{ + axis2_char_t *user; + axis2_char_t *encryption_user; + axis2_char_t *password_callback_class; + axis2_char_t *authenticate_module; + axis2_char_t *replay_detector; + axis2_char_t *sct_provider; + axis2_char_t *password_type; + axis2_char_t *time_to_live; + axis2_char_t *clock_skew_buffer; + axis2_char_t *need_millisecond_precision; + axis2_char_t *receiver_certificate_file; + axis2_char_t *certificate_file; + axis2_char_t *private_key_file; + axis2_char_t *pkcs12_file; + axis2_char_t *rd_val; + int ref; +}; + +AXIS2_EXTERN rp_rampart_config_t *AXIS2_CALL +rp_rampart_config_create( + const axutil_env_t * env) +{ + rp_rampart_config_t *rampart_config = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + rampart_config = (rp_rampart_config_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_rampart_config_t)); + + if(rampart_config == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + rampart_config->user = NULL; + rampart_config->encryption_user = NULL; + rampart_config->password_callback_class = NULL; + rampart_config->private_key_file = NULL; + rampart_config->receiver_certificate_file = NULL; + rampart_config->certificate_file = NULL; + rampart_config->authenticate_module = NULL; + rampart_config->replay_detector = NULL; + rampart_config->sct_provider = NULL; + rampart_config->password_type = NULL; + rampart_config->time_to_live = NULL; + rampart_config->clock_skew_buffer = NULL; + rampart_config->need_millisecond_precision = NULL; + rampart_config->pkcs12_file = NULL; + rampart_config->rd_val = NULL; + rampart_config->ref = 0; + + return rampart_config; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_rampart_config_free( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(rampart_config) + { + if(--(rampart_config->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, rampart_config); + rampart_config = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_user( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->user; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_user( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * user) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, user, AXIS2_FAILURE); + + rampart_config->user = user; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_encryption_user( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->encryption_user; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_encryption_user( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * encryption_user) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encryption_user, AXIS2_FAILURE); + + rampart_config->encryption_user = encryption_user; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_password_callback_class( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->password_callback_class; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_password_callback_class( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * password_callback_class) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, password_callback_class, AXIS2_FAILURE); + + rampart_config->password_callback_class = password_callback_class; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_authenticate_module( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->authenticate_module; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_authenticate_module( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * authenticate_module) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, authenticate_module, AXIS2_FAILURE); + + rampart_config->authenticate_module = authenticate_module; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_replay_detector( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->replay_detector; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_replay_detector( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * replay_detector) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, replay_detector, AXIS2_FAILURE); + + rampart_config->replay_detector = replay_detector; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_sct_provider( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->sct_provider; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_sct_provider( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * sct_module) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, sct_module, AXIS2_FAILURE); + + rampart_config->sct_provider = sct_module; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_password_type( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->password_type; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_password_type( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * password_type) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, password_type, AXIS2_FAILURE); + + rampart_config->password_type = password_type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_private_key_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->private_key_file; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_private_key_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * private_key_file) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, private_key_file, AXIS2_FAILURE); + + rampart_config->private_key_file = private_key_file; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_receiver_certificate_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->receiver_certificate_file; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_receiver_certificate_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * receiver_certificate_file) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, receiver_certificate_file, AXIS2_FAILURE); + + rampart_config->receiver_certificate_file = receiver_certificate_file; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_certificate_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->certificate_file; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_certificate_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * certificate_file) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, certificate_file, AXIS2_FAILURE); + + rampart_config->certificate_file = certificate_file; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_time_to_live( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->time_to_live; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_time_to_live( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * time_to_live) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, time_to_live, AXIS2_FAILURE); + + rampart_config->time_to_live = time_to_live; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_clock_skew_buffer( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + return rampart_config->clock_skew_buffer; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_clock_skew_buffer( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * clock_skew_buffer) +{ + rampart_config->clock_skew_buffer = clock_skew_buffer; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_need_millisecond_precision( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + return rampart_config->need_millisecond_precision; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_need_millisecond_precision( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * need_millisecond_precision) +{ + rampart_config->need_millisecond_precision = need_millisecond_precision; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_pkcs12_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + return rampart_config->pkcs12_file; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_pkcs12_file( + rp_rampart_config_t * rampart_config, + const axutil_env_t *env, + axis2_char_t * pkcs12_file) +{ + if(rampart_config) + { + if(pkcs12_file) + { + rampart_config->pkcs12_file = pkcs12_file; + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; + } + + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_rampart_config_get_rd_val( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return rampart_config->rd_val; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_set_rd_val( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env, + axis2_char_t * rd_val) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, rd_val, AXIS2_FAILURE); + + rampart_config->rd_val = rd_val; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_rampart_config_increment_ref( + rp_rampart_config_t * rampart_config, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + rampart_config->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/saml_token.c b/neethi/src/secpolicy/model/saml_token.c new file mode 100644 index 0000000..ae0f1ea --- /dev/null +++ b/neethi/src/secpolicy/model/saml_token.c @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_saml_token +{ + axis2_char_t *inclusion; + axis2_bool_t derivedkeys; + axis2_bool_t require_key_identifier_reference; + axis2_char_t *token_version_and_type; + int ref; +}; + +AXIS2_EXTERN rp_saml_token_t * AXIS2_CALL +rp_saml_token_create( + const axutil_env_t *env) +{ + rp_saml_token_t * saml_token; + + saml_token = (rp_saml_token_t*)AXIS2_MALLOC(env->allocator, sizeof(rp_saml_token_t)); + + if(saml_token == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + saml_token->inclusion = NULL; + saml_token->derivedkeys = AXIS2_FALSE; + saml_token->require_key_identifier_reference = AXIS2_FALSE; + saml_token->token_version_and_type = NULL; + saml_token->ref = 0; + + return saml_token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_saml_token_free( + rp_saml_token_t *saml_token, + const axutil_env_t *env) +{ + if(saml_token) + { + if(--(saml_token->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, saml_token); + saml_token = NULL; + } + + return; +} + +AXIS2_EXTERN axis2_char_t * AXIS2_CALL +rp_saml_token_get_inclusion( + rp_saml_token_t *saml_token, + const axutil_env_t *env) +{ + return saml_token->inclusion; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_saml_token_set_inclusion( + rp_saml_token_t *saml_token, + const axutil_env_t *env, + axis2_char_t * inclusion) +{ + AXIS2_PARAM_CHECK(env->error, inclusion, AXIS2_FAILURE); + saml_token->inclusion = inclusion; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_saml_token_get_derivedkeys( + rp_saml_token_t *saml_token, + const axutil_env_t *env) +{ + return saml_token->derivedkeys; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_saml_token_set_derivedkeys( + rp_saml_token_t *saml_token, + const axutil_env_t *env, + axis2_bool_t derivedkeys) +{ + AXIS2_PARAM_CHECK(env->error, derivedkeys, AXIS2_FAILURE); + saml_token->derivedkeys = derivedkeys; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_saml_token_get_require_key_identifier_reference( + rp_saml_token_t * saml_token, + const axutil_env_t * env) +{ + return saml_token->require_key_identifier_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_saml_token_set_require_key_identifier_reference( + rp_saml_token_t * saml_token, + const axutil_env_t * env, + axis2_bool_t require_key_identifier_reference) +{ + AXIS2_PARAM_CHECK(env->error, require_key_identifier_reference, AXIS2_FAILURE); + saml_token->require_key_identifier_reference = require_key_identifier_reference; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_saml_token_get_token_version_and_type( + rp_saml_token_t * saml_token, + const axutil_env_t * env) +{ + return saml_token->token_version_and_type; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_saml_token_set_token_version_and_type( + rp_saml_token_t * saml_token, + const axutil_env_t * env, + axis2_char_t * token_version_and_type) +{ + AXIS2_PARAM_CHECK(env->error, token_version_and_type, AXIS2_FAILURE); + + saml_token->token_version_and_type = token_version_and_type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_saml_token_increment_ref( + rp_saml_token_t * saml_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + saml_token->ref++; + return AXIS2_SUCCESS; +} + diff --git a/neethi/src/secpolicy/model/secpolicy.c b/neethi/src/secpolicy/model/secpolicy.c new file mode 100644 index 0000000..fdd112c --- /dev/null +++ b/neethi/src/secpolicy/model/secpolicy.c @@ -0,0 +1,493 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_secpolicy_t +{ + rp_property_t *binding; + rp_property_t *wss; + rp_trust10_t *trust10; + rp_supporting_tokens_t *supporting_tokens; + rp_supporting_tokens_t *signed_supporting_tokens; + rp_supporting_tokens_t *endorsing_supporting_tokens; + rp_supporting_tokens_t *signed_endorsing_supporting_tokens; + rp_signed_encrypted_parts_t *signed_parts; + rp_signed_encrypted_parts_t *encrypted_parts; + rp_signed_encrypted_elements_t *signed_elements; + rp_signed_encrypted_elements_t *encrypted_elements; + rp_signed_encrypted_items_t *signed_items; + rp_signed_encrypted_items_t *encrypted_items; + rp_rampart_config_t *rampart_config; + +}; + +AXIS2_EXTERN rp_secpolicy_t *AXIS2_CALL +rp_secpolicy_create( + const axutil_env_t * env) +{ + rp_secpolicy_t *secpolicy = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + secpolicy = (rp_secpolicy_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_secpolicy_t)); + + if(secpolicy == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + secpolicy->binding = NULL; + secpolicy->wss = NULL; + secpolicy->trust10 = NULL; + secpolicy->supporting_tokens = NULL; + secpolicy->signed_supporting_tokens = NULL; + secpolicy->endorsing_supporting_tokens = NULL; + secpolicy->signed_endorsing_supporting_tokens = NULL; + secpolicy->signed_parts = NULL; + secpolicy->encrypted_parts = NULL; + secpolicy->signed_elements = NULL; + secpolicy->encrypted_elements = NULL; + secpolicy->signed_items = NULL; + secpolicy->encrypted_items = NULL; + secpolicy->rampart_config = NULL; + + return secpolicy; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_secpolicy_free( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(secpolicy) + { + if(secpolicy->binding) + { + rp_property_free(secpolicy->binding, env); + secpolicy->binding = NULL; + } + if(secpolicy->wss) + { + rp_property_free(secpolicy->wss, env); + secpolicy->wss = NULL; + } + if(secpolicy->trust10) + { + rp_trust10_free(secpolicy->trust10, env); + secpolicy->trust10 = NULL; + } + if(secpolicy->supporting_tokens) + { + rp_supporting_tokens_free(secpolicy->supporting_tokens, env); + secpolicy->supporting_tokens = NULL; + } + if(secpolicy->signed_supporting_tokens) + { + rp_supporting_tokens_free(secpolicy->signed_supporting_tokens, env); + secpolicy->signed_supporting_tokens = NULL; + } + if(secpolicy->endorsing_supporting_tokens) + { + rp_supporting_tokens_free(secpolicy->endorsing_supporting_tokens, env); + secpolicy->endorsing_supporting_tokens = NULL; + } + if(secpolicy->signed_endorsing_supporting_tokens) + { + rp_supporting_tokens_free(secpolicy-> signed_endorsing_supporting_tokens, env); + secpolicy->signed_endorsing_supporting_tokens = NULL; + } + if(secpolicy->signed_parts) + { + rp_signed_encrypted_parts_free(secpolicy->signed_parts, env); + secpolicy->signed_parts = NULL; + } + if(secpolicy->encrypted_parts) + { + rp_signed_encrypted_parts_free(secpolicy->encrypted_parts, env); + secpolicy->encrypted_parts = NULL; + } + if(secpolicy->signed_elements) + { + rp_signed_encrypted_elements_free(secpolicy->signed_elements, env); + secpolicy->signed_elements = NULL; + } + if(secpolicy->encrypted_elements) + { + rp_signed_encrypted_elements_free(secpolicy->encrypted_elements, env); + secpolicy->encrypted_elements = NULL; + } + if(secpolicy->signed_items) + { + rp_signed_encrypted_items_free(secpolicy->signed_items, env); + secpolicy->signed_items = NULL; + } + if(secpolicy->encrypted_items) + { + rp_signed_encrypted_items_free(secpolicy->encrypted_items, env); + secpolicy->encrypted_items = NULL; + } + if(secpolicy->rampart_config) + { + rp_rampart_config_free(secpolicy->rampart_config, env); + secpolicy->rampart_config = NULL; + } + AXIS2_FREE(env->allocator, secpolicy); + } + + return; +} + +/* Implementations */ +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_secpolicy_get_binding( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->binding; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_binding( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_property_t * binding) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, binding, AXIS2_FAILURE); + rp_property_increment_ref(binding, env); + secpolicy->binding = binding; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_supporting_tokens_t * supporting_tokens) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, supporting_tokens, AXIS2_FAILURE); + + rp_supporting_tokens_increment_ref(supporting_tokens, env); + secpolicy->supporting_tokens = supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_secpolicy_get_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_signed_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_supporting_tokens_t * signed_supporting_tokens) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_supporting_tokens, AXIS2_FAILURE); + + rp_supporting_tokens_increment_ref(signed_supporting_tokens, env); + secpolicy->signed_supporting_tokens = signed_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_secpolicy_get_signed_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->signed_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_endorsing_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_supporting_tokens_t * endorsing_supporting_tokens) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, endorsing_supporting_tokens, AXIS2_FAILURE); + + rp_supporting_tokens_increment_ref(endorsing_supporting_tokens, env); + secpolicy->endorsing_supporting_tokens = endorsing_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_secpolicy_get_endorsing_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->endorsing_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_signed_endorsing_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_supporting_tokens_t * signed_endorsing_supporting_tokens) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_endorsing_supporting_tokens, AXIS2_FAILURE); + + rp_supporting_tokens_increment_ref(signed_endorsing_supporting_tokens, env); + secpolicy->signed_endorsing_supporting_tokens = signed_endorsing_supporting_tokens; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_secpolicy_get_signed_endorsing_supporting_tokens( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->signed_endorsing_supporting_tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_signed_parts( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_parts_t * signed_parts) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_parts, AXIS2_FAILURE); + rp_signed_encrypted_parts_increment_ref(signed_parts, env); + secpolicy->signed_parts = signed_parts; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_signed_encrypted_parts_t *AXIS2_CALL +rp_secpolicy_get_signed_parts( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->signed_parts; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_encrypted_parts( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_parts_t * encrypted_parts) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encrypted_parts, AXIS2_FAILURE); + + rp_signed_encrypted_parts_increment_ref(encrypted_parts, env); + secpolicy->encrypted_parts = encrypted_parts; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_signed_encrypted_parts_t *AXIS2_CALL +rp_secpolicy_get_encrypted_parts( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->encrypted_parts; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_signed_elements( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_elements_t * signed_elements) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_elements, AXIS2_FAILURE); + + rp_signed_encrypted_elements_increment_ref(signed_elements, env); + secpolicy->signed_elements = signed_elements; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_signed_encrypted_elements_t *AXIS2_CALL +rp_secpolicy_get_signed_elements( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->signed_elements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_encrypted_elements( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_elements_t * encrypted_elements) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encrypted_elements, AXIS2_FAILURE); + + rp_signed_encrypted_elements_increment_ref(encrypted_elements, env); + secpolicy->encrypted_elements = encrypted_elements; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_elements_t *AXIS2_CALL +rp_secpolicy_get_encrypted_elements( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->encrypted_elements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_signed_items( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_items_t * signed_items) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_items, AXIS2_FAILURE); + + secpolicy->signed_items = signed_items; + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_signed_encrypted_items_t *AXIS2_CALL +rp_secpolicy_get_signed_items( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->signed_items; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_encrypted_items( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_signed_encrypted_items_t * encrypted_items) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encrypted_items, AXIS2_FAILURE); + + secpolicy->encrypted_items = encrypted_items; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_items_t *AXIS2_CALL +rp_secpolicy_get_encrypted_items( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->encrypted_items; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_wss( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_property_t * wss) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, wss, AXIS2_FAILURE); + + rp_property_increment_ref(wss, env); + secpolicy->wss = wss; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_secpolicy_get_wss( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->wss; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_trust10( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_trust10_t * trust10) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, trust10, AXIS2_FAILURE); + + rp_trust10_increment_ref(trust10, env); + secpolicy->trust10 = trust10; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_trust10_t *AXIS2_CALL +rp_secpolicy_get_trust10( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->trust10; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_secpolicy_set_rampart_config( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env, + rp_rampart_config_t * rampart_config) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, rampart_config, AXIS2_FAILURE); + + rp_rampart_config_increment_ref(rampart_config, env); + secpolicy->rampart_config = rampart_config; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_rampart_config_t *AXIS2_CALL +rp_secpolicy_get_rampart_config( + rp_secpolicy_t * secpolicy, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return secpolicy->rampart_config; +} diff --git a/neethi/src/secpolicy/model/security_context_token.c b/neethi/src/secpolicy/model/security_context_token.c new file mode 100644 index 0000000..9b00465 --- /dev/null +++ b/neethi/src/secpolicy/model/security_context_token.c @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_security_context_token_t +{ + rp_token_t *token; + axis2_bool_t require_external_uri_ref; + axis2_bool_t sc10_security_context_token; + neethi_policy_t *bootstrap_policy; + axis2_bool_t is_secure_conversation_token; + int ref; +}; + +AXIS2_EXTERN rp_security_context_token_t *AXIS2_CALL +rp_security_context_token_create( + const axutil_env_t * env) +{ + rp_security_context_token_t *security_context_token = NULL; + + security_context_token = (rp_security_context_token_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_security_context_token_t)); + + if(!security_context_token) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Security context token assertion creation failed. Insufficient memory"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + security_context_token->ref = 0; + security_context_token->require_external_uri_ref = AXIS2_FALSE; + security_context_token->sc10_security_context_token = AXIS2_FALSE; + security_context_token->bootstrap_policy = NULL; + security_context_token->is_secure_conversation_token = AXIS2_FALSE; + + security_context_token->token = rp_token_create(env); + if(!security_context_token->token) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Security context token assertion creation failed."); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + rp_security_context_token_free(security_context_token, env); + return NULL; + } + + return security_context_token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_security_context_token_free( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + if(security_context_token) + { + if(--(security_context_token->ref) > 0) + { + return; + } + + if(security_context_token->bootstrap_policy) + { + neethi_policy_free(security_context_token->bootstrap_policy, env); + } + + rp_token_free(security_context_token->token, env); + AXIS2_FREE(env->allocator, security_context_token); + security_context_token = NULL; + } +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_security_context_token_get_inclusion( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + return rp_token_get_inclusion(security_context_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_inclusion( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + axis2_char_t * inclusion) +{ + return rp_token_set_inclusion(security_context_token->token, env, inclusion); +} + +AXIS2_EXTERN derive_key_type_t AXIS2_CALL +rp_security_context_token_get_derivedkey( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + return rp_token_get_derivedkey_type(security_context_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_derivedkey( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + derive_key_type_t derivedkey) +{ + return rp_token_set_derivedkey_type(security_context_token->token, env, derivedkey); +} + +AXIS2_EXTERN derive_key_version_t AXIS2_CALL +rp_security_context_token_get_derivedkey_version( + rp_security_context_token_t *security_context_token, + const axutil_env_t *env) +{ + return rp_token_get_derive_key_version(security_context_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_derivedkey_version( + rp_security_context_token_t *security_context_token, + const axutil_env_t *env, + derive_key_version_t version) +{ + return rp_token_set_derive_key_version(security_context_token->token, env, version); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_security_context_token_get_require_external_uri_ref( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + return security_context_token->require_external_uri_ref; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_require_external_uri_ref( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + axis2_bool_t require_external_uri_ref) +{ + security_context_token->require_external_uri_ref = require_external_uri_ref; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_security_context_token_get_sc10_security_context_token( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + return security_context_token->sc10_security_context_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_sc10_security_context_token( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + axis2_bool_t sc10_security_context_token) +{ + security_context_token->sc10_security_context_token = sc10_security_context_token; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_security_context_token_get_issuer( + rp_security_context_token_t *security_context_token, + const axutil_env_t *env) +{ + return rp_token_get_issuer(security_context_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_issuer( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + axis2_char_t *issuer) +{ + return rp_token_set_issuer(security_context_token->token, env, issuer); +} + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +rp_security_context_token_get_bootstrap_policy( + rp_security_context_token_t *security_context_token, + const axutil_env_t *env) +{ + return security_context_token->bootstrap_policy; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_bootstrap_policy( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + neethi_policy_t *bootstrap_policy) +{ + security_context_token->bootstrap_policy = bootstrap_policy; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_security_context_token_get_is_secure_conversation_token( + rp_security_context_token_t *security_context_token, + const axutil_env_t *env) +{ + return security_context_token->is_secure_conversation_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_set_is_secure_conversation_token( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env, + axis2_bool_t is_secure_conversation_token) +{ + security_context_token->is_secure_conversation_token = is_secure_conversation_token; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_security_context_token_increment_ref( + rp_security_context_token_t * security_context_token, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + security_context_token->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/signed_encrypted_elements.c b/neethi/src/secpolicy/model/signed_encrypted_elements.c new file mode 100644 index 0000000..b656f0f --- /dev/null +++ b/neethi/src/secpolicy/model/signed_encrypted_elements.c @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_signed_encrypted_elements_t +{ + axis2_bool_t signedelements; + axutil_array_list_t *xpath_expressions; + axis2_char_t *xpath_version; + int ref; + +}; + +AXIS2_EXTERN rp_signed_encrypted_elements_t *AXIS2_CALL +rp_signed_encrypted_elements_create( + const axutil_env_t * env) +{ + rp_signed_encrypted_elements_t *signed_encrypted_elements = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + signed_encrypted_elements = (rp_signed_encrypted_elements_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_signed_encrypted_elements_t)); + + if(signed_encrypted_elements == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + signed_encrypted_elements->xpath_expressions = NULL; + + signed_encrypted_elements->xpath_expressions = axutil_array_list_create(env, 0); + if(!(signed_encrypted_elements->xpath_expressions)) + { + rp_signed_encrypted_elements_free(signed_encrypted_elements, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + signed_encrypted_elements->xpath_version = NULL; + signed_encrypted_elements->ref = 0; + + return signed_encrypted_elements; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_signed_encrypted_elements_free( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(signed_encrypted_elements) + { + if(--(signed_encrypted_elements->ref) > 0) + { + return; + } + + if(signed_encrypted_elements->xpath_expressions) + { + int i = 0; + for(i = 0; i < axutil_array_list_size(signed_encrypted_elements-> xpath_expressions, + env); i++) + { + axis2_char_t *expression = NULL; + expression = (axis2_char_t *)axutil_array_list_get( + signed_encrypted_elements-> xpath_expressions, env, i); + if(expression) + AXIS2_FREE(env->allocator, expression); + + expression = NULL; + } + axutil_array_list_free(signed_encrypted_elements->xpath_expressions, env); + signed_encrypted_elements->xpath_expressions = NULL; + + } + AXIS2_FREE(env->allocator, signed_encrypted_elements); + signed_encrypted_elements = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_signed_encrypted_elements_get_signedelements( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return signed_encrypted_elements->signedelements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_elements_set_signedelements( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env, + axis2_bool_t signedelements) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signedelements, AXIS2_FAILURE); + + signed_encrypted_elements->signedelements = signedelements; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +rp_signed_encrypted_elements_get_xpath_expressions( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return signed_encrypted_elements->xpath_expressions; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_elements_add_expression( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env, + axis2_char_t * expression) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, expression, AXIS2_FAILURE); + + axutil_array_list_add(signed_encrypted_elements->xpath_expressions, env, expression); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_signed_encrypted_elements_get_xpath_version( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return signed_encrypted_elements->xpath_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_elements_set_xpath_version( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env, + axis2_char_t * xpath_version) +{ + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, xpath_version, AXIS2_FAILURE); + + signed_encrypted_elements->xpath_version = xpath_version; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_elements_increment_ref( + rp_signed_encrypted_elements_t * signed_encrypted_elements, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + signed_encrypted_elements->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/signed_encrypted_items.c b/neethi/src/secpolicy/model/signed_encrypted_items.c new file mode 100644 index 0000000..e3e6150 --- /dev/null +++ b/neethi/src/secpolicy/model/signed_encrypted_items.c @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_signed_encrypted_items_t +{ + axis2_bool_t signeditems; + axutil_array_list_t *elements; + +}; + +AXIS2_EXTERN rp_signed_encrypted_items_t *AXIS2_CALL +rp_signed_encrypted_items_create( + const axutil_env_t * env) +{ + rp_signed_encrypted_items_t *signed_encrypted_items = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + signed_encrypted_items = (rp_signed_encrypted_items_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_signed_encrypted_items_t)); + + if(signed_encrypted_items == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + signed_encrypted_items->elements = NULL; + + signed_encrypted_items->elements = axutil_array_list_create(env, 0); + if(!(signed_encrypted_items->elements)) + { + rp_signed_encrypted_items_free(signed_encrypted_items, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + return signed_encrypted_items; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_signed_encrypted_items_free( + rp_signed_encrypted_items_t * signed_encrypted_items, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(signed_encrypted_items) + { + + if(signed_encrypted_items->elements) + { + int i = 0; + for(i = 0; i < axutil_array_list_size(signed_encrypted_items->elements, env); i++) + { + rp_element_t *element = NULL; + element = (rp_element_t *)axutil_array_list_get(signed_encrypted_items->elements, + env, i); + if(element) + rp_element_free(element, env); + + element = NULL; + } + axutil_array_list_free(signed_encrypted_items->elements, env); + signed_encrypted_items->elements = NULL; + + } + AXIS2_FREE(env->allocator, signed_encrypted_items); + signed_encrypted_items = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_signed_encrypted_items_get_signeditems( + rp_signed_encrypted_items_t * signed_encrypted_items, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return signed_encrypted_items->signeditems; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_items_set_signeditems( + rp_signed_encrypted_items_t * signed_encrypted_items, + const axutil_env_t * env, + axis2_bool_t signeditems) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signeditems, AXIS2_FAILURE); + signed_encrypted_items->signeditems = signeditems; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +rp_signed_encrypted_items_get_elements( + rp_signed_encrypted_items_t * signed_encrypted_items, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return signed_encrypted_items->elements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_items_add_element( + rp_signed_encrypted_items_t * signed_encrypted_items, + const axutil_env_t * env, + rp_element_t * element) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, element, AXIS2_FAILURE); + + axutil_array_list_add(signed_encrypted_items->elements, env, element); + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/signed_encrypted_parts.c b/neethi/src/secpolicy/model/signed_encrypted_parts.c new file mode 100644 index 0000000..0f16e83 --- /dev/null +++ b/neethi/src/secpolicy/model/signed_encrypted_parts.c @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_signed_encrypted_parts_t +{ + axis2_bool_t body; + axis2_bool_t signedparts; + axis2_bool_t attachments; + axutil_array_list_t *headers; + int ref; +}; + +AXIS2_EXTERN rp_signed_encrypted_parts_t *AXIS2_CALL +rp_signed_encrypted_parts_create( + const axutil_env_t * env) +{ + rp_signed_encrypted_parts_t *signed_encrypted_parts = NULL; + signed_encrypted_parts = (rp_signed_encrypted_parts_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_signed_encrypted_parts_t)); + + if(!signed_encrypted_parts) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot create signed_encrypted_parts. Insuficient memory."); + return NULL; + } + + signed_encrypted_parts->headers = axutil_array_list_create(env, 0); + if(!signed_encrypted_parts->headers) + { + rp_signed_encrypted_parts_free(signed_encrypted_parts, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Cannot create signed_encrypted_parts. Headers array list creation failed."); + return NULL; + } + + signed_encrypted_parts->body = AXIS2_FALSE; + signed_encrypted_parts->ref = 0; + signed_encrypted_parts->signedparts = AXIS2_FALSE; + signed_encrypted_parts->attachments = AXIS2_FALSE; + return signed_encrypted_parts; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_signed_encrypted_parts_free( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + if(signed_encrypted_parts) + { + if(--(signed_encrypted_parts->ref) > 0) + { + return; + } + + if(signed_encrypted_parts->headers) + { + int i = 0; + for(i = 0; i < axutil_array_list_size(signed_encrypted_parts->headers, env); i++) + { + rp_header_t *header = NULL; + header = (rp_header_t *)axutil_array_list_get(signed_encrypted_parts->headers, env, + i); + if(header) + { + rp_header_free(header, env); + } + } + axutil_array_list_free(signed_encrypted_parts->headers, env); + signed_encrypted_parts->headers = NULL; + } + AXIS2_FREE(env->allocator, signed_encrypted_parts); + signed_encrypted_parts = NULL; + } +} + +/* Implementations */ + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_signed_encrypted_parts_get_body( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + return signed_encrypted_parts->body; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_set_body( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env, + axis2_bool_t body) +{ + AXIS2_PARAM_CHECK(env->error, body, AXIS2_FAILURE); + signed_encrypted_parts->body = body; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_signed_encrypted_parts_get_signedparts( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + return signed_encrypted_parts->signedparts; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_set_signedparts( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env, + axis2_bool_t signedparts) +{ + signed_encrypted_parts->signedparts = signedparts; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +rp_signed_encrypted_parts_get_headers( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + return signed_encrypted_parts->headers; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_add_header( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env, + rp_header_t * header) +{ + AXIS2_PARAM_CHECK(env->error, header, AXIS2_FAILURE); + axutil_array_list_add(signed_encrypted_parts->headers, env, header); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_increment_ref( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + signed_encrypted_parts->ref++; + return AXIS2_SUCCESS; +} +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_signed_encrypted_parts_get_attachments( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env) +{ + return signed_encrypted_parts->attachments; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_signed_encrypted_parts_set_attachments( + rp_signed_encrypted_parts_t * signed_encrypted_parts, + const axutil_env_t * env, + axis2_bool_t attachments) +{ + signed_encrypted_parts->attachments = attachments; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/supporting_tokens.c b/neethi/src/secpolicy/model/supporting_tokens.c new file mode 100644 index 0000000..7ec2d7f --- /dev/null +++ b/neethi/src/secpolicy/model/supporting_tokens.c @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_supporting_tokens_t +{ + rp_algorithmsuite_t *algorithmsuite; + axutil_array_list_t *tokens; + rp_signed_encrypted_elements_t *signed_elements; + rp_signed_encrypted_parts_t *signed_parts; + rp_signed_encrypted_elements_t *encrypted_elements; + rp_signed_encrypted_parts_t *encrypted_parts; + int type; + int ref; +}; + +AXIS2_EXTERN rp_supporting_tokens_t *AXIS2_CALL +rp_supporting_tokens_create( + const axutil_env_t * env) +{ + rp_supporting_tokens_t *supporting_tokens = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + supporting_tokens = (rp_supporting_tokens_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_supporting_tokens_t)); + + if(supporting_tokens == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + supporting_tokens->tokens = NULL; + supporting_tokens->tokens = axutil_array_list_create(env, 0); + if(!(supporting_tokens->tokens)) + { + rp_supporting_tokens_free(supporting_tokens, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + supporting_tokens->algorithmsuite = NULL; + supporting_tokens->signed_parts = NULL; + supporting_tokens->signed_elements = NULL; + supporting_tokens->encrypted_parts = NULL; + supporting_tokens->encrypted_elements = NULL; + supporting_tokens->type = 0; + supporting_tokens->ref = 0; + return supporting_tokens; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_supporting_tokens_free( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(supporting_tokens) + { + + if(--(supporting_tokens->ref) > 0) + { + return; + } + + if(supporting_tokens->tokens) + { + int i = 0; + for(i = 0; i < axutil_array_list_size(supporting_tokens->tokens, env); i++) + { + rp_property_t *token = NULL; + token = (rp_property_t *)axutil_array_list_get(supporting_tokens->tokens, env, i); + if(token) + rp_property_free(token, env); + + token = NULL; + } + axutil_array_list_free(supporting_tokens->tokens, env); + supporting_tokens->tokens = NULL; + + } + if(supporting_tokens->algorithmsuite) + { + rp_algorithmsuite_free(supporting_tokens->algorithmsuite, env); + supporting_tokens->algorithmsuite = NULL; + } + if(supporting_tokens->signed_parts) + { + rp_signed_encrypted_parts_free(supporting_tokens->signed_parts, env); + supporting_tokens->signed_parts = NULL; + } + if(supporting_tokens->signed_elements) + { + rp_signed_encrypted_elements_free(supporting_tokens-> signed_elements, env); + supporting_tokens->signed_elements = NULL; + } + if(supporting_tokens->encrypted_parts) + { + rp_signed_encrypted_parts_free(supporting_tokens->encrypted_parts, env); + supporting_tokens->encrypted_parts = NULL; + } + if(supporting_tokens->encrypted_elements) + { + rp_signed_encrypted_elements_free(supporting_tokens-> encrypted_elements, env); + supporting_tokens->encrypted_elements = NULL; + } + AXIS2_FREE(env->allocator, supporting_tokens); + supporting_tokens = NULL; + } + return; +} + +/* Implementations */ + +AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL +rp_supporting_tokens_get_tokens( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return supporting_tokens->tokens; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_add_token( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_property_t * token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, token, AXIS2_FAILURE); + + rp_property_increment_ref(token, env); + axutil_array_list_add(supporting_tokens->tokens, env, token); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_algorithmsuite_t *AXIS2_CALL +rp_supporting_tokens_get_algorithmsuite( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return supporting_tokens->algorithmsuite; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_algorithmsuite( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_algorithmsuite_t * algorithmsuite) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, algorithmsuite, AXIS2_FAILURE); + + rp_algorithmsuite_increment_ref(algorithmsuite, env); + supporting_tokens->algorithmsuite = algorithmsuite; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_parts_t *AXIS2_CALL +rp_supporting_tokens_get_signed_parts( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return supporting_tokens->signed_parts; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_signed_parts( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_signed_encrypted_parts_t * signed_parts) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_parts, AXIS2_FAILURE); + + supporting_tokens->signed_parts = signed_parts; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_elements_t *AXIS2_CALL +rp_supporting_tokens_get_signed_elements( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return supporting_tokens->signed_elements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_signed_elements( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_signed_encrypted_elements_t * signed_elements) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signed_elements, AXIS2_FAILURE); + + supporting_tokens->signed_elements = signed_elements; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_parts_t *AXIS2_CALL +rp_supporting_tokens_get_encrypted_parts( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return supporting_tokens->encrypted_parts; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_encrypted_parts( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_signed_encrypted_parts_t * encrypted_parts) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encrypted_parts, AXIS2_FAILURE); + + supporting_tokens->encrypted_parts = encrypted_parts; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_signed_encrypted_elements_t *AXIS2_CALL +rp_supporting_tokens_get_encrypted_elements( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return supporting_tokens->encrypted_elements; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_encrypted_elements( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + rp_signed_encrypted_elements_t * encrypted_elements) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encrypted_elements, AXIS2_FAILURE); + + supporting_tokens->encrypted_elements = encrypted_elements; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN int AXIS2_CALL +rp_supporting_tokens_get_type( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + return supporting_tokens->type; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_set_type( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env, + int type) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + supporting_tokens->type = type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_supporting_tokens_increment_ref( + rp_supporting_tokens_t * supporting_tokens, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + supporting_tokens->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/symmetric_asymmetric_binding_commons.c b/neethi/src/secpolicy/model/symmetric_asymmetric_binding_commons.c new file mode 100644 index 0000000..06a4188 --- /dev/null +++ b/neethi/src/secpolicy/model/symmetric_asymmetric_binding_commons.c @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_symmetric_asymmetric_binding_commons_t +{ + rp_binding_commons_t *binding_commons; + axis2_char_t *protection_order; + axis2_bool_t signature_protection; + axis2_bool_t token_protection; + axis2_bool_t entire_headers_and_body_signatures; + +}; + +AXIS2_EXTERN rp_symmetric_asymmetric_binding_commons_t *AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_create( + const axutil_env_t * env) +{ + rp_symmetric_asymmetric_binding_commons_t *symmetric_asymmetric_binding_commons = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + symmetric_asymmetric_binding_commons + = (rp_symmetric_asymmetric_binding_commons_t *)AXIS2_MALLOC(env-> allocator, + sizeof(rp_symmetric_asymmetric_binding_commons_t)); + + if(symmetric_asymmetric_binding_commons == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + symmetric_asymmetric_binding_commons->binding_commons = NULL; + symmetric_asymmetric_binding_commons->protection_order = RP_SIGN_BEFORE_ENCRYPTING; + symmetric_asymmetric_binding_commons->signature_protection = AXIS2_FALSE; + symmetric_asymmetric_binding_commons->token_protection = AXIS2_FALSE; + symmetric_asymmetric_binding_commons->entire_headers_and_body_signatures = AXIS2_FALSE; + + return symmetric_asymmetric_binding_commons; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_free( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(symmetric_asymmetric_binding_commons) + { + if(symmetric_asymmetric_binding_commons->binding_commons) + { + rp_binding_commons_free(symmetric_asymmetric_binding_commons-> binding_commons, env); + symmetric_asymmetric_binding_commons->binding_commons = NULL; + } + AXIS2_FREE(env->allocator, symmetric_asymmetric_binding_commons); + symmetric_asymmetric_binding_commons = NULL; + } + return; +} + +/* Implementations */ +AXIS2_EXTERN rp_binding_commons_t *AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_get_binding_commons( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_asymmetric_binding_commons->binding_commons; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_set_binding_commons( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env, + rp_binding_commons_t * binding_commons) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, binding_commons, AXIS2_FAILURE); + + symmetric_asymmetric_binding_commons->binding_commons = binding_commons; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_get_signature_protection( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return symmetric_asymmetric_binding_commons->signature_protection; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_set_signature_protection( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env, + axis2_bool_t signature_protection) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signature_protection, AXIS2_FAILURE); + symmetric_asymmetric_binding_commons->signature_protection = signature_protection; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_get_token_protection( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return symmetric_asymmetric_binding_commons->token_protection; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_set_token_protection( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env, + axis2_bool_t token_protection) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, token_protection, AXIS2_FAILURE); + + symmetric_asymmetric_binding_commons->token_protection = token_protection; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_get_entire_headers_and_body_signatures( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return symmetric_asymmetric_binding_commons-> entire_headers_and_body_signatures; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_set_entire_headers_and_body_signatures( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env, + axis2_bool_t entire_headers_and_body_signatures) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, entire_headers_and_body_signatures, AXIS2_FAILURE); + + symmetric_asymmetric_binding_commons->entire_headers_and_body_signatures + = entire_headers_and_body_signatures; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_get_protection_order( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_asymmetric_binding_commons->protection_order; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_asymmetric_binding_commons_set_protection_order( + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons, + const axutil_env_t * env, + axis2_char_t * protection_order) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, protection_order, AXIS2_FAILURE); + + symmetric_asymmetric_binding_commons->protection_order = protection_order; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/symmetric_binding.c b/neethi/src/secpolicy/model/symmetric_binding.c new file mode 100644 index 0000000..4d6dc2d --- /dev/null +++ b/neethi/src/secpolicy/model/symmetric_binding.c @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_symmetric_binding_t +{ + rp_symmetric_asymmetric_binding_commons_t *symmetric_asymmetric_binding_commons; + rp_property_t *protection_token; + rp_property_t *signature_token; + rp_property_t *encryption_token; + int ref; +}; + +AXIS2_EXTERN rp_symmetric_binding_t *AXIS2_CALL +rp_symmetric_binding_create( + const axutil_env_t * env) +{ + rp_symmetric_binding_t *symmetric_binding = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + symmetric_binding = (rp_symmetric_binding_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_symmetric_binding_t)); + + if(symmetric_binding == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + symmetric_binding->symmetric_asymmetric_binding_commons = NULL; + symmetric_binding->protection_token = NULL; + symmetric_binding->signature_token = NULL; + symmetric_binding->encryption_token = NULL; + symmetric_binding->ref = 0; + + return symmetric_binding; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_symmetric_binding_free( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(symmetric_binding) + { + if(--(symmetric_binding->ref) > 0) + { + return; + } + + if(symmetric_binding->symmetric_asymmetric_binding_commons) + { + rp_symmetric_asymmetric_binding_commons_free( + symmetric_binding-> symmetric_asymmetric_binding_commons, env); + symmetric_binding->symmetric_asymmetric_binding_commons = NULL; + } + if(symmetric_binding->protection_token) + { + rp_property_free(symmetric_binding->protection_token, env); + symmetric_binding->protection_token = NULL; + } + if(symmetric_binding->encryption_token) + { + rp_property_free(symmetric_binding->encryption_token, env); + symmetric_binding->encryption_token = NULL; + } + if(symmetric_binding->signature_token) + { + rp_property_free(symmetric_binding->signature_token, env); + symmetric_binding->signature_token = NULL; + } + AXIS2_FREE(env->allocator, symmetric_binding); + } + + return; +} + +/* Implementations */ + +AXIS2_EXTERN rp_symmetric_asymmetric_binding_commons_t *AXIS2_CALL +rp_symmetric_binding_get_symmetric_asymmetric_binding_commons( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_binding->symmetric_asymmetric_binding_commons; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_binding_set_symmetric_asymmetric_binding_commons( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env, + rp_symmetric_asymmetric_binding_commons_t * symmetric_asymmetric_binding_commons) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, symmetric_asymmetric_binding_commons, AXIS2_FAILURE); + + symmetric_binding->symmetric_asymmetric_binding_commons = symmetric_asymmetric_binding_commons; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_symmetric_binding_get_protection_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_binding->protection_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_binding_set_protection_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env, + rp_property_t * protection_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, protection_token, AXIS2_FAILURE); + if(symmetric_binding->signature_token || symmetric_binding->encryption_token) + { + return AXIS2_FAILURE; + } + rp_property_increment_ref(protection_token, env); + symmetric_binding->protection_token = protection_token; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_binding_set_encryption_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env, + rp_property_t * encryption_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encryption_token, AXIS2_FAILURE); + if(symmetric_binding->protection_token) + { + return AXIS2_FAILURE; + } + rp_property_increment_ref(encryption_token, env); + symmetric_binding->encryption_token = encryption_token; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_symmetric_binding_get_encryption_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_binding->encryption_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_binding_set_signature_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env, + rp_property_t * signature_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, signature_token, AXIS2_FAILURE); + if(symmetric_binding->protection_token) + { + return AXIS2_FAILURE; + } + rp_property_increment_ref(signature_token, env); + symmetric_binding->signature_token = signature_token; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_symmetric_binding_get_signature_token( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return symmetric_binding->signature_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_symmetric_binding_increment_ref( + rp_symmetric_binding_t * symmetric_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + symmetric_binding->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/token.c b/neethi/src/secpolicy/model/token.c new file mode 100644 index 0000000..ccb80e4 --- /dev/null +++ b/neethi/src/secpolicy/model/token.c @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_token_t +{ + axis2_char_t *issuer; + axis2_char_t *inclusion; + axiom_node_t *claim; + axis2_bool_t is_issuer_name; /* shows whether 'issuer' points to issuer name or end point */ + derive_key_type_t derive_key; + derive_key_version_t derive_key_version; + int ref; +}; + +AXIS2_EXTERN rp_token_t *AXIS2_CALL +rp_token_create( + const axutil_env_t * env) +{ + rp_token_t *token = NULL; + token = (rp_token_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_token_t)); + + if(!token) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] Token creation failed. Insufficient memory"); + return NULL; + } + token->issuer = NULL; + token->is_issuer_name = AXIS2_FALSE; + token->claim = NULL; + token->derive_key = DERIVEKEY_NONE; + token->derive_key_version = DERIVEKEY_VERSION_SC13; + token->inclusion = RP_INCLUDE_ALWAYS_SP12; + token->ref = 0; + + return token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_token_free( + rp_token_t * token, + const axutil_env_t * env) +{ + if(token) + { + if(--(token->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, token); + token = NULL; + } +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_token_get_issuer( + rp_token_t * token, + const axutil_env_t * env) +{ + return token->issuer; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_issuer( + rp_token_t * token, + const axutil_env_t * env, + axis2_char_t * issuer) +{ + token->issuer = issuer; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_derive_key_version( + rp_token_t *token, + const axutil_env_t *env, + derive_key_version_t version) +{ + token->derive_key_version = version; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN derive_key_version_t AXIS2_CALL +rp_token_get_derive_key_version( + rp_token_t *token, + const axutil_env_t *env) +{ + return token->derive_key_version; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_inclusion( + rp_token_t *token, + const axutil_env_t *env, + axis2_char_t *inclusion) +{ + token->inclusion = inclusion; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_token_get_inclusion( + rp_token_t *token, + const axutil_env_t *env) +{ + return token->inclusion; +} + +AXIS2_EXTERN derive_key_type_t AXIS2_CALL +rp_token_get_derivedkey_type( + rp_token_t * token, + const axutil_env_t * env) +{ + return token->derive_key; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_derivedkey_type( + rp_token_t * token, + const axutil_env_t * env, + derive_key_type_t derivedkey) +{ + token->derive_key = derivedkey; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_token_get_is_issuer_name( + rp_token_t * token, + const axutil_env_t * env) +{ + return token->is_issuer_name; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_is_issuer_name( + rp_token_t * token, + const axutil_env_t * env, + axis2_bool_t is_issuer_name) +{ + token->is_issuer_name = is_issuer_name; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +rp_token_get_claim( + rp_token_t * token, + const axutil_env_t * env) +{ + return token->claim; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_set_claim( + rp_token_t * token, + const axutil_env_t * env, + axiom_node_t *claim) +{ + token->claim = claim; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_token_increment_ref( + rp_token_t * token, + const axutil_env_t * env) +{ + token->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/transport_binding.c b/neethi/src/secpolicy/model/transport_binding.c new file mode 100644 index 0000000..cb84fff --- /dev/null +++ b/neethi/src/secpolicy/model/transport_binding.c @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_transport_binding_t +{ + rp_binding_commons_t *binding_commons; + rp_property_t *transport_token; + int ref; +}; + +AXIS2_EXTERN rp_transport_binding_t *AXIS2_CALL +rp_transport_binding_create( + const axutil_env_t * env) +{ + rp_transport_binding_t *transport_binding = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + transport_binding = (rp_transport_binding_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_transport_binding_t)); + + if(transport_binding == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + transport_binding->binding_commons = NULL; + transport_binding->transport_token = NULL; + transport_binding->ref = 0; + + return transport_binding; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_transport_binding_free( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(transport_binding) + { + if(--(transport_binding->ref) > 0) + { + return; + } + if(transport_binding->binding_commons) + { + rp_binding_commons_free(transport_binding->binding_commons, env); + transport_binding->binding_commons = NULL; + } + if(transport_binding->transport_token) + { + rp_property_free(transport_binding->transport_token, env); + transport_binding->transport_token = NULL; + } + AXIS2_FREE(env->allocator, transport_binding); + } + + return; +} + +/* Implementations */ + +AXIS2_EXTERN rp_binding_commons_t *AXIS2_CALL +rp_transport_binding_get_binding_commons( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return transport_binding->binding_commons; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_transport_binding_set_binding_commons( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env, + rp_binding_commons_t * binding_commons) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, binding_commons, AXIS2_FAILURE); + + transport_binding->binding_commons = binding_commons; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN rp_property_t *AXIS2_CALL +rp_transport_binding_get_transport_token( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, NULL); + + return transport_binding->transport_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_transport_binding_set_transport_token( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env, + rp_property_t * transport_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, transport_token, AXIS2_FAILURE); + + rp_property_increment_ref(transport_token, env); + transport_binding->transport_token = transport_token; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_transport_binding_increment_ref( + rp_transport_binding_t * transport_binding, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + transport_binding->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/trust10.c b/neethi/src/secpolicy/model/trust10.c new file mode 100644 index 0000000..54d98c8 --- /dev/null +++ b/neethi/src/secpolicy/model/trust10.c @@ -0,0 +1,201 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_trust10_t +{ + axis2_bool_t must_support_client_challenge; + axis2_bool_t must_support_server_challenge; + axis2_bool_t require_client_entropy; + axis2_bool_t require_server_entropy; + axis2_bool_t must_support_issued_token; + int ref; +}; + +AXIS2_EXTERN rp_trust10_t *AXIS2_CALL +rp_trust10_create( + const axutil_env_t * env) +{ + rp_trust10_t *trust10 = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + trust10 = (rp_trust10_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_trust10_t)); + + if(trust10 == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + trust10->must_support_client_challenge = AXIS2_FALSE; + trust10->must_support_server_challenge = AXIS2_FALSE; + trust10->require_client_entropy = AXIS2_FALSE; + trust10->require_server_entropy = AXIS2_FALSE; + trust10->must_support_issued_token = AXIS2_FALSE; + trust10->ref = 0; + + return trust10; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_trust10_free( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(trust10) + { + if(--(trust10->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, trust10); + trust10 = NULL; + } + return; +} + +/* Implementations */ +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_trust10_get_must_support_client_challenge( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return trust10->must_support_client_challenge; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_set_must_support_client_challenge( + rp_trust10_t * trust10, + const axutil_env_t * env, + axis2_bool_t must_support_client_challenge) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_client_challenge, AXIS2_FAILURE); + trust10->must_support_client_challenge = must_support_client_challenge; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_trust10_get_must_support_server_challenge( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return trust10->must_support_server_challenge; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_set_must_support_server_challenge( + rp_trust10_t * trust10, + const axutil_env_t * env, + axis2_bool_t must_support_server_challenge) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_server_challenge, AXIS2_FAILURE); + trust10->must_support_server_challenge = must_support_server_challenge; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_trust10_get_require_client_entropy( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return trust10->require_client_entropy; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_set_require_client_entropy( + rp_trust10_t * trust10, + const axutil_env_t * env, + axis2_bool_t require_client_entropy) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, require_client_entropy, AXIS2_FAILURE); + trust10->require_client_entropy = require_client_entropy; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_trust10_get_require_server_entropy( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return trust10->require_server_entropy; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_set_require_server_entropy( + rp_trust10_t * trust10, + const axutil_env_t * env, + axis2_bool_t require_server_entropy) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, require_server_entropy, AXIS2_FAILURE); + trust10->require_server_entropy = require_server_entropy; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_trust10_get_must_support_issued_token( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return trust10->must_support_issued_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_set_must_support_issued_token( + rp_trust10_t * trust10, + const axutil_env_t * env, + axis2_bool_t must_support_issued_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_issued_token, AXIS2_FAILURE); + trust10->must_support_issued_token = must_support_issued_token; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_trust10_increment_ref( + rp_trust10_t * trust10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + trust10->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/ut.c b/neethi/src/secpolicy/model/ut.c new file mode 100644 index 0000000..867e5c1 --- /dev/null +++ b/neethi/src/secpolicy/model/ut.c @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +struct rp_username_token_t +{ + axis2_char_t *inclusion; + password_type_t password_type; + axis2_bool_t useUTprofile10; + axis2_bool_t useUTprofile11; + rp_token_t *token; + int ref; +}; + +AXIS2_EXTERN rp_username_token_t *AXIS2_CALL +rp_username_token_create( + const axutil_env_t * env) +{ + rp_username_token_t *username_token = NULL; + username_token = (rp_username_token_t *)AXIS2_MALLOC(env->allocator, + sizeof(rp_username_token_t)); + + if(!username_token) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] User name token creation failed. Insufficient memory"); + return NULL; + } + + username_token->token = rp_token_create(env); + if(!username_token->token) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] User name token creation failed."); + rp_username_token_free(username_token, env); + return NULL; + } + + username_token->inclusion = RP_INCLUDE_ALWAYS; + username_token->password_type = PASSWORD_PLAIN; + username_token->useUTprofile10 = AXIS2_TRUE; + username_token->useUTprofile11 = AXIS2_FALSE; + username_token->ref = 0; + + return username_token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_username_token_free( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + if(username_token) + { + if(--(username_token->ref) > 0) + { + return; + } + + rp_token_free(username_token->token, env); + AXIS2_FREE(env->allocator, username_token); + username_token = NULL; + } +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_username_token_get_inclusion( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return username_token->inclusion; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_inclusion( + rp_username_token_t * username_token, + const axutil_env_t * env, + axis2_char_t * inclusion) +{ + AXIS2_PARAM_CHECK(env->error, inclusion, AXIS2_FAILURE); + username_token->inclusion = inclusion; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_username_token_get_useUTprofile10( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return username_token->useUTprofile10; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_useUTprofile10( + rp_username_token_t * username_token, + const axutil_env_t * env, + axis2_bool_t useUTprofile10) +{ + username_token->useUTprofile10 = useUTprofile10; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_username_token_get_useUTprofile11( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return username_token->useUTprofile10; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_useUTprofile11( + rp_username_token_t * username_token, + const axutil_env_t * env, + axis2_bool_t useUTprofile11) +{ + username_token->useUTprofile11 = useUTprofile11; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_increment_ref( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + username_token->ref++; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_username_token_get_issuer( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return rp_token_get_issuer(username_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_issuer( + rp_username_token_t * username_token, + const axutil_env_t * env, + axis2_char_t * issuer) +{ + return rp_token_set_issuer(username_token->token, env, issuer); +} + +AXIS2_EXTERN derive_key_type_t AXIS2_CALL +rp_username_token_get_derivedkey_type( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return rp_token_get_derivedkey_type(username_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_derivedkey_type( + rp_username_token_t * username_token, + const axutil_env_t * env, + derive_key_type_t derivedkey) +{ + return rp_token_set_derivedkey_type(username_token->token, env, derivedkey); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_username_token_get_is_issuer_name( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return rp_token_get_is_issuer_name(username_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_is_issuer_name( + rp_username_token_t * username_token, + const axutil_env_t * env, + axis2_bool_t is_issuer_name) +{ + return rp_token_set_is_issuer_name(username_token->token, env, is_issuer_name); +} + +AXIS2_EXTERN axiom_node_t *AXIS2_CALL +rp_username_token_get_claim( + rp_username_token_t * username_token, + const axutil_env_t * env) +{ + return rp_token_get_claim(username_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_username_token_set_claim( + rp_username_token_t * username_token, + const axutil_env_t * env, + axiom_node_t *claim) +{ + return rp_token_set_claim(username_token->token, env, claim); +} diff --git a/neethi/src/secpolicy/model/wss10.c b/neethi/src/secpolicy/model/wss10.c new file mode 100644 index 0000000..2ee451d --- /dev/null +++ b/neethi/src/secpolicy/model/wss10.c @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_wss10_t +{ + axis2_bool_t must_support_ref_key_identifier; + axis2_bool_t must_support_ref_issuer_serial; + axis2_bool_t must_support_ref_external_uri; + axis2_bool_t must_support_ref_embedded_token; + axis2_bool_t must_support_direct_reference; + int ref; +}; + +AXIS2_EXTERN rp_wss10_t *AXIS2_CALL +rp_wss10_create( + const axutil_env_t * env) +{ + rp_wss10_t *wss10 = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + wss10 = (rp_wss10_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_wss10_t)); + + if(wss10 == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + wss10->must_support_ref_key_identifier = AXIS2_FALSE; + wss10->must_support_ref_issuer_serial = AXIS2_FALSE; + wss10->must_support_ref_external_uri = AXIS2_FALSE; + wss10->must_support_ref_embedded_token = AXIS2_FALSE; + wss10->must_support_direct_reference = AXIS2_TRUE; + wss10->ref = 0; + + return wss10; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_wss10_free( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(wss10) + { + if(--(wss10->ref) > 0) + { + return; + } + + AXIS2_FREE(env->allocator, wss10); + wss10 = NULL; + } + return; +} + +/* Implementations */ +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss10_get_must_support_ref_key_identifier( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss10->must_support_ref_key_identifier; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss10_set_must_support_ref_key_identifier( + rp_wss10_t * wss10, + const axutil_env_t * env, + axis2_bool_t must_support_ref_key_identifier) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_key_identifier, AXIS2_FAILURE); + wss10->must_support_ref_key_identifier = must_support_ref_key_identifier; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss10_get_must_support_ref_issuer_serial( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss10->must_support_ref_issuer_serial; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss10_set_must_support_ref_issuer_serial( + rp_wss10_t * wss10, + const axutil_env_t * env, + axis2_bool_t must_support_ref_issuer_serial) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_issuer_serial, AXIS2_FAILURE); + wss10->must_support_ref_issuer_serial = must_support_ref_issuer_serial; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss10_get_must_support_ref_external_uri( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss10->must_support_ref_external_uri; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss10_set_must_support_ref_external_uri( + rp_wss10_t * wss10, + const axutil_env_t * env, + axis2_bool_t must_support_ref_external_uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_external_uri, AXIS2_FAILURE); + wss10->must_support_ref_external_uri = must_support_ref_external_uri; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss10_get_must_support_ref_embedded_token( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss10->must_support_ref_embedded_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss10_set_must_support_ref_embedded_token( + rp_wss10_t * wss10, + const axutil_env_t * env, + axis2_bool_t must_support_ref_embedded_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_embedded_token, AXIS2_FAILURE); + wss10->must_support_ref_embedded_token = must_support_ref_embedded_token; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss10_increment_ref( + rp_wss10_t * wss10, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + wss10->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/wss11.c b/neethi/src/secpolicy/model/wss11.c new file mode 100644 index 0000000..552646c --- /dev/null +++ b/neethi/src/secpolicy/model/wss11.c @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_wss11_t +{ + axis2_bool_t must_support_ref_key_identifier; + axis2_bool_t must_support_ref_issuer_serial; + axis2_bool_t must_support_ref_external_uri; + axis2_bool_t must_support_ref_embedded_token; + axis2_bool_t must_support_ref_thumbprint; + axis2_bool_t must_support_ref_encryptedkey; + axis2_bool_t require_signature_confirmation; + axis2_bool_t must_support_direct_reference; + int ref; +}; + +AXIS2_EXTERN rp_wss11_t *AXIS2_CALL +rp_wss11_create( + const axutil_env_t * env) +{ + rp_wss11_t *wss11 = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + wss11 = (rp_wss11_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_wss11_t)); + + if(wss11 == NULL) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + wss11->must_support_ref_key_identifier = AXIS2_FALSE; + wss11->must_support_ref_issuer_serial = AXIS2_FALSE; + wss11->must_support_ref_external_uri = AXIS2_FALSE; + wss11->must_support_ref_embedded_token = AXIS2_FALSE; + wss11->must_support_ref_thumbprint = AXIS2_FALSE; + wss11->must_support_ref_encryptedkey = AXIS2_FALSE; + wss11->require_signature_confirmation = AXIS2_FALSE; + wss11->must_support_direct_reference = AXIS2_TRUE; + wss11->ref = 0; + + return wss11; + +} + +AXIS2_EXTERN void AXIS2_CALL +rp_wss11_free( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + if(wss11) + { + if(--(wss11->ref) > 0) + { + return; + } + AXIS2_FREE(env->allocator, wss11); + wss11 = NULL; + } + return; +} + +/* Implementations */ +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_key_identifier( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_key_identifier; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_key_identifier( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_key_identifier) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_key_identifier, AXIS2_FAILURE); + wss11->must_support_ref_key_identifier = must_support_ref_key_identifier; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_issuer_serial( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_issuer_serial; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_issuer_serial( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_issuer_serial) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_issuer_serial, AXIS2_FAILURE); + wss11->must_support_ref_issuer_serial = must_support_ref_issuer_serial; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_external_uri( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_external_uri; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_external_uri( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_external_uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_external_uri, AXIS2_FAILURE); + wss11->must_support_ref_external_uri = must_support_ref_external_uri; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_embedded_token( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_embedded_token; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_embedded_token( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_embedded_token) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_embedded_token, AXIS2_FAILURE); + wss11->must_support_ref_embedded_token = must_support_ref_embedded_token; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_thumbprint( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_thumbprint; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_thumbprint( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_thumbprint) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_thumbprint, AXIS2_FAILURE); + wss11->must_support_ref_thumbprint = must_support_ref_thumbprint; + + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_must_support_ref_encryptedkey( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->must_support_ref_encryptedkey; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_must_support_ref_encryptedkey( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t must_support_ref_encryptedkey) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, must_support_ref_encryptedkey, AXIS2_FAILURE); + wss11->must_support_ref_encryptedkey = must_support_ref_encryptedkey; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_wss11_get_require_signature_confirmation( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + + return wss11->require_signature_confirmation; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_set_require_signature_confirmation( + rp_wss11_t * wss11, + const axutil_env_t * env, + axis2_bool_t require_signature_confirmation) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, require_signature_confirmation, AXIS2_FAILURE); + wss11->require_signature_confirmation = require_signature_confirmation; + + return AXIS2_SUCCESS; + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_wss11_increment_ref( + rp_wss11_t * wss11, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + wss11->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/secpolicy/model/x509_token.c b/neethi/src/secpolicy/model/x509_token.c new file mode 100644 index 0000000..057af86 --- /dev/null +++ b/neethi/src/secpolicy/model/x509_token.c @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct rp_x509_token_t +{ + rp_token_t *token; + axis2_bool_t require_key_identifier_reference; + axis2_bool_t require_issuer_serial_reference; + axis2_bool_t require_embedded_token_reference; + axis2_bool_t require_thumb_print_reference; + axis2_char_t *token_version_and_type; + int ref; + +}; + +AXIS2_EXTERN rp_x509_token_t *AXIS2_CALL +rp_x509_token_create( + const axutil_env_t * env) +{ + rp_x509_token_t *x509_token = NULL; + x509_token = (rp_x509_token_t *)AXIS2_MALLOC(env->allocator, sizeof(rp_x509_token_t)); + + if(!x509_token) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[neethi] X509 token assertion creation failed. Insufficient memory"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + x509_token->require_key_identifier_reference = AXIS2_FALSE; + x509_token->require_issuer_serial_reference = AXIS2_FALSE; + x509_token->require_embedded_token_reference = AXIS2_FALSE; + x509_token->require_thumb_print_reference = AXIS2_FALSE; + x509_token->token_version_and_type = RP_WSS_X509_V3_TOKEN_10; + x509_token->ref = 0; + + x509_token->token = rp_token_create(env); + if(!x509_token->token) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[neethi] X509 token assertion creation failed."); + rp_x509_token_free(x509_token, env); + return NULL; + } + return x509_token; +} + +AXIS2_EXTERN void AXIS2_CALL +rp_x509_token_free( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + if(x509_token) + { + if(--(x509_token->ref) > 0) + { + return; + } + + rp_token_free(x509_token->token, env); + AXIS2_FREE(env->allocator, x509_token); + x509_token = NULL; + } +} + +/* Implementations */ + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_x509_token_get_inclusion( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return rp_token_get_inclusion(x509_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_inclusion( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_char_t * inclusion) +{ + return rp_token_set_inclusion(x509_token->token, env, inclusion); +} + +AXIS2_EXTERN derive_key_type_t AXIS2_CALL +rp_x509_token_get_derivedkey( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return rp_token_get_derivedkey_type(x509_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_derivedkey( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + derive_key_type_t derivedkeys) +{ + return rp_token_set_derivedkey_type(x509_token->token, env, derivedkeys); +} + +AXIS2_EXTERN derive_key_version_t AXIS2_CALL +rp_x509_token_get_derivedkey_version( + rp_x509_token_t *x509_token, + const axutil_env_t *env) +{ + return rp_token_get_derive_key_version(x509_token->token, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_derivedkey_version( + rp_x509_token_t *x509_token, + const axutil_env_t *env, + derive_key_version_t version) +{ + return rp_token_set_derive_key_version(x509_token->token, env, version); +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_x509_token_get_require_key_identifier_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return x509_token->require_key_identifier_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_require_key_identifier_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_bool_t require_key_identifier_reference) +{ + x509_token->require_key_identifier_reference = require_key_identifier_reference; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_x509_token_get_require_issuer_serial_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return x509_token->require_issuer_serial_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_require_issuer_serial_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_bool_t require_issuer_serial_reference) +{ + x509_token->require_issuer_serial_reference = require_issuer_serial_reference; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_x509_token_get_require_embedded_token_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return x509_token->require_embedded_token_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_require_embedded_token_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_bool_t require_embedded_token_reference) +{ + x509_token->require_embedded_token_reference = require_embedded_token_reference; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_bool_t AXIS2_CALL +rp_x509_token_get_require_thumb_print_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return x509_token->require_thumb_print_reference; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_require_thumb_print_reference( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_bool_t require_thumb_print_reference) +{ + x509_token->require_thumb_print_reference = require_thumb_print_reference; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +rp_x509_token_get_token_version_and_type( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + return x509_token->token_version_and_type; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_set_token_version_and_type( + rp_x509_token_t * x509_token, + const axutil_env_t * env, + axis2_char_t * token_version_and_type) +{ + x509_token->token_version_and_type = token_version_and_type; + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +rp_x509_token_increment_ref( + rp_x509_token_t * x509_token, + const axutil_env_t * env) +{ + x509_token->ref++; + return AXIS2_SUCCESS; +} diff --git a/neethi/src/util.c b/neethi/src/util.c new file mode 100644 index 0000000..ca3d790 --- /dev/null +++ b/neethi/src/util.c @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_util_create_policy_from_file( + const axutil_env_t *env, + axis2_char_t *file_name) +{ + + axiom_xml_reader_t *reader = NULL; + axiom_stax_builder_t *builder = NULL; + axiom_document_t *document = NULL; + axiom_node_t *root_node = NULL; + + reader = axiom_xml_reader_create_for_file(env, file_name, NULL); + + if(!reader) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory"); + return NULL; + } + + builder = axiom_stax_builder_create(env, reader); + if(!builder) + { + axiom_xml_reader_free(reader, env); + return NULL; + } + document = axiom_stax_builder_get_document(builder, env); + + if(!document) + { + axiom_stax_builder_free(builder, env); + return NULL; + } + + root_node = axiom_document_build_all(document, env); + if(!root_node) + { + axiom_stax_builder_free(builder, env); + return NULL; + } + + axiom_stax_builder_free_self(builder, env); + builder = NULL; + + return neethi_util_create_policy_from_om(env, root_node); + +} + +AXIS2_EXTERN neethi_policy_t *AXIS2_CALL +neethi_util_create_policy_from_om( + const axutil_env_t *env, + axiom_node_t *root_node) +{ + + axiom_element_t *root_ele = NULL; + + if(axiom_node_get_node_type(root_node, env) == AXIOM_ELEMENT) + { + root_ele = (axiom_element_t *)axiom_node_get_data_element(root_node, env); + if(root_ele) + { + neethi_policy_t *neethi_policy = NULL; + neethi_policy = neethi_engine_get_policy(env, root_node, root_ele); + if(!neethi_policy) + { + return NULL; + } + neethi_policy_set_root_node(neethi_policy, env, root_node); + return neethi_policy; + } + else + return NULL; + } + else + return NULL; +} -- cgit v1.1-32-gdbae