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
This commit is contained in:
John Dennis 2015-05-28 08:14:35 -04:00 committed by Benjamin Dauvergne
parent ad3751f2b0
commit a7a54cabad
4 changed files with 75 additions and 1 deletions

View File

@ -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"/>

View File

@ -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

View File

@ -470,6 +470,72 @@ lasso_node_export_to_soap(LassoNode *node)
return ret;
}
/**
* 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
@ -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());

View File

@ -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,