1 /* SOGoWebAuthenticator.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSUserDefaults.h>
27 #import <NGObjWeb/WOApplication.h>
28 #import <NGObjWeb/WOContext.h>
29 #import <NGObjWeb/WORequest.h>
30 #import <NGObjWeb/WOResponse.h>
31 #import <NGLdap/NGLdapConnection.h>
33 #import <UI/MainUI/SOGoRootPage.h>
35 #import "LDAPUserManager.h"
36 #import "SOGoPermissions.h"
39 #import "SOGoWebAuthenticator.h"
41 @implementation SOGoWebAuthenticator
43 + (id) sharedSOGoWebAuthenticator
45 static SOGoWebAuthenticator *auth = nil;
55 if ((self = [super init]))
57 authMethod = [[NSUserDefaults standardUserDefaults]
58 stringForKey: @"SOGoAuthentificationMethod"];
71 - (BOOL) checkLogin: (NSString *) _login
72 password: (NSString *) _pwd
77 if ([authMethod isEqualToString: @"LDAP"])
79 um = [LDAPUserManager sharedUserManager];
80 accept = [um checkLogin: _login andPassword: _pwd];
83 accept = ([authMethod isEqualToString: @"bypass"]
84 && [_login length] > 0);
87 // || ([_login isEqualToString: @"freebusy"]
88 // && [_pwd isEqualToString: @"freebusy"]));
91 - (NSString *) passwordInContext: (WOContext *) context
94 NSString *auth, *password;
96 auth = [[context request] cookieValueForKey:
97 [self cookieNameInContext: context]];
98 creds = [self parseCredentials: auth];
99 if ([creds count] > 1)
100 password = [creds objectAtIndex: 1];
107 /* create SOGoUser */
109 - (SOGoUser *) userWithLogin: (NSString *) login
110 andRoles: (NSArray *) roles
111 inContext: (WOContext *) ctx
113 /* the actual factory method */
114 return [SOGoUser userWithLogin: login roles: roles];
117 - (void) setupAuthFailResponse: (WOResponse *) response
118 withReason: (NSString *) reason
119 inContext: (WOContext *) context
123 page = [[WOApplication application] pageWithName: @"SOGoRootPage"
124 forRequest: [context request]];
125 [page appendToResponse: response inContext: context];
128 @end /* SOGoWebAuthenticator */