]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoAuthenticator.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1086 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoAuthenticator.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <NGLdap/NGLdapConnection.h>
23 #import "SOGoPermissions.h"
24
25 #import "LDAPUserManager.h"
26
27 #import "SOGoAuthenticator.h"
28 #import "SOGoUser.h"
29 #import "common.h"
30
31 @implementation SOGoAuthenticator
32
33 static SOGoAuthenticator *auth = nil;
34
35 + (id) sharedSOGoAuthenticator
36 {
37   if (auth == nil)
38     auth = [[self alloc] init];
39   return auth;
40 }
41
42 - (id) init
43 {
44   if ((self = [super init]))
45     {
46       ud = [NSUserDefaults standardUserDefaults];
47
48       LDAPBaseDN = nil;
49       LDAPHost = nil;
50       LDAPPort = -1;
51
52       authMethod = [[ud stringForKey:@"AuthentificationMethod"] retain];
53       if ([authMethod isEqualToString: @"LDAP"])
54         {
55 //        LDAPBaseDN = [[ud stringForKey:@"LDAPRootDN"] retain];
56 //        LDAPHost = [[ud stringForKey:@"LDAPHost"] retain];
57 //        LDAPPort = [ud integerForKey:@"LDAPPort"];
58         }
59     }
60
61   return self;
62 }
63
64 - (void) dealloc
65 {
66   if (LDAPBaseDN)
67     [LDAPBaseDN release];
68   if (LDAPHost)
69     [LDAPHost release];
70   [authMethod release];
71   [super dealloc];
72 }
73
74 - (BOOL) checkLogin: (NSString *) _login
75            password: (NSString *) _pwd
76 {
77   BOOL accept;
78
79   if ([authMethod isEqualToString: @"LDAP"])
80     accept = [self LDAPCheckLogin: _login password: _pwd];
81   else
82     accept = ([_login length] > 0);
83
84   return (([_login isEqualToString: @"freebusy"]
85            && [_pwd isEqualToString: @"freebusy"])
86           || accept);
87 }
88
89 - (BOOL) LDAPCheckLogin: (NSString *) _login
90                password: (NSString *) _pwd
91 {
92   LDAPUserManager *um;
93
94   um = [LDAPUserManager sharedUserManager];
95
96   return [um checkLogin: _login andPassword: _pwd];
97 }
98
99 /* create SOGoUser */
100
101 - (SOGoUser *) userInContext: (WOContext *)_ctx
102 {
103   static SOGoUser *anonymous = nil, *freebusy;
104   SOGoUser *user;
105   NSArray *traversalPath;
106   NSString *login;
107
108   if (!anonymous)
109     anonymous
110       = [[SOGoUser alloc] initWithLogin: @"anonymous"
111                           roles: [NSArray arrayWithObject: SoRole_Anonymous]];
112   if (!freebusy)
113     freebusy
114       = [[SOGoUser alloc] initWithLogin: @"freebusy"
115                           roles: [NSArray arrayWithObject: SOGoRole_FreeBusy]];
116
117   login = [self checkCredentialsInContext:_ctx];
118   if (login)
119     {
120       if ([login isEqualToString: @"anonymous"])
121         {
122           traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
123           if ([[traversalPath lastObject] isEqualToString: @"freebusy.ifb"])
124             user = freebusy;
125           else
126             user = anonymous;
127         }
128       else
129         user = [SOGoUser userWithLogin: login
130                          roles: [self rolesForLogin: login]];
131     }
132   else
133     user = nil;
134
135   return user;
136 }
137
138 // - (BOOL) renderException: (NSException *) exception
139 //                inContext: (WOContext *) context
140 // {
141 //   id renderedException;
142 //   WOComponent *tmpComponent;
143 //   WOResponse *response;
144 //   BOOL rc;
145
146 //   rc = [super renderException: exception inContext: context];
147 //   if (!rc)
148 //     {
149 //       tmpComponent = [WOComponent new];
150 //       renderedException = [tmpComponent pageWithName: @"UIxException"];
151 //       if (renderedException)
152 //         {
153 //           rc = YES;
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];
160 //         }
161 //       [tmpComponent release];
162 //     }
163
164 //   return rc;
165 // }
166
167 @end /* SOGoAuthenticator */