]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoWebAuthenticator.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1166 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoWebAuthenticator.m
1 /* SOGoWebAuthenticator.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSUserDefaults.h>
26
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>
32
33 #import <UI/MainUI/SOGoRootPage.h>
34
35 #import "LDAPUserManager.h"
36 #import "SOGoPermissions.h"
37 #import "SOGoUser.h"
38
39 #import "SOGoWebAuthenticator.h"
40
41 @implementation SOGoWebAuthenticator
42
43 + (id) sharedSOGoWebAuthenticator
44 {
45   static SOGoWebAuthenticator *auth = nil;
46  
47   if (!auth)
48     auth = [self new];
49
50   return auth;
51 }
52
53 - (id) init
54 {
55   if ((self = [super init]))
56     {
57       authMethod = [[NSUserDefaults standardUserDefaults]
58                      stringForKey: @"SOGoAuthentificationMethod"];
59       [authMethod retain];
60     }
61
62   return self;
63 }
64
65 - (void) dealloc
66 {
67   [authMethod release];
68   [super dealloc];
69 }
70
71 - (BOOL) checkLogin: (NSString *) _login
72            password: (NSString *) _pwd
73 {
74   BOOL accept;
75   LDAPUserManager *um;
76
77   if ([authMethod isEqualToString: @"LDAP"])
78     {
79       um = [LDAPUserManager sharedUserManager];
80       accept = [um checkLogin: _login andPassword: _pwd];
81     }
82   else
83     accept = ([authMethod isEqualToString: @"bypass"]
84               && [_login length] > 0);
85
86   return accept;
87 //        || ([_login isEqualToString: @"freebusy"]
88 //            && [_pwd isEqualToString: @"freebusy"]));
89 }
90
91 - (NSString *) passwordInContext: (WOContext *) context
92 {
93   NSArray *creds;
94   NSString *auth, *password;
95   
96   auth = [[context request] cookieValueForKey:
97                               [self cookieNameInContext: context]];
98   creds = [self parseCredentials: auth];
99   if ([creds count] > 1)
100     password = [creds objectAtIndex: 1];
101   else
102     password = nil;
103
104   return password;
105 }
106
107 /* create SOGoUser */
108
109 - (SOGoUser *) userWithLogin: (NSString *) login
110                     andRoles: (NSArray *) roles
111                    inContext: (WOContext *) ctx
112 {
113   /* the actual factory method */
114   return [SOGoUser userWithLogin: login roles: roles];
115 }
116
117 - (void) setupAuthFailResponse: (WOResponse *) response
118                     withReason: (NSString *) reason
119                      inContext: (WOContext *) context
120 {
121   id page;
122
123   page = [[WOApplication application] pageWithName: @"SOGoRootPage"
124                                       forRequest: [context request]];
125   [page appendToResponse: response inContext: context];
126 }
127
128 @end /* SOGoWebAuthenticator */