]> err.no Git - scalable-opengroupware.org/blobdiff - SoObjects/SOGo/SOGoAuthenticator.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1087 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoAuthenticator.m
index 134dba0235f104ae0eef91ddfd45e4583481b28e..0c8d5c0a8b950bbe169a13d09714e71d50e3e10a 100644 (file)
   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;
@@ -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;