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 <Foundation/NSArray.h>
23 #import <Foundation/NSString.h>
24 #import <Foundation/NSUserDefaults.h>
26 #import <NGObjWeb/WOContext.h>
27 #import <NGObjWeb/WOResponse.h>
28 #import <NGLdap/NGLdapConnection.h>
30 #import "LDAPUserManager.h"
31 #import "SOGoPermissions.h"
34 #import "SOGoAuthenticator.h"
36 @implementation SOGoAuthenticator
38 + (id) sharedSOGoAuthenticator
40 static SOGoAuthenticator *auth = nil;
50 if ((self = [super init]))
52 authMethod = [[NSUserDefaults standardUserDefaults]
53 stringForKey: @"AuthentificationMethod"];
66 - (BOOL) checkLogin: (NSString *) _login
67 password: (NSString *) _pwd
72 if ([authMethod isEqualToString: @"LDAP"])
74 um = [LDAPUserManager sharedUserManager];
75 accept = [um checkLogin: _login andPassword: _pwd];
78 accept = ([_login length] > 0);
81 // || ([_login isEqualToString: @"freebusy"]
82 // && [_pwd isEqualToString: @"freebusy"]));
85 - (NSString *) _passwordInContext: (WOContext *) context
87 NSString *auth, *password;
91 auth = [[context request] headerForKey: @"authorization"];
94 creds = [self parseCredentials: auth];
95 if ([creds count] > 1)
96 password = [creds objectAtIndex: 1];
102 /* create SOGoUser */
104 - (SOGoUser *) userInContext: (WOContext *)_ctx
106 static SOGoUser *anonymous = nil;
108 NSArray *traversalPath;
113 = [[SOGoUser alloc] initWithLogin: @"anonymous"
114 roles: [NSArray arrayWithObject: SoRole_Anonymous]];
117 // = [[SOGoUser alloc] initWithLogin: @"freebusy"
118 // roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
120 login = [self checkCredentialsInContext:_ctx];
123 if ([login isEqualToString: @"anonymous"])
125 traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
126 // if ([[traversalPath lastObject] isEqualToString: @"freebusy.ifb"])
133 user = [SOGoUser userWithLogin: login
134 roles: [self rolesForLogin: login]];
135 [user setCurrentPassword: [self _passwordInContext: _ctx]];
144 // - (BOOL) renderException: (NSException *) exception
145 // inContext: (WOContext *) context
147 // id renderedException;
148 // WOComponent *tmpComponent;
149 // WOResponse *response;
152 // rc = [super renderException: exception inContext: context];
155 // tmpComponent = [WOComponent new];
156 // renderedException = [tmpComponent pageWithName: @"UIxException"];
157 // if (renderedException)
160 // response = [context response];
161 // [response setHeader: @"text/html" forKey: @"content-type"];
162 // [renderedException setClientObject: exception];
163 // [context setPage: renderedException];
164 // [renderedException appendToResponse: response
165 // inContext: context];
167 // [tmpComponent release];
173 @end /* SOGoAuthenticator */