2 Copyright (C) 2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <NGLdap/NGLdapConnection.h>
23 #import "SOGoPermissions.h"
25 #include "SOGoAuthenticator.h"
29 @implementation SOGoAuthenticator
31 static SOGoAuthenticator *auth = nil;
33 + (id) sharedSOGoAuthenticator
36 auth = [[self alloc] init];
42 if ((self = [super init]))
44 ud = [NSUserDefaults standardUserDefaults];
50 authMethod = [[ud stringForKey:@"AuthentificationMethod"] retain];
51 if ([authMethod isEqualToString: @"LDAP"])
53 LDAPBaseDN = [[ud stringForKey:@"LDAPRootDN"] retain];
54 LDAPHost = [[ud stringForKey:@"LDAPHost"] retain];
55 LDAPPort = [ud integerForKey:@"LDAPPort"];
72 - (BOOL) checkLogin: (NSString *) _login
73 password: (NSString *) _pwd
77 if ([authMethod isEqualToString: @"LDAP"])
78 accept = [self LDAPCheckLogin: _login password: _pwd];
80 accept = ([_login length] > 0);
82 return (([_login isEqualToString: @"freebusy"]
83 && [_pwd isEqualToString: @"freebusy"])
87 - (BOOL) LDAPCheckLogin: (NSString *) _login
88 password: (NSString *) _pwd
90 return [NGLdapConnection checkPassword: _pwd
99 - (SoUser *) userInContext:(WOContext *)_ctx
101 static SoUser *anonymous = nil, *freebusy;
103 NSArray *traversalPath;
108 = [[SOGoUser alloc] initWithLogin:@"anonymous"
109 roles: [NSArray arrayWithObject: SoRole_Anonymous]];
112 = [[SOGoUser alloc] initWithLogin: @"freebusy"
113 roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
115 login = [self checkCredentialsInContext:_ctx];
118 if ([login isEqualToString: @"anonymous"])
120 traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
121 if ([[traversalPath lastObject] isEqualToString: @"freebusy.ifb"])
127 user = [[[SOGoUser alloc] initWithLogin: login
128 roles: [self rolesForLogin: login]]
137 // - (BOOL) renderException: (NSException *) exception
138 // inContext: (WOContext *) context
140 // id renderedException;
141 // WOComponent *tmpComponent;
142 // WOResponse *response;
145 // rc = [super renderException: exception inContext: context];
148 // tmpComponent = [WOComponent new];
149 // renderedException = [tmpComponent pageWithName: @"UIxException"];
150 // if (renderedException)
153 // response = [context response];
154 // [response setHeader: @"text/html" forKey: @"content-type"];
155 // [renderedException setClientObject: exception];
156 // [context setPage: renderedException];
157 // [renderedException appendToResponse: response
158 // inContext: context];
160 // [tmpComponent release];
166 @end /* SOGoAuthenticator */