diff options
| author | Frederic Peters <fpeters@entrouvert.com> | 2005-01-28 10:25:19 +0000 |
|---|---|---|
| committer | Frederic Peters <fpeters@entrouvert.com> | 2005-01-28 10:25:19 +0000 |
| commit | 299d5bd2cfe15cf4288d04ac9707fd8cfddf014b (patch) | |
| tree | 2f038f92f9b09e31b4a002d14e51bb1581d038be | |
| parent | 472aded71ad91451e94d3c2449b8258779a0d692 (diff) | |
| download | lasso-299d5bd2cfe15cf4288d04ac9707fd8cfddf014b.tar.gz lasso-299d5bd2cfe15cf4288d04ac9707fd8cfddf014b.tar.xz lasso-299d5bd2cfe15cf4288d04ac9707fd8cfddf014b.zip | |
Document new functions; pretty please. Fixed memory leak introduced in
lasso_profile_get_request_type_from_soap_msg; moved wsf chunk from
build_assertion to its own function.
| -rw-r--r-- | docs/reference/lasso-sections.txt | 4 | ||||
| -rw-r--r-- | lasso/id-ff/login.c | 100 | ||||
| -rw-r--r-- | lasso/id-ff/login.h | 2 | ||||
| -rw-r--r-- | lasso/id-ff/profile.c | 43 | ||||
| -rw-r--r-- | lasso/id-ff/server.c | 45 |
5 files changed, 122 insertions, 72 deletions
diff --git a/docs/reference/lasso-sections.txt b/docs/reference/lasso-sections.txt index c0afa1cd..182426a1 100644 --- a/docs/reference/lasso-sections.txt +++ b/docs/reference/lasso-sections.txt @@ -33,9 +33,11 @@ LassoServer lasso_server_new lasso_server_new_from_dump lasso_server_add_provider +lasso_server_add_service lasso_server_destroy lasso_server_dump lasso_server_get_provider +lasso_server_get_service <SUBSECTION Standard> LASSO_SERVER LASSO_IS_SERVER @@ -155,6 +157,8 @@ lasso_login_process_authn_response_msg lasso_login_process_request_msg lasso_login_process_response_msg lasso_login_validate_request_msg +lasso_login_set_encryptedResourceId +lasso_login_set_resourceId <SUBSECTION Standard> LASSO_LOGIN LASSO_IS_LOGIN diff --git a/lasso/id-ff/login.c b/lasso/id-ff/login.c index 8ab92e88..f841017f 100644 --- a/lasso/id-ff/login.c +++ b/lasso/id-ff/login.c @@ -49,10 +49,54 @@ struct _LassoLoginPrivate LassoDiscoEncryptedResourceID *encryptedResourceId; }; + +static void +lasso_login_assertion_add_discovery(LassoLogin *login, LassoSamlAssertion *assertion); + /*****************************************************************************/ /* static methods/functions */ /*****************************************************************************/ + +/** + * lasso_login_assertion_add_discovery: + * @login: a #LassoLogin + * @assertion: + * + * Adds AttributeStatement and ResourceOffering attributes to assertion if + * there is a discovery service. + **/ +static void +lasso_login_assertion_add_discovery(LassoLogin *login, LassoSamlAssertion *assertion) +{ + LassoProfile *profile = LASSO_PROFILE(login); + LassoDiscoResourceOffering *resourceOffering; + LassoDiscoServiceInstance *serviceInstance; + LassoSamlAttributeStatement *attributeStatement; + LassoSamlAttribute *attribute; + LassoSamlAttributeValue *attributeValue; + + serviceInstance = lasso_server_get_service(profile->server, LASSO_DISCO_HREF); + if (LASSO_IS_DISCO_SERVICE_INSTANCE(serviceInstance)) { + resourceOffering = lasso_disco_resource_offering_new(serviceInstance); + resourceOffering->ResourceID = g_object_ref(login->private_data->resourceId); + + attributeValue = lasso_saml_attribute_value_new(); + attributeValue->any = g_list_append(attributeValue->any, resourceOffering); + + attribute = lasso_saml_attribute_new(); + attribute->AttributeValue = g_list_append(attribute->AttributeValue, + attributeValue); + + attributeStatement = lasso_saml_attribute_statement_new(); + attributeStatement->Attribute = g_list_append( + attributeStatement->Attribute, attribute); + + assertion->AttributeStatement = attributeStatement; + } +} + + /** * lasso_login_build_assertion: * @login: a #LassoLogin @@ -137,37 +181,7 @@ lasso_login_build_assertion(LassoLogin *login, LASSO_SAML_ASSERTION(assertion)); } - /* Bootstrapping : if server has a discovery service and if login->resourceId is set, - then add a AttributeStatement / ResourceOffering */ - { - LassoDiscoResourceOffering *resourceOffering; - LassoDiscoServiceInstance *serviceInstance; - - LassoSamlAttributeStatement *attributeStatement; - LassoSamlAttribute *attribute; - LassoSamlAttributeValue *attributeValue; - - serviceInstance = lasso_server_get_service(profile->server, LASSO_DISCO_HREF); - if (LASSO_IS_DISCO_SERVICE_INSTANCE(serviceInstance) == TRUE) { - - resourceOffering = lasso_disco_resource_offering_new(serviceInstance); - resourceOffering->ResourceID = g_object_ref( - login->private_data->resourceId); - - attributeValue = lasso_saml_attribute_value_new(); - attributeValue->any = g_list_append(attributeValue->any, resourceOffering); - - attribute = lasso_saml_attribute_new(); - attribute->AttributeValue = g_list_append(attribute->AttributeValue, - attributeValue); - - attributeStatement = lasso_saml_attribute_statement_new(); - attributeStatement->Attribute = g_list_append( - attributeStatement->Attribute, attribute); - - assertion->AttributeStatement = attributeStatement; - } - } + lasso_login_assertion_add_discovery(login, assertion); /* store assertion in session object */ if (profile->session == NULL) { @@ -1313,6 +1327,16 @@ lasso_login_process_response_msg(LassoLogin *login, gchar *response_msg) return lasso_login_process_response_status_and_assertion(login); } + +/** + * lasso_login_set_encryptedResourceId: + * @login: a #LassoLogin + * @encryptedResourceId: + * + * ... + * + * Return value: 0 on success; or a negative value otherwise. + **/ int lasso_login_set_encryptedResourceId(LassoLogin *login, LassoDiscoEncryptedResourceID *encryptedResourceId) @@ -1321,12 +1345,21 @@ lasso_login_set_encryptedResourceId(LassoLogin *login, g_return_val_if_fail(LASSO_IS_DISCO_ENCRYPTED_RESOURCE_ID(encryptedResourceId), LASSO_PARAM_ERROR_INVALID_VALUE); - g_object_ref(encryptedResourceId); - login->private_data->encryptedResourceId = encryptedResourceId; + login->private_data->encryptedResourceId = g_object_ref(encryptedResourceId); return 0; } + +/** + * lasso_login_set_resourceId: + * @login: a #LassoLogin + * @content: + * + * ... + * + * Return value: 0 on success; or a negative value otherwise. + **/ int lasso_login_set_resourceId(LassoLogin *login, const char *content) { @@ -1338,6 +1371,7 @@ lasso_login_set_resourceId(LassoLogin *login, const char *content) return 0; } + /*****************************************************************************/ /* private methods */ /*****************************************************************************/ diff --git a/lasso/id-ff/login.h b/lasso/id-ff/login.h index 347b2c0a..2eef0f69 100644 --- a/lasso/id-ff/login.h +++ b/lasso/id-ff/login.h @@ -120,7 +120,7 @@ LASSO_EXPORT gint lasso_login_process_response_msg(LassoLogin *login, gchar *res LASSO_EXPORT int lasso_login_set_encryptedResourceId( LassoLogin *login, LassoDiscoEncryptedResourceID *encryptedResourceId); -LASSO_EXPORT int lasso_login_set_resourceId(LassoLogin *login, const char *resourceId); +LASSO_EXPORT int lasso_login_set_resourceId(LassoLogin *login, const char *content); LASSO_EXPORT int lasso_login_validate_request_msg(LassoLogin *login, gboolean authentication_result, gboolean is_consent_obtained); diff --git a/lasso/id-ff/profile.c b/lasso/id-ff/profile.c index 9719d3f6..a9185f7e 100644 --- a/lasso/id-ff/profile.c +++ b/lasso/id-ff/profile.c @@ -103,21 +103,23 @@ LassoRequestType lasso_profile_get_request_type_from_soap_msg(const gchar *soap) { xmlDoc *doc; - xmlNode *xmlnode; xmlXPathContext *xpathCtx; xmlXPathObject *xpathObj; LassoRequestType type = LASSO_REQUEST_TYPE_INVALID; const char *name = NULL; + xmlNs *ns = NULL; doc = xmlParseMemory(soap, strlen(soap)); xpathCtx = xmlXPathNewContext(doc); xmlXPathRegisterNs(xpathCtx, "s", LASSO_SOAP_ENV_HREF); xpathObj = xmlXPathEvalExpression("//s:Body/*", xpathCtx); - if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) + if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { name = xpathObj->nodesetval->nodeTab[0]->name; + ns = xpathObj->nodesetval->nodeTab[0]->ns; + } - if (name == NULL) { + if (name == NULL || ns == NULL) { message(G_LOG_LEVEL_WARNING, "Invalid SOAP request"); } else if (strcmp(name, "Request") == 0) { type = LASSO_REQUEST_TYPE_LOGIN; @@ -131,31 +133,20 @@ lasso_profile_get_request_type_from_soap_msg(const gchar *soap) type = LASSO_REQUEST_TYPE_NAME_IDENTIFIER_MAPPING; } else if (strcmp(name, "AuthnRequest") == 0) { type = LASSO_REQUEST_TYPE_LECP; - } else { - /* try to get type of wsf request */ - xmlnode = xpathObj->nodesetval->nodeTab[0]; - if (xmlnode->ns == NULL) { - return LASSO_REQUEST_TYPE_INVALID; - } - if ( strcmp(name, "Query") == 0 ) { - if ( strcmp(xmlnode->ns->href, LASSO_DISCO_HREF) == 0 ) { - type = LASSO_REQUEST_TYPE_DISCO_QUERY; - } - else { - type = LASSO_REQUEST_TYPE_DST_QUERY; - } + } else if (strcmp(name, "Query") == 0) { + if (strcmp(ns->href, LASSO_DISCO_HREF) == 0) { + type = LASSO_REQUEST_TYPE_DISCO_QUERY; + } else { + type = LASSO_REQUEST_TYPE_DST_QUERY; } - else if ( strcmp(name, "Modify") == 0 ) { - if ( strcmp(xmlnode->ns->href, LASSO_DISCO_HREF) == 0 ) { - type = LASSO_REQUEST_TYPE_DISCO_MODIFY; - } - else { - type = LASSO_REQUEST_TYPE_DST_MODIFY; - } - } - else { - message(G_LOG_LEVEL_WARNING, "Unkown node name : %s", name); + } else if (strcmp(name, "Modify") == 0) { + if (strcmp(ns->href, LASSO_DISCO_HREF) == 0) { + type =LASSO_REQUEST_TYPE_DISCO_MODIFY; + } else { + type =LASSO_REQUEST_TYPE_DST_MODIFY; } + } else { + message(G_LOG_LEVEL_WARNING, "Unkown node name : %s", name); } xmlFreeDoc(doc); diff --git a/lasso/id-ff/server.c b/lasso/id-ff/server.c index ffe1a73e..f24e054f 100644 --- a/lasso/id-ff/server.c +++ b/lasso/id-ff/server.c @@ -68,21 +68,30 @@ lasso_server_add_provider(LassoServer *server, LassoProviderRole role, return 0; } + +/** + * lasso_server_add_service: + * @server: a #LassoServer + * @service: + * + * ... + * + * Return value: 0 on success; a negative value if an error occured. + **/ gint lasso_server_add_service(LassoServer *server, LassoDiscoServiceInstance *service) { g_return_val_if_fail(LASSO_IS_SERVER(server), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); g_return_val_if_fail(LASSO_IS_DISCO_SERVICE_INSTANCE(service), - LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); - /* append new service */ - g_hash_table_insert(server->services, - g_strdup(service->ServiceType), - g_object_ref(service)); + g_hash_table_insert(server->services, g_strdup(service->ServiceType), + g_object_ref(service)); - return 0; + return 0; } + /** * lasso_server_destroy: * @server: a #LassoServer @@ -118,7 +127,7 @@ add_provider_childnode(gchar *key, LassoProvider *value, xmlNode *xmlnode) static void add_service_childnode(gchar *key, LassoNode *value, xmlNode *xmlnode) { - xmlAddChild(xmlnode, lasso_node_get_xmlNode(LASSO_NODE(value), TRUE)); + xmlAddChild(xmlnode, lasso_node_get_xmlNode(LASSO_NODE(value), TRUE)); } static xmlNode* @@ -185,7 +194,6 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode) continue; } - /* Providers part */ if (strcmp(t->name, "Providers") == 0) { while (t2) { if (t2->type != XML_ELEMENT_NODE) { @@ -198,9 +206,8 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode) t2 = t2->next; } } - - /* Services part */ - else if (strcmp(t->name, "Services") == 0) { + + if (strcmp(t->name, "Services") == 0) { while (t2) { if (t2->type != XML_ELEMENT_NODE) { t2 = t2->next; @@ -215,11 +222,11 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode) t = t->next; } + return 0; } - static gboolean get_first_providerID(gchar *key, gpointer value, char **providerID) { @@ -245,6 +252,7 @@ lasso_server_get_first_providerID(LassoServer *server) return g_strdup(providerID); } + /** * lasso_server_get_provider: * @server: a #LassoServer @@ -261,12 +269,25 @@ lasso_server_get_provider(LassoServer *server, gchar *providerID) return g_hash_table_lookup(server->providers, providerID); } + +/** + * lasso_server_get_service: + * @server: a #LassoServer + * @serviceType: + * + * ... + * + * Return value: the #LassoDiscoServiceInstance, NULL if it was not found. + * The #LassoDiscoServiceInstance is owned by Lasso and should not be + * freed. + **/ LassoDiscoServiceInstance* lasso_server_get_service(LassoServer *server, gchar *serviceType) { return g_hash_table_lookup(server->services, serviceType); } + static gboolean get_providerID_with_hash(gchar *key, gpointer value, char **providerID) { |
