#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
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"];
}
}
- (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