summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2015-05-28 12:14:35 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2015-08-24 14:05:29 (GMT)
commita7a54cabad24e2d4388b633eb7a8166c793960aa (patch)
tree5bc374943e2bc39367f50767754575d5e15a1c85
parentad3751f2b02645165a9681907b251abef2884828 (diff)
downloadlasso-a7a54cabad24e2d4388b633eb7a8166c793960aa.zip
lasso-a7a54cabad24e2d4388b633eb7a8166c793960aa.tar.gz
lasso-a7a54cabad24e2d4388b633eb7a8166c793960aa.tar.bz2
Export LassonNode to SOAP with arbitrary SOAP headers
Add function lasso_node_export_to_soap_with_headers() Utility function to build a full SOAP envelope message with arbitrary headers. The LassoNode becomes the body of the SOAP envelope. The headers are passed as a GList of LassoNode's and are added as header elements to the SOAP envelope header. This is a flexible way to build a SOAP envelope that contains headers without constraints on the headers. Signed-off-by: John Dennis <jdennis@redhat.com> License: MIT
-rw-r--r--bindings/overrides.xml5
-rw-r--r--docs/reference/lasso/lasso-sections.txt1
-rw-r--r--lasso/xml/xml.c68
-rw-r--r--lasso/xml/xml.h2
4 files changed, 75 insertions, 1 deletions
diff --git a/bindings/overrides.xml b/bindings/overrides.xml
index e30c97a..451199c 100644
--- a/bindings/overrides.xml
+++ b/bindings/overrides.xml
@@ -198,6 +198,11 @@
<func name="lasso_log_set_handler" skip="true"/>
<func name="lasso_log_remove_handler" skip="true"/>
<func name="lasso_key_new_for_signature_from_memory" skip="true"/>
+ <!-- Xml -->
+ <func name="lasso_node_export_to_soap_with_headers">
+ <param name="node"/>
+ <param name="headers" type="GList*" elem_type="LassoNode*"/>
+ </func>
<!-- Exceptions -->
<exception>
<category name="Profile"/>
diff --git a/docs/reference/lasso/lasso-sections.txt b/docs/reference/lasso/lasso-sections.txt
index 72d0031..a0e70e1 100644
--- a/docs/reference/lasso/lasso-sections.txt
+++ b/docs/reference/lasso/lasso-sections.txt
@@ -1058,6 +1058,7 @@ lasso_node_export_to_base64
lasso_node_export_to_query
lasso_node_export_to_query_with_password
lasso_node_export_to_soap
+lasso_node_export_to_soap_with_headers
lasso_node_export_to_xml
lasso_node_export_to_paos_request
lasso_node_export_to_ecp_soap_response
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c
index d6e29ed..397a1b0 100644
--- a/lasso/xml/xml.c
+++ b/lasso/xml/xml.c
@@ -471,6 +471,72 @@ lasso_node_export_to_soap(LassoNode *node)
}
/**
+ * lasso_node_export_to_soap_with_headers:
+ * @node: a #LassoNode, becomes the SOAP body
+ * @headers: (allow-none): #GList of #LassNode
+ *
+ * Exports @node to a SOAP message. The @node becomes the SOAP body.
+ * each header in the #headers list is added to the SOAP header if non-NULL.
+ * @headers is permitted to be an empty list (e.g. NULL).
+ *
+ * <example>
+ * <title>Create SOAP envelope with variable number of header nodes</title>
+ *
+ * <para>You need to form a SOAP message with authn_request as the body and
+ * paos_request, ecp_request and ecp_relaystate as SOAP header elements.
+ * It is possible one or more of these may be NULL and should be skipped.</para>
+ * <programlisting>
+ * char *text = NULL;
+ * LassoNode *paos_request = NULL;
+ * LassoNode *ecp_request = NULL;
+ * LassoNode *ecp_relaystate = NULL;
+ * GList *headers = NULL;
+ *
+ * paos_request = lasso_paos_request_new(responseConsumerURL, message_id);
+ * ecp_request = lasso_ecp_request_new(issuer, is_passive, provider_name, idp_list);
+ *
+ * lasso_list_add_new_gobject(headers, paos_request);
+ * lasso_list_add_new_gobject(headers, ecp_request);
+ * lasso_list_add_new_gobject(headers, ecp_relaystate);
+ *
+ * text = lasso_node_export_to_soap_with_headers(node, headers);
+ *
+ * lasso_release_list_of_gobjects(headers);
+ * </programlisting>
+ * </example>
+ *
+ * Return value: a SOAP export of @node. The string must be freed by the
+ * caller.
+ **/
+char*
+lasso_node_export_to_soap_with_headers(LassoNode *node, GList *headers)
+{
+ GList *i;
+ LassoSoapEnvelope *envelope = NULL;
+ LassoNode *header = NULL;
+ char *ret = NULL;
+
+ g_return_val_if_fail(LASSO_IS_NODE(node), NULL);
+
+ envelope = lasso_soap_envelope_new_full();
+ lasso_list_add_gobject(envelope->Body->any, node);
+
+ lasso_foreach(i, headers) {
+ header = i->data;
+ if (!header) continue;
+
+ goto_cleanup_if_fail(LASSO_IS_NODE(header));
+ lasso_list_add_gobject(envelope->Header->Other, header); /* adds ref */
+ }
+
+ ret = lasso_node_export_to_xml((LassoNode*)envelope);
+
+ cleanup:
+ lasso_release_gobject(envelope);
+ return ret;
+}
+
+/**
* lasso_node_encrypt:
* @lasso_node: a #LassoNode to encrypt
* @encryption_public_key : RSA public key the node will be encrypted with
@@ -643,7 +709,7 @@ lasso_node_encrypt(LassoNode *lasso_node, xmlSecKey *encryption_public_key,
message(G_LOG_LEVEL_WARNING, "Encryption failed");
goto cleanup;
}
-
+
/* Create a new EncryptedElement */
encrypted_element = LASSO_SAML2_ENCRYPTED_ELEMENT(lasso_saml2_encrypted_element_new());
diff --git a/lasso/xml/xml.h b/lasso/xml/xml.h
index c4e4279..848f144 100644
--- a/lasso/xml/xml.h
+++ b/lasso/xml/xml.h
@@ -162,6 +162,8 @@ LASSO_EXPORT char* lasso_node_export_to_query_with_password(LassoNode *node,
LASSO_EXPORT char* lasso_node_export_to_soap(LassoNode *node);
+LASSO_EXPORT char* lasso_node_export_to_soap_with_headers(LassoNode *node, GList *headers);
+
LASSO_EXPORT gchar* lasso_node_export_to_xml(LassoNode *node);
LASSO_EXPORT char* lasso_node_export_to_paos_request(LassoNode *node, const char *issuer,