From 451672047ae33ca53c79d40af31c16d6b4cd1970 Mon Sep 17 00:00:00 2001 From: Nicolas Clapies Date: Fri, 6 Aug 2004 07:31:59 +0000 Subject: Renamed load_notification_msg to process_notification msg, renamed process_request to validate_request, added some goto for code error, little update of the code style, updated examples --- lasso/id-ff/federation_termination.c | 114 ++++++++++++++++++---------- lasso/id-ff/federation_termination.h | 24 +++--- python/environs/py_federation_termination.c | 18 ++--- python/environs/py_federation_termination.h | 4 +- python/examples/defederation.py | 16 ++-- python/lasso.py | 16 ++-- python/lassomod.c | 4 +- 7 files changed, 112 insertions(+), 84 deletions(-) diff --git a/lasso/id-ff/federation_termination.c b/lasso/id-ff/federation_termination.c index 7c180dd8..25aad288 100644 --- a/lasso/id-ff/federation_termination.c +++ b/lasso/id-ff/federation_termination.c @@ -32,10 +32,11 @@ gint lasso_federation_termination_build_notification_msg(LassoFederationTermination *defederation) { - LassoProfile *profile; - LassoProvider *provider; - xmlChar *protocolProfile; - lassoProviderType provider_type; /* use to get metadata */ + LassoProfile *profile; + LassoProvider *provider; + xmlChar *protocolProfile; + lassoProviderType provider_type; /* use to get metadata */ + gint ret = 0; g_return_val_if_fail(LASSO_IS_FEDERATION_TERMINATION(defederation), -1); @@ -44,7 +45,8 @@ lasso_federation_termination_build_notification_msg(LassoFederationTermination * provider = lasso_server_get_provider_ref(profile->server, profile->remote_providerID); if (provider == NULL) { message(G_LOG_LEVEL_CRITICAL, "Provider %s not found\n", profile->remote_providerID); - return(-2); + ret = -1; + goto done; } if (profile->provider_type == lassoProviderTypeSp) { @@ -60,7 +62,8 @@ lasso_federation_termination_build_notification_msg(LassoFederationTermination * NULL); if (protocolProfile == NULL) { message(G_LOG_LEVEL_CRITICAL, "Federation termination notification protocol profile not found\n"); - return(-3); + ret = -1; + goto done; } if (xmlStrEqual(protocolProfile, lassoLibProtocolProfileSloSpSoap) || \ @@ -71,7 +74,8 @@ lasso_federation_termination_build_notification_msg(LassoFederationTermination * NULL); if (profile->msg_url == NULL) { message(G_LOG_LEVEL_CRITICAL, "Federation Termination Notification url not found\n"); - return(-4); + ret = -1; + goto done; } profile->msg_body = lasso_node_export_to_soap(profile->request); } @@ -85,10 +89,19 @@ lasso_federation_termination_build_notification_msg(LassoFederationTermination * } else { message(G_LOG_LEVEL_CRITICAL, "Invalid protocol profile\n"); - return(-5); + ret = -1; + goto done; } - return(0); + done: + if (provider != NULL) { + lasso_provider_destroy(provider); + } + if (protocolProfile != NULL) { + xmlFree(protocolProfile); + } + + return(ret); } void @@ -101,13 +114,11 @@ gint lasso_federation_termination_init_notification(LassoFederationTermination *defederation, gchar *remote_providerID) { - LassoProfile *profile; - LassoFederation *federation; - - LassoNode *nameIdentifier = NULL; - xmlChar *content = NULL, *nameQualifier = NULL, *format = NULL; - - gint codeError = 0; + LassoProfile *profile; + LassoFederation *federation; + LassoNode *nameIdentifier = NULL; + xmlChar *content = NULL, *nameQualifier = NULL, *format = NULL; + gint ret = 0; g_return_val_if_fail(LASSO_IS_FEDERATION_TERMINATION(defederation), -1); @@ -124,7 +135,7 @@ lasso_federation_termination_init_notification(LassoFederationTermination *defed if (profile->remote_providerID == NULL) { message(G_LOG_LEVEL_CRITICAL, "No provider Id for init notification\n"); - codeError = -1; + ret = -1; goto done; } @@ -132,7 +143,7 @@ lasso_federation_termination_init_notification(LassoFederationTermination *defed federation = lasso_identity_get_federation(profile->identity, profile->remote_providerID); if (federation == NULL) { message(G_LOG_LEVEL_CRITICAL, "Federation not found for %s\n", profile->remote_providerID); - codeError = -1; + ret = -1; goto done; } @@ -153,11 +164,10 @@ lasso_federation_termination_init_notification(LassoFederationTermination *defed default: message(G_LOG_LEVEL_CRITICAL, "Invalid provider type\n"); } - lasso_federation_destroy(federation); if (!nameIdentifier) { message(G_LOG_LEVEL_CRITICAL, "Name identifier not found for %s\n", profile->remote_providerID); - codeError = -1; + ret = -1; goto done; } @@ -172,11 +182,15 @@ lasso_federation_termination_init_notification(LassoFederationTermination *defed if (profile->request == NULL) { message(G_LOG_LEVEL_CRITICAL, "Error while creating the notification\n"); - codeError = -1; + ret = -1; goto done; } done: + if (federation!=NULL) { + lasso_federation_destroy(federation); + } + /* destroy allocated objects */ debug("Free content, nameQualifier, format and nameIdentifier vars\n"); xmlFree(content); @@ -184,22 +198,22 @@ lasso_federation_termination_init_notification(LassoFederationTermination *defed xmlFree(format); lasso_node_destroy(nameIdentifier); - return(codeError); + return(ret); } gint -lasso_federation_termination_load_notification_msg(LassoFederationTermination *defederation, - gchar *notification_msg, - lassoHttpMethod notification_method) +lasso_federation_termination_process_notification_msg(LassoFederationTermination *defederation, + gchar *notification_msg, + lassoHttpMethod notification_method) { LassoProfile *profile; g_return_val_if_fail(LASSO_IS_FEDERATION_TERMINATION(defederation), -1); - g_return_val_if_fail(notification_msg!=NULL, -2); + g_return_val_if_fail(notification_msg!=NULL, -1); profile = LASSO_PROFILE(defederation); - switch (notification_method){ + switch (notification_method) { case lassoHttpMethodSoap: debug("Build a federation termination notification from soap msg\n"); profile->request = lasso_federation_termination_notification_new_from_export(notification_msg, lassoNodeExportTypeSoap); @@ -212,7 +226,7 @@ lasso_federation_termination_load_notification_msg(LassoFederationTermination *d message(G_LOG_LEVEL_CRITICAL, "Invalid notification method\n"); return(-3); } - if(profile->request==NULL){ + if (profile->request==NULL) { message(G_LOG_LEVEL_CRITICAL, "Error while building the notification from msg\n"); return(-4); } @@ -220,6 +234,10 @@ lasso_federation_termination_load_notification_msg(LassoFederationTermination *d /* get the NameIdentifier to load identity dump */ profile->nameIdentifier = lasso_node_get_child_content(profile->request, "NameIdentifier", NULL, NULL); + if (profile->nameIdentifier==NULL) { + message(G_LOG_LEVEL_CRITICAL, "NameIdentifier not found\n"); + return(-1); + } /* get the RelayState */ profile->msg_relayState = lasso_node_get_child_content(profile->request, @@ -229,17 +247,19 @@ lasso_federation_termination_load_notification_msg(LassoFederationTermination *d } gint -lasso_federation_termination_process_notification(LassoFederationTermination *defederation) +lasso_federation_termination_validate_notification(LassoFederationTermination *defederation) { - LassoProfile *profile; - LassoFederation *federation; - LassoNode *nameIdentifier; + LassoProfile *profile; + LassoFederation *federation; + LassoNode *nameIdentifier; + gint ret = 0; profile = LASSO_PROFILE(defederation); if (profile->request == NULL) { message(G_LOG_LEVEL_CRITICAL, "Request not found\n"); - return(-1); + ret = -1; + goto done; } /* set the remote provider id from the request */ @@ -247,38 +267,50 @@ lasso_federation_termination_process_notification(LassoFederationTermination *de NULL, NULL); if (profile->remote_providerID == NULL) { message(G_LOG_LEVEL_CRITICAL, "Remote provider id not found\n"); - return(-1); + ret = -1; + goto done; } nameIdentifier = lasso_node_get_child(profile->request, "NameIdentifier", NULL, NULL); if (nameIdentifier == NULL) { message(G_LOG_LEVEL_CRITICAL, "Name identifier not found in request\n"); - return(-1); + ret = -1; + goto done; } /* Verify federation */ if (profile->identity == NULL) { - message(G_LOG_LEVEL_CRITICAL, "Identity environ not found\n"); - return(-1); + message(G_LOG_LEVEL_CRITICAL, "Identity not found\n"); + ret = -1; + goto done; } federation = lasso_identity_get_federation(profile->identity, profile->remote_providerID); if (federation == NULL) { message(G_LOG_LEVEL_WARNING, "No federation for %s\n", profile->remote_providerID); - return(-1); + ret = -1; + goto done; } if (lasso_federation_verify_nameIdentifier(federation, nameIdentifier) == FALSE) { message(G_LOG_LEVEL_WARNING, "No name identifier for %s\n", profile->remote_providerID); - return(-1); + ret = -1; + goto done; } - lasso_federation_destroy(federation); /* remove federation of the remote provider */ lasso_identity_remove_federation(profile->identity, profile->remote_providerID); - return(0); + done: + if (federation!=NULL) { + lasso_federation_destroy(federation); + } + if (nameIdentifier!=NULL) { + lasso_node_destroy(nameIdentifier); + } + + return(ret); } /*****************************************************************************/ diff --git a/lasso/id-ff/federation_termination.h b/lasso/id-ff/federation_termination.h index aee63746..ae5352f5 100644 --- a/lasso/id-ff/federation_termination.h +++ b/lasso/id-ff/federation_termination.h @@ -54,23 +54,23 @@ struct _LassoFederationTerminationClass { }; -LASSO_EXPORT GType lasso_federation_termination_get_type (void); - -LASSO_EXPORT LassoFederationTermination *lasso_federation_termination_new (LassoServer *server, - gint provider_type); +LASSO_EXPORT GType lasso_federation_termination_get_type (void); +LASSO_EXPORT LassoFederationTermination *lasso_federation_termination_new (LassoServer *server, + gint provider_type); -LASSO_EXPORT gint lasso_federation_termination_build_notification_msg (LassoFederationTermination *defederation); -LASSO_EXPORT void lasso_federation_termination_destroy (LassoFederationTermination *defederation); +LASSO_EXPORT gint lasso_federation_termination_build_notification_msg (LassoFederationTermination *defederation); + +LASSO_EXPORT void lasso_federation_termination_destroy (LassoFederationTermination *defederation); -LASSO_EXPORT gint lasso_federation_termination_init_notification (LassoFederationTermination *defederation, - gchar *remote_providerID); +LASSO_EXPORT gint lasso_federation_termination_init_notification (LassoFederationTermination *defederation, + gchar *remote_providerID); -LASSO_EXPORT gint lasso_federation_termination_load_notification_msg (LassoFederationTermination *defederation, - gchar *request_msg, - lassoHttpMethod request_method); +LASSO_EXPORT gint lasso_federation_termination_process_notification_msg (LassoFederationTermination *defederation, + gchar *request_msg, + lassoHttpMethod request_method); -LASSO_EXPORT gint lasso_federation_termination_process_notification (LassoFederationTermination *defederation); +LASSO_EXPORT gint lasso_federation_termination_validate_notification (LassoFederationTermination *defederation); diff --git a/python/environs/py_federation_termination.c b/python/environs/py_federation_termination.c index 83d27be9..b4b1ac33 100644 --- a/python/environs/py_federation_termination.c +++ b/python/environs/py_federation_termination.c @@ -143,37 +143,37 @@ PyObject *federation_termination_init_notification(PyObject *self, PyObject *arg return(int_wrap(codeError)); } -PyObject *federation_termination_load_notification_msg(PyObject *self, PyObject *args){ +PyObject *federation_termination_process_notification_msg(PyObject *self, PyObject *args){ PyObject *notification_obj; gchar *notification_msg; gint notification_method; gint codeError; - if (CheckArgs(args, "OSI:federation_termination_load_notification_msg")) { - if(!PyArg_ParseTuple(args, (char *) "Osi:federation_termination_load_notification_msg", + if (CheckArgs(args, "OSI:federation_termination_process_notification_msg")) { + if(!PyArg_ParseTuple(args, (char *) "Osi:federation_termination_process_notification_msg", ¬ification_obj, ¬ification_msg, ¬ification_method)) return NULL; } else return NULL; - codeError = lasso_federation_termination_load_notification_msg(LassoFederationTermination_get(notification_obj), - notification_msg, notification_method); + codeError = lasso_federation_termination_process_notification_msg(LassoFederationTermination_get(notification_obj), + notification_msg, notification_method); return(int_wrap(codeError)); } -PyObject *federation_termination_process_notification(PyObject *self, PyObject *args) { +PyObject *federation_termination_validate_notification(PyObject *self, PyObject *args) { PyObject *federation_termination_obj; gint codeError; - if (CheckArgs(args, "O:federation_termination_process_notification")) { - if(!PyArg_ParseTuple(args, (char *) "O:federation_termination_process_notification", + if (CheckArgs(args, "O:federation_termination_validate_notification")) { + if(!PyArg_ParseTuple(args, (char *) "O:federation_termination_validate_notification", &federation_termination_obj)) return NULL; } else return NULL; - codeError = lasso_federation_termination_process_notification(LassoFederationTermination_get(federation_termination_obj)); + codeError = lasso_federation_termination_validate_notification(LassoFederationTermination_get(federation_termination_obj)); return(int_wrap(codeError)); } diff --git a/python/environs/py_federation_termination.h b/python/environs/py_federation_termination.h index 57f01a5a..97567859 100644 --- a/python/environs/py_federation_termination.h +++ b/python/environs/py_federation_termination.h @@ -46,7 +46,7 @@ PyObject *federation_termination_new(PyObject *self, PyObject *args); PyObject *federation_termination_build_notification_msg(PyObject *self, PyObject *args); PyObject *federation_termination_destroy(PyObject *self, PyObject *args); PyObject *federation_termination_init_notification(PyObject *self, PyObject *args); -PyObject *federation_termination_load_notification_msg(PyObject *self, PyObject *args); -PyObject *federation_termination_process_notification(PyObject *self, PyObject *args); +PyObject *federation_termination_process_notification_msg(PyObject *self, PyObject *args); +PyObject *federation_termination_validate_notification(PyObject *self, PyObject *args); #endif /* __PYLASSO_PY_FEDERATION_TERMINATION_H__ */ diff --git a/python/examples/defederation.py b/python/examples/defederation.py index 34d060c1..e4b44de8 100644 --- a/python/examples/defederation.py +++ b/python/examples/defederation.py @@ -5,9 +5,9 @@ sys.path.insert(0, '../') import lasso -spuser_dump = "1111111111111111111111111" +spidentity_dump = "1111111111111111111111111" -idpuser_dump = "1111111111111111111111111" +idpidentity_dump = "1111111111111111111111111" # SP : @@ -16,10 +16,8 @@ spserver = lasso.Server.new("../../examples/sp.xml", lasso.signatureMethodRsaSha1) spserver.add_provider("../../examples/idp.xml", None, None) -spuser = lasso.User.new_from_dump(spuser_dump) - spdefederation = lasso.FederationTermination.new(spserver, lasso.providerTypeSp) -spdefederation.set_user_from_dump(spuser_dump) +spdefederation.set_identity_from_dump(spidentity_dump) spdefederation.init_notification() spdefederation.build_notification_msg() print 'url : ', spdefederation.msg_url @@ -34,14 +32,12 @@ idpserver = lasso.Server.new("../../examples/idp.xml", lasso.signatureMethodRsaSha1) idpserver.add_provider("../../examples/sp.xml", None, None) -idpuser = lasso.User.new_from_dump(idpuser_dump) - idpdefederation = lasso.FederationTermination.new(idpserver, lasso.providerTypeIdp) -idpdefederation.load_notification_msg(notification_msg, lasso.httpMethodSoap) +idpdefederation.process_notification_msg(notification_msg, lasso.httpMethodSoap) print 'NameIdentifier :', idpdefederation.nameIdentifier -idpdefederation.set_user_from_dump(idpuser_dump); -idpdefederation.process_notification() +idpdefederation.set_identity_from_dump(idpidentity_dump); +idpdefederation.validate_notification() print 'End of federation termination notification' diff --git a/python/lasso.py b/python/lasso.py index 937e4736..ad210795 100644 --- a/python/lasso.py +++ b/python/lasso.py @@ -1353,19 +1353,19 @@ class FederationTermination(Profile): if errorCode: raise newError(errorCode, 'lasso_federation_termination_init_notification') - def load_notification_msg(self, notification_msg, notification_method): - errorCode = lassomod.federation_termination_load_notification_msg( + def process_notification_msg(self, notification_msg, notification_method): + errorCode = lassomod.federation_termination_process_notification_msg( self, notification_msg, notification_method) if errorCode: raise newError(errorCode, 'lasso_federation_termination_load_notification_msg') - def process_notification(self): - errorCode = lassomod.federation_termination_process_notification(self) + def validate_notification(self): + errorCode = lassomod.federation_termination_validate_notification(self) if errorCode: raise newError(errorCode, 'lasso_federation_termination_process_notification') -class RegisterNameIdentifier: +class RegisterNameIdentifier(Profile): """\brief Short desc Long desc @@ -1378,7 +1378,7 @@ class RegisterNameIdentifier: """ The constructor """ - self._o = _obj + Profile.__init__(self, _obj=_obj) def __getattr__(self, name): if self.__isprivate(name): @@ -1424,7 +1424,7 @@ class RegisterNameIdentifier: if errorCode: raise newError(errorCode, 'lasso_register_name_identifier_process_response_msg') -class Lecp: +class Lecp(Login): """\brief Short desc Long desc @@ -1437,7 +1437,7 @@ class Lecp: """ The constructor """ - self._o = _obj + Login.__init__(self, _obj = _obj) def __getattr__(self, name): if self.__isprivate(name): diff --git a/python/lassomod.c b/python/lassomod.c index 1d39fd2d..da59b62f 100644 --- a/python/lassomod.c +++ b/python/lassomod.c @@ -223,8 +223,8 @@ static PyMethodDef lasso_methods[] = { {"federation_termination_build_notification_msg", federation_termination_build_notification_msg, METH_VARARGS}, {"federation_termination_destroy", federation_termination_destroy, METH_VARARGS}, {"federation_termination_init_notification", federation_termination_init_notification, METH_VARARGS}, - {"federation_termination_load_notification_msg", federation_termination_load_notification_msg, METH_VARARGS}, - {"federation_termination_process_notification", federation_termination_process_notification, METH_VARARGS}, + {"federation_termination_process_notification_msg", federation_termination_process_notification_msg, METH_VARARGS}, + {"federation_termination_validate_notification", federation_termination_validate_notification, METH_VARARGS}, /* py_lecp.h */ {"lecp_new", lecp_new, METH_VARARGS}, -- cgit