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
23 #include "DSoAuthenticator.h"
25 #include <GDLAccess/GDLAccess.h>
29 - authenticators themselves are _not_ bound to a context or a SOPE
31 - because of that we need to duplicate some stuff
32 => or use a separate layer which handles uniquing
35 @implementation DSoAuthenticator
37 static BOOL debugOn = NO;
39 // TODO: might want to cache authenticator objects ...
41 - (id)initWithHostName:(NSString *)_hostname port:(int)_port
42 databaseName:(NSString *)_dbname
44 if ((self = [super init])) {
45 self->hostname = [_hostname copy];
47 self->dbname = [_dbname copy];
52 + (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port {
53 return [[[self alloc] initWithHostName:_hostname port:_port
54 databaseName:nil] autorelease];
56 + (id)authenticatorWithHostName:(NSString *)_hostname port:(int)_port
57 databaseName:(NSString *)_dbname
59 return [[[self alloc] initWithHostName:_hostname port:_port
60 databaseName:_dbname] autorelease];
64 [self->hostname release];
65 [self->dbname release];
71 - (NSString *)authRealm {
73 the HTTP authentication realm, we use the database info (default is the
74 application name, but in our case we can be more specific)
76 if (self->dbname == nil)
77 return self->hostname;
79 return [[self->dbname stringByAppendingString:@"@"]
80 stringByAppendingString:self->hostname];
85 - (NSString *)defaultDatabase {
86 /* template1 is supposed to exist always (#postgresql channel ;-) */
90 - (EOAdaptor *)adaptorForLogin:(NSString *)_login password:(NSString *)_pwd {
92 NSDictionary *condict;
95 if ((adaptor = [EOAdaptor adaptorWithName:@"PostgreSQL72"]) == nil)
98 if (![_login isNotNull]) _login = @"";
99 if (![_pwd isNotNull]) _pwd = @"";
101 dbn = [self->dbname isNotNull] ? self->dbname : [self defaultDatabase];
103 // TODO: ignores port
104 condict = [[NSDictionary alloc] initWithObjectsAndKeys:
105 self->hostname, @"hostName",
108 dbn, @"databaseName",
110 [adaptor setConnectionDictionary:condict];
115 /* check credentials */
117 - (BOOL)checkLogin:(NSString *)_login password:(NSString *)_pwd {
119 EOAdaptorContext *adctx;
120 EOAdaptorChannel *adch;
123 [self debugWithFormat:@"check login: %@", _login];
125 /* create all necessary objects */
127 adaptor = [self adaptorForLogin:_login password:_pwd];
128 adctx = [adaptor createAdaptorContext];
129 adch = [adctx createAdaptorChannel];
131 [self debugWithFormat:@" channel: %@", adch];
133 /* open channel to check whether credentials are valid */
135 if ((ok = [adch openChannel]))
138 [self debugWithFormat:@"could not open the channel."];
145 - (BOOL)isDebuggingEnabled {
149 @end /* DSoAuthenticator */