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

This commit is contained in:
Nicolas Clapies 2004-08-06 07:31:59 +00:00
parent f4bc1492cd
commit 451672047a
7 changed files with 112 additions and 84 deletions

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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 gint lasso_federation_termination_init_notification (LassoFederationTermination *defederation,
gchar *remote_providerID);
LASSO_EXPORT void lasso_federation_termination_destroy (LassoFederationTermination *defederation);
LASSO_EXPORT gint lasso_federation_termination_load_notification_msg (LassoFederationTermination *defederation,
gchar *request_msg,
lassoHttpMethod request_method);
LASSO_EXPORT gint lasso_federation_termination_init_notification (LassoFederationTermination *defederation,
gchar *remote_providerID);
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);

View File

@ -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",
&notification_obj, &notification_msg, &notification_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));
}

View File

@ -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__ */

View File

@ -5,9 +5,9 @@ sys.path.insert(0, '../')
import lasso
spuser_dump = "<LassoUser><LassoIdentities><LassoIdentity RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">1111111111111111111111111</NameIdentifier></LassoRemoteNameIdentifier></LassoIdentity></LassoIdentities></LassoUser>"
spidentity_dump = "<LassoIdentity><LassoFederations><LassoFederation RemoteProviderID=\"https://identity-provider:2003/liberty-alliance/metadata\"><LassoRemoteNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">1111111111111111111111111</NameIdentifier></LassoRemoteNameIdentifier></LassoFederation></LassoFederations></LassoIdentity>"
idpuser_dump = "<LassoUser><LassoIdentities><LassoIdentity RemoteProviderID=\"https://service-provider:2003/liberty-alliance/metadata\"><LassoLocalNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">1111111111111111111111111</NameIdentifier></LassoLocalNameIdentifier></LassoIdentity></LassoIdentities></LassoUser>"
idpidentity_dump = "<LassoIdentity><LassoFederations><LassoFederation RemoteProviderID=\"https://service-provider:2003/liberty-alliance/metadata\"><LassoLocalNameIdentifier><NameIdentifier NameQualifier=\"qualifier.com\" Format=\"federated\">1111111111111111111111111</NameIdentifier></LassoLocalNameIdentifier></LassoFederation></LassoFederations></LassoIdentity>"
# 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'

View File

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

View File

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