Monotone-Parent: 4e7dca3054e95b38b822f5fc8ff05e3b263e1e91

Monotone-Revision: 78533df190b5cd6050f9b57ff65db1e242028164

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-12-02T20:53:52
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2009-12-02 20:53:52 +00:00
parent 29f7d5c7d8
commit bc8e5a9998
3 changed files with 72 additions and 23 deletions
+9
View File
@@ -1,3 +1,12 @@
2009-12-02 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* SoObjects/SOGo/SOGoUserManager.m: added new
"SOGoUserManagerRegistry" class that handles the mapping between
source types and their corresponding classes.
(-[SOGoUserManager registryClass]): new method that returns the
class name of the registry class, which can be overriden to handle
other types.
2009-12-01 Ludovic Marcotte <lmarcotte@inverse.ca>
* Reworked the calendar's categories (introduced
+11
View File
@@ -35,15 +35,26 @@
@protocol SOGoSource;
@interface SOGoUserManagerRegistry : NSObject
+ (id) sharedRegistry;
- (NSString *) sourceClassForType: (NSString *) type;
@end
@interface SOGoUserManager : NSObject
{
@private
SOGoUserManagerRegistry *_registry;
NSMutableDictionary *_sources;
NSMutableDictionary *_sourcesMetadata;
}
+ (id) sharedUserManager;
- (NSString *) registryClass;
- (NSArray *) sourceIDsInDomain: (NSString *) domain;
- (NSArray *) authenticationSourceIDsInDomain: (NSString *) domain;
- (NSArray *) addressBookSourceIDsInDomain: (NSString *) domain;
+52 -23
View File
@@ -22,6 +22,7 @@
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTimer.h>
@@ -37,8 +38,39 @@
#import "SOGoCache.h"
#import "SOGoSource.h"
#import "LDAPSource.h"
#import "SQLSource.h"
@implementation SOGoUserManagerRegistry
+ (id) sharedRegistry
{
static id sharedRegistry = nil;
if (!sharedRegistry)
sharedRegistry = [self new];
return sharedRegistry;
}
- (NSString *) sourceClassForType: (NSString *) type
{
NSString *sourceClass;
if (type)
{
if ([type isEqualToString: @"ldap"])
sourceClass = @"LDAPSource";
else if ([type isEqualToString: @"sql"])
sourceClass = @"SQLSource";
else
[NSException raise: @"SOGoUserManagerRegistryException"
format: @"No class known for type '%@'", type];
}
else
sourceClass = @"LDAPSource";
return sourceClass;
}
@end
@implementation SOGoUserManager
@@ -64,15 +96,9 @@
sourceID = [udSource objectForKey: @"id"];
if ([sourceID length] > 0)
{
type = [udSource objectForKey: @"type"];
if (!type || [type caseInsensitiveCompare: @"ldap"] == NSOrderedSame)
c = [LDAPSource class];
else
c = [SQLSource class];
ldapSource = [c sourceFromUDSource: udSource
inDomain: domain];
type = [[udSource objectForKey: @"type"] lowercaseString];
c = NSClassFromString ([_registry sourceClassForType: type]);
ldapSource = [c sourceFromUDSource: udSource inDomain: domain];
if (sourceID)
[_sources setObject: ldapSource forKey: sourceID];
else
@@ -155,6 +181,7 @@
{
_sources = nil;
_sourcesMetadata = nil;
_registry = [NSClassFromString ([self registryClass]) sharedRegistry];
[self _prepareSources];
}
@@ -168,6 +195,11 @@
[super dealloc];
}
- (NSString *) registryClass
{
return @"SOGoUserManagerRegistry";
}
- (NSArray *) sourceIDsInDomain: (NSString *) domain
{
NSMutableArray *sourceIDs;
@@ -619,21 +651,18 @@
- (NSString *) getLoginForDN: (NSString *) theDN
{
NSEnumerator *ldapSources;
NSEnumerator *sources;
NSString *login;
LDAPSource *currentSource;
NSObject <SOGoDNSource> *currentSource;
login = nil;
ldapSources = [[_sources allValues] objectEnumerator];
while ((currentSource = [ldapSources nextObject]))
{
if ([theDN hasSuffix: [currentSource baseDN]])
{
login = [currentSource lookupLoginByDN: theDN];
if (login)
break;
}
}
sources = [[_sources allValues] objectEnumerator];
while (!login && (currentSource = [sources nextObject]))
if ([currentSource conformsToProtocol: @protocol (SOGoDNSource)]
&& [theDN hasSuffix: [currentSource baseDN]])
login = [currentSource lookupLoginByDN: theDN];
return login;
}