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;
52 if ((self = [super init]))
54 ud = [NSUserDefaults standardUserDefaults];
56 authMethod = [[ud stringForKey:@"AuthentificationMethod"] retain];
68 - (BOOL) checkLogin: (NSString *) _login
69 password: (NSString *) _pwd
74 if ([authMethod isEqualToString: @"LDAP"])
76 um = [LDAPUserManager sharedUserManager];
77 accept = [um checkLogin: _login andPassword: _pwd];
80 accept = ([_login length] > 0);
83 || ([_login isEqualToString: @"freebusy"]
84 && [_pwd isEqualToString: @"freebusy"]));
87 - (NSString *) _passwordInContext: (WOContext *) context
89 NSString *auth, *password;
93 auth = [[context request] headerForKey:@"authorization"];
96 creds = [self parseCredentials: auth];
97 if ([creds count] > 1)
98 password = [creds objectAtIndex: 1];
104 /* create SOGoUser */
106 - (SOGoUser *) userInContext: (WOContext *)_ctx
108 static SOGoUser *anonymous = nil, *freebusy;
110 NSArray *traversalPath;
115 = [[SOGoUser alloc] initWithLogin: @"anonymous"
116 roles: [NSArray arrayWithObject: SoRole_Anonymous]];
119 = [[SOGoUser alloc] initWithLogin: @"freebusy"
120 roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
122 login = [self checkCredentialsInContext:_ctx];
125 if ([login isEqualToString: @"anonymous"])
127 traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
128 if ([[traversalPath lastObject] isEqualToString: @"freebusy.ifb"])
135 user = [SOGoUser userWithLogin: login
136 roles: [self rolesForLogin: login]];
137 [user setCurrentPassword: [self _passwordInContext: _ctx]];
146 // - (BOOL) renderException: (NSException *) exception
147 // inContext: (WOContext *) context
149 // id renderedException;
150 // WOComponent *tmpComponent;
151 // WOResponse *response;
154 // rc = [super renderException: exception inContext: context];
157 // tmpComponent = [WOComponent new];
158 // renderedException = [tmpComponent pageWithName: @"UIxException"];
159 // if (renderedException)
162 // response = [context response];
163 // [response setHeader: @"text/html" forKey: @"content-type"];
164 // [renderedException setClientObject: exception];
165 // [context setPage: renderedException];
166 // [renderedException appendToResponse: response
167 // inContext: context];
169 // [tmpComponent release];
175 @end /* SOGoAuthenticator */