summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-04 09:14:54 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-04 09:14:54 +0000
commite6748141896b172ac0e35fad2ccbfa033f34f031 (patch)
tree390681e3c34f2dcb080145f3c76bfe009a1a6da3
parent78dd2ec1f86888539b9e19e649fe74d531477211 (diff)
downloadlasso-e6748141896b172ac0e35fad2ccbfa033f34f031.tar.gz
lasso-e6748141896b172ac0e35fad2ccbfa033f34f031.tar.xz
lasso-e6748141896b172ac0e35fad2ccbfa033f34f031.zip
ID-WSF 2.0: add files soap_binding.c, soap_binding.h
* lasso/id-wsf-2.0/Makefile.am - reference new source files in Makefile.am * lasso/id-wsf-2.0/soap_binding.c * lasso/id-wsf-2.0/soap_binding.h: - add extraction functions lasso_soap_envelope_sb2_get_provider_id, lasso_soap_envelope_sb2_get_redirect_request_url, lasso_soap_envelope_sb2_get_target_identity_header, lasso_soap_envelope_add_action and lasso_soap_envelope_get_action. - add SOAP security headers accessors - add lasso_soap_envelope_get_saml2_security_token which simplify retrieving a SAML 2.0 assertion used as a WS-Security token. complete documentation of other functions. * docs/reference/lasso/lasso-sections.txt: - reference the new functions in a new section soap_binding2 * docs/reference/lasso/lasso-docs.sgml: - add new section soap_binding2 ID-WSF 2.0: in soap_binding.{c,h}: add function
-rw-r--r--docs/reference/lasso/lasso-docs.sgml1
-rw-r--r--docs/reference/lasso/lasso-sections.txt8
-rw-r--r--lasso/id-wsf-2.0/Makefile.am6
-rw-r--r--lasso/id-wsf-2.0/soap_binding.c222
-rw-r--r--lasso/id-wsf-2.0/soap_binding.h62
5 files changed, 297 insertions, 2 deletions
diff --git a/docs/reference/lasso/lasso-docs.sgml b/docs/reference/lasso/lasso-docs.sgml
index c14bc133..429046ae 100644
--- a/docs/reference/lasso/lasso-docs.sgml
+++ b/docs/reference/lasso/lasso-docs.sgml
@@ -351,6 +351,7 @@ the <ulink url="http://lasso.entrouvert.org/license">GNU General Public License<
</chapter>
<chapter id="idwsf2">
<title>ID-WSF 2.0</title>
+ <xi:include href="xml/soap_binding2.xml"/>
<xi:include href="xml/id_wsf_2_0_discovery.xml"/>
<xi:include href="xml/id_wsf_2_0_data_service.xml"/>
<xi:include href="xml/id_wsf_2_0_profile.xml"/>
diff --git a/docs/reference/lasso/lasso-sections.txt b/docs/reference/lasso/lasso-sections.txt
index 38234e07..a9d8fea0 100644
--- a/docs/reference/lasso/lasso-sections.txt
+++ b/docs/reference/lasso/lasso-sections.txt
@@ -6035,3 +6035,11 @@ lasso_get_prefix_for_dst_service_href
lasso_profile_is_saml_query
lasso_provider_saml2_node_encrypt
</SECTION>
+
+<SECTION>
+<FILE>soap_binding2</FILE>
+<TITLE>SOAP Binding utility function for ID-WSF 2.0</TITLE>
+lasso_soap_envelope_sb2_get_provider_id
+lasso_soap_envelope_sb2_get_redirect_request_url
+lasso_soap_envelope_sb2_get_target_identity_header
+</SECTION>
diff --git a/lasso/id-wsf-2.0/Makefile.am b/lasso/id-wsf-2.0/Makefile.am
index 2fa5992b..2f3eb3c4 100644
--- a/lasso/id-wsf-2.0/Makefile.am
+++ b/lasso/id-wsf-2.0/Makefile.am
@@ -22,7 +22,8 @@ liblasso_id_wsf2_la_SOURCES = \
discovery.c \
data_service.c \
profile.c \
- saml2_login.c
+ saml2_login.c \
+ soap_binding.c
liblassoinclude_HEADERS = \
id_wsf_2.h \
@@ -31,6 +32,7 @@ liblassoinclude_HEADERS = \
profile.h \
identity.h \
server.h \
- session.h
+ session.h \
+ soap_binding.h
EXTRA_DIST = $(lasso_private_h_sources)
diff --git a/lasso/id-wsf-2.0/soap_binding.c b/lasso/id-wsf-2.0/soap_binding.c
new file mode 100644
index 00000000..e578e4c6
--- /dev/null
+++ b/lasso/id-wsf-2.0/soap_binding.c
@@ -0,0 +1,222 @@
+/* $Id: wsf_profile.c,v 1.45 2007/01/05 16:11:02 Exp $
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004-2007 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: See AUTHORS file in top-level directory.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "./soap_binding.h"
+#include "../xml/id-wsf-2.0/sb2_sender.h"
+#include "../xml/id-wsf-2.0/sb2_redirect_request.h"
+
+#include "../utils.h"
+
+#define get_header(test) \
+ GList *i = NULL; \
+ \
+ if (! LASSO_IS_SOAP_ENVELOPE(soap_envelope)) \
+ return NULL; \
+ if (! LASSO_IS_SOAP_HEADER(soap_envelope->Header)) \
+ return NULL; \
+ \
+ i = soap_envelope->Header->Other; \
+ for (; i != NULL; i = g_list_next(i)) { \
+ if (test(i->data)) { \
+ break; \
+ } \
+ }
+
+/**
+ * lasso_soap_envelope_sb2_get_provider_id:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ *
+ * Return the providerID contained in the sb2:Sender header.
+ *
+ * Return value: the providerID string or NULL if no sb2:Sender header is present.
+ */
+char *
+lasso_soap_envelope_sb2_get_provider_id(LassoSoapEnvelope *soap_envelope)
+{
+ get_header(LASSO_IS_IDWSF2_SB2_SENDER);
+
+ if (i)
+ return g_strdup(((LassoIdWsf2Sb2Sender*)i->data)->providerID);
+ else
+ return NULL;
+}
+
+/**
+ * lasso_soap_envelope_sb2_get_redirect_request_url:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ *
+ * Return the redirect request URL from the sb2:RedirectRequest header.
+ *
+ * Return value: the redirect URL string or NULL if no sb2:RedirectRequest header is present.
+ */
+char *
+lasso_soap_envelope_sb2_get_redirect_request_url(LassoSoapEnvelope *soap_envelope)
+{
+ get_header(LASSO_IS_IDWSF2_SB2_REDIRECT_REQUEST);
+
+ if (i)
+ return g_strdup(((LassoIdWsf2Sb2RedirectRequest*)i->data)->redirectURL);
+ else
+ return NULL;
+}
+
+/**
+ * lasso_soap_envelope_sb2_get_target_identity_header:
+ * @soap_envelope: a #LassoSoapEnvelope object.
+ *
+ * Return the first sb2:TargetIdentity header.
+ *
+ * Return value: (transfer-none): the first #LassoIdWsf2Sb2TargetIdentity object found in the headers of the
+ * @soap_envelope, or NULL if none is found.
+ */
+LassoIdWsf2Sb2TargetIdentity*
+lasso_soap_envelope_sb2_get_target_identity_header(LassoSoapEnvelope *soap_envelope)
+{
+ get_header(LASSO_IS_IDWSF2_SB2_TARGET_IDENTITY);
+
+ if (i)
+ return (LassoIdWsf2Sb2TargetIdentity*)i->data;
+ else
+ return NULL;
+}
+
+
+/**
+ * lasso_soap_envelope_wssec_get_security_header_impl:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ * @create: wether to create the header if not found
+ *
+ * Return value: (transfer-none): the wsse:Security header found in the SOAP message, or NULL if none is found, and
+ * creation was not allowed.
+ */
+static LassoWsSec1SecurityHeader*
+lasso_soap_envelope_wssec_get_security_header_impl(LassoSoapEnvelope *soap_envelope, gboolean create)
+{
+ get_header(LASSO_IS_WSSE_SECURITY_HEADER);
+
+ if (i) {
+ return (LassoWsSec1SecurityHeader*)i->data;
+ }
+
+ if (create) {
+ LassoWsSec1SecurityHeader *wssec_security = lasso_wsse_security_header_new();
+ lasso_list_add_new_gobject (soap_envelope->Header->Other, wssec_security);
+ return wssec_security;
+ }
+
+ return NULL;
+}
+
+/**
+ * lasso_soap_envelope_wssec_get_security_header:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ *
+ * Return the first wsse:Security header found in the headers of @soap_envelope.
+ *
+ * Return value: (transfer-none): the wsse:Security header found in the SOAP message, or NULL if none is found.
+ */
+LassoWsSec1SecurityHeader*
+lasso_soap_envelope_wssec_get_security_header(LassoSoapEnvelope *soap_envelope)
+{
+ return lasso_soap_envelope_wssec_get_security_header_impl (soap_envelope, FALSE);
+}
+
+/**
+ * lasso_soap_envelope_add_security_token:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ * @token: a #LassoNode to use as a security token
+ *
+ * Add @token as a security token to the headers of @soap_envelope using a
+ * #LassoWsSec1SecurityHeader element as a container. Eventually create the
+ * #LassoWsSec1SecurityHeader element if it does not exist already.
+ */
+void
+lasso_soap_envelope_add_security_token(LassoSoapEnvelope *soap_envelope, LassoNode *token)
+{
+ LassoWsSec1SecurityHeader *wssec_security;
+
+ wssec_security = lasso_soap_envelope_wssec_get_security_header_impl (soap_envelope, TRUE);
+ g_return_if_fail (wssec_security != NULL);
+ lasso_list_add_gobject(wssec_security->any, token);
+}
+
+/**
+ * lasso_soap_envelope_get_saml2_security_token:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ *
+ * Return a SAML2 Assertion used as a security token if one is found in the headers of @soap_envelope.
+ *
+ * Return value: (transfer-none): a #LassoSaml2Assertion, or NULL if none is found.
+ */
+LassoSaml2Assertion*
+lasso_soap_envelope_get_saml2_security_token(LassoSoapEnvelope *soap_envelope)
+{
+ const LassoWsSec1SecurityHeader *security;
+ GList *it;
+
+ security = lasso_soap_envelope_wssec_get_security_header (soap_envelope);
+ lasso_foreach (it, security->any) {
+ if (LASSO_IS_SAML2_ASSERTION (it->data)) {
+ return (LassoSaml2Assertion*)g_object_ref(it->data);
+ }
+ }
+ return NULL;
+}
+
+/**
+ * lasso_soap_envelope_add_action_header:
+ * @soap_envelope: a #LassoSoapEnvelope object
+ * @action: the action targeted by this message
+ *
+ * Add an action header to a #LassoSoapEnvelope object.
+ */
+void
+lasso_soap_envelope_add_action_(LassoSoapEnvelope *soap_envelope, const char *action)
+{
+ LassoWsAddrAttributedURI *wsa_action;
+
+ if (! LASSO_IS_SOAP_ENVELOPE(soap_envelope) || ! LASSO_IS_SOAP_HEADER(soap_envelope->Header))
+ return;
+ wsa_action = lasso_wsa_attributed_uri_new_with_string(action);
+ lasso_node_set_custom_nodename(wsa_action, "Action");
+ lasso_list_add_new_gobject(soap_envelope->Header->Other, wsa_action);
+}
+
+const char*
+lasso_soap_envelope_get_action(LassoSoapEnvelope *soap_envelope)
+{
+ LassoWsAddrAttributedURI *wsa_action;
+ GList *i;
+
+ if (! LASSO_IS_SOAP_ENVELOPE(soap_envelope) || ! LASSO_IS_SOAP_HEADER(soap_envelope->Header))
+ return NULL;
+
+ lasso_foreach(i, soap_envelope->Header->Other) {
+ if (LASSO_IS_WSA_ATTRIBUTED_URI(i->data) && g_strcmp0(lasso_node_get_name((LassoNode*)i->data, "Action"))) {
+ return ((LassoWsAddrAttributedURI*)i->data)->content;
+ }
+
+ }
+ }
+}
diff --git a/lasso/id-wsf-2.0/soap_binding.h b/lasso/id-wsf-2.0/soap_binding.h
new file mode 100644
index 00000000..1ef9b2f8
--- /dev/null
+++ b/lasso/id-wsf-2.0/soap_binding.h
@@ -0,0 +1,62 @@
+/* $Id: wsf_profile.h,v 1.13 2006/11/14 17:07:30 Exp $
+ *
+ * Lasso - A free implementation of the Liberty Alliance specifications.
+ *
+ * Copyright (C) 2004-2007 Entr'ouvert
+ * http://lasso.entrouvert.org
+ *
+ * Authors: See AUTHORS file in top-level directory.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __LASSO_IDWSF2_SOAP_BINDING_H__
+#define __LASSO_IDWSF2_SOAP_BINDING_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "../export.h"
+#include "../xml/soap_envelope.h"
+#include "../xml/id-wsf-2.0/sb2_target_identity.h"
+#include "../xml/ws/wsse_security_header.h"
+#include "../xml/saml-2.0/saml2_assertion.h"
+
+LASSO_EXPORT char* lasso_soap_envelope_sb2_get_provider_id(LassoSoapEnvelope *soap_envelope);
+
+LASSO_EXPORT char* lasso_soap_envelope_sb2_get_redirect_request_url(
+ LassoSoapEnvelope *soap_envelope);
+
+LASSO_EXPORT LassoIdWsf2Sb2TargetIdentity* lasso_soap_envelope_sb2_get_target_identity_header(
+ LassoSoapEnvelope *soap_envelope);
+
+LASSO_EXPORT LassoWsSec1SecurityHeader* lasso_soap_envelope_wssec_get_security_header(
+ LassoSoapEnvelope *soap_envelope);
+
+LASSO_EXPORT void lasso_soap_envelope_add_security_token(LassoSoapEnvelope *soap_envelope,
+ LassoNode *token);
+
+LASSO_EXPORT LassoSaml2Assertion *lasso_soap_envelope_get_saml2_security_token(
+ LassoSoapEnvelope *soap_envelope);
+
+LASSO_EXPORT const char* lasso_soap_envelope_get_action(LassoSoapEnvelope *soap_envelope);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __LASSO_IDWSF2_SOAP_BINDING_H__ */
+