02111-1307, USA.
*/
+#import <Foundation/NSArray.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSUserDefaults.h>
+
+#import <NGObjWeb/WOContext.h>
+#import <NGObjWeb/WOResponse.h>
#import <NGLdap/NGLdapConnection.h>
-#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;
- (void) dealloc
{
- if (LDAPBaseDN)
- [LDAPBaseDN release];
- if (LDAPHost)
- [LDAPHost release];
[authMethod release];
[super dealloc];
}
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 */
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;