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
78 if ([authMethod isEqualToString: @"LDAP"])
79 result = [self LDAPCheckLogin: _login password: _pwd];
82 if ([_login length] == 0)
91 - (BOOL) LDAPCheckLogin: (NSString *) _login
92 password: (NSString *) _pwd
94 return [NGLdapConnection checkPassword: _pwd
101 /* create SOGoUser */
103 - (SoUser *) userInContext:(WOContext *)_ctx
105 static SoUser *anonymous = nil, *freebusy;
110 = [[SOGoUser alloc] initWithLogin:@"anonymous"
111 roles: [NSArray arrayWithObject: SoRole_Anonymous]];
115 = [[SOGoUser alloc] initWithLogin: @"freebusy"
116 roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
118 if ((login = [self checkCredentialsInContext:_ctx]) == nil)
119 /* some error (otherwise result would have been anonymous */
122 if ([login isEqualToString: @"anonymous"])
124 else if ([login isEqualToString: @"freebusy"])
127 // uroles = [NSMutableArray arrayWithArray: ];
129 return [[[SOGoUser alloc] initWithLogin: login
130 roles: [self rolesForLogin: login]]
134 // - (BOOL) renderException: (NSException *) exception
135 // inContext: (WOContext *) context
137 // id renderedException;
138 // WOComponent *tmpComponent;
139 // WOResponse *response;
142 // rc = [super renderException: exception inContext: context];
145 // tmpComponent = [WOComponent new];
146 // renderedException = [tmpComponent pageWithName: @"UIxException"];
147 // if (renderedException)
150 // response = [context response];
151 // [response setHeader: @"text/html" forKey: @"content-type"];
152 // [renderedException setClientObject: exception];
153 // [context setPage: renderedException];
154 // [renderedException appendToResponse: response
155 // inContext: context];
157 // [tmpComponent release];
163 @end /* SOGoAuthenticator */