diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2008-08-01 14:08:17 +0000 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2008-08-01 14:08:17 +0000 |
| commit | ed41e73e77bc76467cf7b1d70b1825fcba86b73a (patch) | |
| tree | 5e893f1e2d2fb73dc3163848b676ea553fb38167 | |
| parent | 0546219300855f2f1e39c973fcc958f68e411af7 (diff) | |
* lasso/id-wsf/discovery.c: repurpose lasso_discovery_process_query_response_msg
in order to extract credentials informations and store them into
the current session.
* lasso/id-wsf/wsf_profile.c: Remove any high-level processing from
lasso_wsf_profile_process_soap_response_msg, just parse and setup
the corresponding fields into the structure. Eventually signal a
SOAP using a return code.
| -rw-r--r-- | lasso/id-wsf/discovery.c | 43 | ||||
| -rw-r--r-- | lasso/id-wsf/wsf_profile.c | 102 |
2 files changed, 70 insertions, 75 deletions
diff --git a/lasso/id-wsf/discovery.c b/lasso/id-wsf/discovery.c index e7ff4e10..1c4e094d 100644 --- a/lasso/id-wsf/discovery.c +++ b/lasso/id-wsf/discovery.c @@ -944,6 +944,8 @@ lasso_discovery_build_response_msg(LassoDiscovery *discovery) * @message: the disco:QueryResponse message * * Processes a disco:QueryResponse message. + * Extract credentials from the response and put them in the session, + * for later use by a request from a #LassoWsfProfile. * * Return value: 0 on success; or a negative value otherwise. **/ @@ -952,27 +954,42 @@ lasso_discovery_process_query_response_msg(LassoDiscovery *discovery, const gcha { LassoWsfProfile *profile = NULL; LassoDiscoQueryResponse *response; - int rc; + xmlXPathContext *xpathCtx = NULL; + xmlXPathObject *xpathObj; + LassoDiscoCredentials *credentials; + int rc = 0, i; - g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); - g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); + g_return_val_if_fail(LASSO_IS_DISCOVERY(discovery), + LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + g_return_val_if_fail(message != NULL, + LASSO_PARAM_ERROR_INVALID_VALUE); profile = LASSO_WSF_PROFILE(discovery); - rc = lasso_wsf_profile_process_soap_response_msg(profile, message); - if (rc) { - return rc; - } - + if (rc) + goto exit; response = LASSO_DISCO_QUERY_RESPONSE(profile->response); - if (strcmp(response->Status->code, LASSO_DISCO_STATUS_CODE_OK) != 0) { return LASSO_PROFILE_ERROR_STATUS_NOT_SUCCESS; } - - /* XXX: anything else to do ? */ - - return 0; + /** Process the credentials, add them to the session */ + if (response->Credentials) { + GList *assertions = response->Credentials->any; + for (; assertions; assertions = g_list_next(assertions)) { + if (LASSO_IS_SAML_ASSERTION(assertions->data) == FALSE) { + continue; + } + if (profile->session) { + lasso_session_add_assertion(profile->session, + assertions->data); + } else { + rc = LASSO_PROFILE_ERROR_SESSION_NOT_FOUND; + goto exit; + } + } + } +exit: + return rc; } diff --git a/lasso/id-wsf/wsf_profile.c b/lasso/id-wsf/wsf_profile.c index cecc6cbb..5bb77cec 100644 --- a/lasso/id-wsf/wsf_profile.c +++ b/lasso/id-wsf/wsf_profile.c @@ -1548,80 +1548,58 @@ lasso_wsf_profile_process_soap_request_msg(LassoWsfProfile *profile, const gchar return res; } +/** + * lasso_wsf_profile_process_soap_response_msg: + * @profile: a #LassoWsfProfile object + * @message: the textual representaition of a SOAP message + * + * Parse a SOAP response from an ID-WSF 1.0 service, + * eventually signal a SOAP fault. + * + * Returns: 0 if the processing of this message was successful. + */ gint lasso_wsf_profile_process_soap_response_msg(LassoWsfProfile *profile, const gchar *message) { LassoSoapEnvelope *envelope; - xmlNode *credential; - int res = 0; - - xmlXPathContext *xpathCtx = NULL; - xmlXPathObject *xpathObj; - xmlDoc *doc; + xmlNode *root; + LassoNode *node; + gint ret = 0; - g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); - g_return_val_if_fail(message != NULL, LASSO_PARAM_ERROR_INVALID_VALUE); + g_return_val_if_fail(LASSO_IS_WSF_PROFILE(profile), + LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ); + g_return_val_if_fail(message != NULL, + LASSO_PARAM_ERROR_INVALID_VALUE); doc = lasso_xml_parse_memory(message, strlen(message)); - - if (lasso_wsf_profile_has_x509_authentication(profile) == TRUE) { - xmlNode *xmlnode; - int res; - - res = lasso_wsf_profile_verify_x509_authentication(profile, doc, NULL); - if (res != 0) { - xmlFreeDoc(doc); - return res; - } - - /* FIXME: Remove Signature element if exists, it seg fault when a call to - lasso_node_new_from_xmlNode() */ - xmlnode = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, - xmlSecDSigNs); - if (xmlnode) { - xmlUnlinkNode(xmlnode); - xmlFreeNode(xmlnode); - } + if (doc == NULL) { + ret = critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG); + goto exit; } - - if (res != 0) { - xmlFreeDoc(doc); - return res; + root = xmlDocGetRootElement(doc); + /* Parse the message */ + node = lasso_node_new_from_xmlNode(root); + if (LASSO_IS_SOAP_ENVELOPE(node)) { + profile->soap_envelope_response = LASSO_SOAP_ENVELOPE(node); + node = NULL; + } else { + ret = critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG); + goto exit; } - - /* If credentials are found, save and remove them from message */ - { - int i; - - xpathCtx = xmlXPathNewContext(doc); - xmlXPathRegisterNs(xpathCtx, (xmlChar*)"saml", (xmlChar*)LASSO_SAML_ASSERTION_HREF); - xpathObj = xmlXPathEvalExpression((xmlChar*)"//saml:Assertion", xpathCtx); - if (xpathObj->nodesetval && xpathObj->nodesetval->nodeNr) { - for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) { - credential = xpathObj->nodesetval->nodeTab[i]; - xmlUnlinkNode(credential); - lasso_wsf_profile_add_credential(profile, credential); - } - } - xmlXPathFreeContext(xpathCtx); - xmlXPathFreeObject(xpathObj); + profile->response = LASSO_NODE(envelope->Body->any->data); + /* Signal soap fault specifically */ + if (LASSO_IS_SOAP_FAULT(envelope->Body->any->data)) { + return LASSO_WSF_PROFILE_ERROR_SOAP_FAULT; } - - envelope = LASSO_SOAP_ENVELOPE(lasso_node_new_from_xmlNode(xmlDocGetRootElement(doc))); - xmlFreeDoc(doc); - - profile->soap_envelope_response = envelope; - - if (envelope == NULL) { - return critical_error(LASSO_PROFILE_ERROR_INVALID_SOAP_MSG); +exit: + if (node) { + g_object_unref(node); } - - /* Soap Fault message */ - if (LASSO_IS_SOAP_FAULT(envelope->Body->any->data) == FALSE) - profile->response = LASSO_NODE(envelope->Body->any->data); - - return 0; + if (doc) { + xmlFreeDoc(doc); + } + return ret; } LassoSoapBindingProvider *lasso_wsf_profile_set_provider_soap_request(LassoWsfProfile *profile, |
