]> err.no Git - scalable-opengroupware.org/blobdiff - SoObjects/SOGo/SOGoAuthenticator.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1052 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoAuthenticator.m
index 00205e6fd373242f8f45ea87ded6f94850b41672..134dba0235f104ae0eef91ddfd45e4583481b28e 100644 (file)
 #import <NGLdap/NGLdapConnection.h>
 #import "SOGoPermissions.h"
 
-#include "SOGoAuthenticator.h"
-#include "SOGoUser.h"
-#include "common.h"
+#import "LDAPUserManager.h"
+
+#import "SOGoAuthenticator.h"
+#import "SOGoUser.h"
+#import "common.h"
 
 @implementation SOGoAuthenticator
 
@@ -50,9 +52,9 @@ static SOGoAuthenticator *auth = nil;
       authMethod = [[ud stringForKey:@"AuthentificationMethod"] retain];
       if ([authMethod isEqualToString: @"LDAP"])
        {
-         LDAPBaseDN = [[ud stringForKey:@"LDAPRootDN"] retain];
-         LDAPHost = [[ud stringForKey:@"LDAPHost"] retain];
-         LDAPPort = [ud integerForKey:@"LDAPPort"];
+//       LDAPBaseDN = [[ud stringForKey:@"LDAPRootDN"] retain];
+//       LDAPHost = [[ud stringForKey:@"LDAPHost"] retain];
+//       LDAPPort = [ud integerForKey:@"LDAPPort"];
        }
     }
 
@@ -72,63 +74,65 @@ static SOGoAuthenticator *auth = nil;
 - (BOOL) checkLogin: (NSString *) _login
           password: (NSString *) _pwd
 {
-  BOOL result;
+  BOOL accept;
 
-//   return YES;
   if ([authMethod isEqualToString: @"LDAP"])
-    result = [self LDAPCheckLogin: _login password: _pwd];
+    accept = [self LDAPCheckLogin: _login password: _pwd];
   else
-    {
-      if ([_login length] == 0)
-       result = NO;
-      else
-       result = YES;
-    }
+    accept = ([_login length] > 0);
 
-  return result;
+  return (([_login isEqualToString: @"freebusy"]
+           && [_pwd isEqualToString: @"freebusy"])
+          || accept);
 }
 
 - (BOOL) LDAPCheckLogin: (NSString *) _login
               password: (NSString *) _pwd
 {
-  return [NGLdapConnection checkPassword: _pwd
-                          ofLogin: _login
-                          atBaseDN: LDAPBaseDN
-                          onHost: LDAPHost
-                          port: LDAPPort];
+  LDAPUserManager *um;
+
+  um = [LDAPUserManager sharedUserManager];
+
+  return [um checkLogin: _login andPassword: _pwd];
 }
 
 /* create SOGoUser */
 
-- (SoUser *) userInContext:(WOContext *)_ctx
+- (SOGoUser *) userInContext: (WOContext *)_ctx
 {
-  static SoUser *anonymous = nil, *freebusy;
-  NSString  *login;
-  
+  static SOGoUser *anonymous = nil, *freebusy;
+  SOGoUser *user;
+  NSArray *traversalPath;
+  NSString *login;
+
   if (!anonymous)
     anonymous
-      = [[SOGoUser alloc] initWithLogin:@"anonymous"
+      = [[SOGoUser alloc] initWithLogin: @"anonymous"
                          roles: [NSArray arrayWithObject: SoRole_Anonymous]];
-
   if (!freebusy)
     freebusy
       = [[SOGoUser alloc] initWithLogin: @"freebusy"
                           roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
 
-  if ((login = [self checkCredentialsInContext:_ctx]) == nil)
-    /* some error (otherwise result would have been anonymous */
-    return nil;
-  
-  if ([login isEqualToString: @"anonymous"])
-    return anonymous;
-  else if ([login isEqualToString: @"freebusy"])
-    return freebusy;
-
-//   uroles = [NSMutableArray arrayWithArray: ];
+  login = [self checkCredentialsInContext:_ctx];
+  if (login)
+    {
+      if ([login isEqualToString: @"anonymous"])
+        {
+          traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
+          if ([[traversalPath lastObject] isEqualToString: @"freebusy.ifb"])
+            user = freebusy;
+          else
+            user = anonymous;
+        }
+      else
+        user = [SOGoUser userWithLogin: login
+                        roles: [self rolesForLogin: login]];
+    }
+  else
+    user = nil;
 
-  return [[[SOGoUser alloc] initWithLogin: login
-                            roles: [self rolesForLogin: login]]
-          autorelease];
+  return user;
 }
 
 // - (BOOL) renderException: (NSException *) exception