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: @"SOGoAuthentificationMethod"];
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 = ([authMethod isEqualToString: @"bypass"]
79 && [_login length] > 0);
82 // || ([_login isEqualToString: @"freebusy"]
83 // && [_pwd isEqualToString: @"freebusy"]));
86 - (NSString *) passwordInContext: (WOContext *) context
88 NSString *auth, *password;
92 auth = [[context request] headerForKey: @"authorization"];
95 creds = [self parseCredentials: auth];
96 if ([creds count] > 1)
97 password = [creds objectAtIndex: 1];
103 /* create SOGoUser */
105 - (SOGoUser *) userInContext: (WOContext *)_ctx
107 static SOGoUser *anonymous = nil;
109 NSArray *traversalPath;
114 = [[SOGoUser alloc] initWithLogin: @"anonymous"
115 roles: [NSArray arrayWithObject: SoRole_Anonymous]];
117 login = [self checkCredentialsInContext:_ctx];
120 if ([login isEqualToString: @"anonymous"])
122 traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
127 user = [SOGoUser userWithLogin: login
128 roles: [self rolesForLogin: login]];
129 [user setCurrentPassword: [self passwordInContext: _ctx]];
138 // - (BOOL) renderException: (NSException *) exception
139 // inContext: (WOContext *) context
141 // id renderedException;
142 // WOComponent *tmpComponent;
143 // WOResponse *response;
146 // rc = [super renderException: exception inContext: context];
149 // tmpComponent = [WOComponent new];
150 // renderedException = [tmpComponent pageWithName: @"UIxException"];
151 // if (renderedException)
154 // response = [context response];
155 // [response setHeader: @"text/html" forKey: @"content-type"];
156 // [renderedException setClientObject: exception];
157 // [context setPage: renderedException];
158 // [renderedException appendToResponse: response
159 // inContext: context];
161 // [tmpComponent release];
167 @end /* SOGoAuthenticator */