X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=SoObjects%2FSOGo%2FSOGoAuthenticator.m;h=0c8d5c0a8b950bbe169a13d09714e71d50e3e10a;hb=4a618da690a9beadcefd0ea89a921900e3897ce8;hp=134dba0235f104ae0eef91ddfd45e4583481b28e;hpb=ab66b6ca55944e8393de4ccf5c4608bd34c83f5e;p=scalable-opengroupware.org diff --git a/SoObjects/SOGo/SOGoAuthenticator.m b/SoObjects/SOGo/SOGoAuthenticator.m index 134dba02..0c8d5c0a 100644 --- a/SoObjects/SOGo/SOGoAuthenticator.m +++ b/SoObjects/SOGo/SOGoAuthenticator.m @@ -19,43 +19,41 @@ 02111-1307, USA. */ +#import +#import +#import + +#import +#import #import -#import "SOGoPermissions.h" #import "LDAPUserManager.h" +#import "SOGoPermissions.h" +#import "SOGoUser.h" #import "SOGoAuthenticator.h" -#import "SOGoUser.h" -#import "common.h" @implementation SOGoAuthenticator -static SOGoAuthenticator *auth = nil; - + (id) sharedSOGoAuthenticator { - if (auth == nil) - auth = [[self alloc] init]; + static SOGoAuthenticator *auth = nil; + + if (!auth) + auth = [self new]; + return auth; } - (id) init { + NSUserDefaults *ud; + if ((self = [super init])) { ud = [NSUserDefaults standardUserDefaults]; - LDAPBaseDN = nil; - LDAPHost = nil; - LDAPPort = -1; - authMethod = [[ud stringForKey:@"AuthentificationMethod"] retain]; - if ([authMethod isEqualToString: @"LDAP"]) - { -// LDAPBaseDN = [[ud stringForKey:@"LDAPRootDN"] retain]; -// LDAPHost = [[ud stringForKey:@"LDAPHost"] retain]; -// LDAPPort = [ud integerForKey:@"LDAPPort"]; - } } return self; @@ -63,10 +61,6 @@ static SOGoAuthenticator *auth = nil; - (void) dealloc { - if (LDAPBaseDN) - [LDAPBaseDN release]; - if (LDAPHost) - [LDAPHost release]; [authMethod release]; [super dealloc]; } @@ -75,25 +69,36 @@ static SOGoAuthenticator *auth = nil; password: (NSString *) _pwd { BOOL accept; + LDAPUserManager *um; if ([authMethod isEqualToString: @"LDAP"]) - accept = [self LDAPCheckLogin: _login password: _pwd]; + { + um = [LDAPUserManager sharedUserManager]; + accept = [um checkLogin: _login andPassword: _pwd]; + } else accept = ([_login length] > 0); - return (([_login isEqualToString: @"freebusy"] - && [_pwd isEqualToString: @"freebusy"]) - || accept); + return (accept + || ([_login isEqualToString: @"freebusy"] + && [_pwd isEqualToString: @"freebusy"])); } -- (BOOL) LDAPCheckLogin: (NSString *) _login - password: (NSString *) _pwd +- (NSString *) _passwordInContext: (WOContext *) context { - LDAPUserManager *um; - - um = [LDAPUserManager sharedUserManager]; + NSString *auth, *password; + NSArray *creds; - return [um checkLogin: _login andPassword: _pwd]; + password = nil; + auth = [[context request] headerForKey:@"authorization"]; + if (auth) + { + creds = [self parseCredentials: auth]; + if ([creds count] > 1) + password = [creds objectAtIndex: 1]; + } + + return password; } /* create SOGoUser */ @@ -126,8 +131,11 @@ static SOGoAuthenticator *auth = nil; user = anonymous; } else - user = [SOGoUser userWithLogin: login - roles: [self rolesForLogin: login]]; + { + user = [SOGoUser userWithLogin: login + roles: [self rolesForLogin: login]]; + [user setCurrentPassword: [self _passwordInContext: _ctx]]; + } } else user = nil;