fix(saml): fix profile initialization, improve error handling

Fixes #5153
Fixes #5270
pull/299/head
Francis Lachapelle 2021-05-17 10:56:43 -04:00
parent e536365646
commit 1d88d36ded
1 changed files with 19 additions and 20 deletions

View File

@ -24,7 +24,6 @@
#include <lasso/xml/saml-2.0/saml2_attribute_value.h> #include <lasso/xml/saml-2.0/saml2_attribute_value.h>
#include <lasso/xml/saml-2.0/samlp2_authn_request.h> #include <lasso/xml/saml-2.0/samlp2_authn_request.h>
#import <NGObjWeb/WOApplication.h> #import <NGObjWeb/WOApplication.h>
#import <NGObjWeb/WOContext.h> #import <NGObjWeb/WOContext.h>
@ -237,22 +236,24 @@ static NSMapTable *serverTable = nil;
- (void) _updateDataFromLogin - (void) _updateDataFromLogin
{ {
LassoSaml2Assertion *saml2Assertion;
GList *statementList, *attributeList; GList *statementList, *attributeList;
LassoSaml2AttributeStatement *statement;
LassoSaml2Attribute *attribute;
LassoSaml2AttributeValue *value;
LassoMiscTextNode *textNode; LassoMiscTextNode *textNode;
LassoNode *lassoNode;
LassoSaml2Assertion *saml2Assertion;
LassoSaml2Attribute *attribute;
LassoSaml2AttributeStatement *statement;
LassoSaml2AttributeValue *value;
LassoSaml2NameID *nameIdentifier; LassoSaml2NameID *nameIdentifier;
SOGoSystemDefaults *sd;
NSString *loginAttribue; NSString *loginAttribue;
SOGoSystemDefaults *sd;
gchar *dump; gchar *dump;
saml2Assertion = LASSO_SAML2_ASSERTION (lasso_login_get_assertion (lassoLogin)); lassoNode = lasso_login_get_assertion (lassoLogin);
saml2Assertion = LASSO_SAML2_ASSERTION (lassoNode);
sd = [SOGoSystemDefaults sharedSystemDefaults]; sd = [SOGoSystemDefaults sharedSystemDefaults];
loginAttribue = [sd SAML2LoginAttribute]; loginAttribue = [sd SAML2LoginAttribute];
if (saml2Assertion) if (saml2Assertion)
{ {
/* deduce user login */ /* deduce user login */
@ -267,6 +268,7 @@ static NSMapTable *serverTable = nil;
while (!login && attributeList) while (!login && attributeList)
{ {
attribute = LASSO_SAML2_ATTRIBUTE (attributeList->data); attribute = LASSO_SAML2_ATTRIBUTE (attributeList->data);
if (loginAttribue && (strcmp (attribute->Name, [loginAttribue UTF8String]) == 0)) if (loginAttribue && (strcmp (attribute->Name, [loginAttribue UTF8String]) == 0))
{ {
value = LASSO_SAML2_ATTRIBUTE_VALUE (attribute->AttributeValue->data); value = LASSO_SAML2_ATTRIBUTE_VALUE (attribute->AttributeValue->data);
@ -320,8 +322,7 @@ static NSMapTable *serverTable = nil;
assertion = nil; assertion = nil;
} }
nameIdentifier nameIdentifier = LASSO_SAML2_NAME_ID (LASSO_PROFILE (lassoLogin)->nameIdentifier);
= LASSO_SAML2_NAME_ID (LASSO_PROFILE (lassoLogin)->nameIdentifier);
if (nameIdentifier) if (nameIdentifier)
{ {
/* deduce session id */ /* deduce session id */
@ -334,7 +335,7 @@ static NSMapTable *serverTable = nil;
- (id) _initWithDump: (NSDictionary *) saml2Dump - (id) _initWithDump: (NSDictionary *) saml2Dump
inContext: (WOContext *) context inContext: (WOContext *) context
{ {
// lasso_error_t rc; lasso_error_t rc;
LassoServer *server; LassoServer *server;
LassoProfile *profile; LassoProfile *profile;
const gchar *dump; const gchar *dump;
@ -346,10 +347,10 @@ static NSMapTable *serverTable = nil;
if (saml2Dump) if (saml2Dump)
{ {
profile = LASSO_PROFILE (lassoLogin); profile = LASSO_PROFILE (lassoLogin);
ASSIGN (login, [saml2Dump objectForKey: @"login"]); ASSIGN (login, [saml2Dump objectForKey: @"login"]);
ASSIGN (identifier, [saml2Dump objectForKey: @"identifier"]); ASSIGN (identifier, [saml2Dump objectForKey: @"identifier"]);
ASSIGN (assertion, [saml2Dump objectForKey: @"assertion"]); ASSIGN (assertion, [saml2Dump objectForKey: @"assertion"]);
ASSIGN(identity, [saml2Dump objectForKey: @"identity"]); ASSIGN(identity, [saml2Dump objectForKey: @"identity"]);
dump = [identity UTF8String]; dump = [identity UTF8String];
if (dump) if (dump)
@ -359,11 +360,10 @@ static NSMapTable *serverTable = nil;
dump = [session UTF8String]; dump = [session UTF8String];
if (dump) if (dump)
lasso_profile_set_session_from_dump (profile, dump); lasso_profile_set_session_from_dump (profile, dump);
lasso_login_accept_sso (lassoLogin); rc = lasso_login_accept_sso (lassoLogin);
// if (rc) if (!rc)
// [NSException raiseSAML2Exception: rc]; [self _updateDataFromLogin];
[self _updateDataFromLogin];
} }
} }
@ -454,6 +454,7 @@ static NSMapTable *serverTable = nil;
responseData = strdup ([authnResponse UTF8String]); responseData = strdup ([authnResponse UTF8String]);
profile = LASSO_PROFILE (lassoLogin);
rc = lasso_login_process_authn_response_msg (lassoLogin, responseData); rc = lasso_login_process_authn_response_msg (lassoLogin, responseData);
if (rc) if (rc)
[NSException raiseSAML2Exception: rc]; [NSException raiseSAML2Exception: rc];
@ -469,8 +470,6 @@ static NSMapTable *serverTable = nil;
[saml2Dump setObject: identifier forKey: @"identifier"]; [saml2Dump setObject: identifier forKey: @"identifier"];
[saml2Dump setObject: assertion forKey: @"assertion"]; [saml2Dump setObject: assertion forKey: @"assertion"];
profile = LASSO_PROFILE (lassoLogin);
lasso_session = lasso_profile_get_session (profile); lasso_session = lasso_profile_get_session (profile);
if (lasso_session) if (lasso_session)
{ {