sogo/SoObjects/SOGo/SOGoDAVAuthenticator.m
Ludovic Marcotte 40c3cb74d0 See ChangeLog
Monotone-Parent: 024380d579a482e49866c36ef54561cf8b39ab02
Monotone-Revision: 2cbc46c16f9b3d45d868b15a968f614dbbaf9749

Monotone-Author: ludovic@Sophos.ca
Monotone-Date: 2010-03-08T15:18:05
Monotone-Branch: ca.inverse.sogo
2010-03-08 15:18:05 +00:00

130 lines
3 KiB
Objective-C

/*
Copyright (C) 2004 SKYRIX Software AG
This file is part of OpenGroupware.org.
OGo is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OGo; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>
#import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
#import <NGExtensions/NSObject+Logs.h>
#import "SOGoConstants.h"
#import "SOGoUserManager.h"
#import "SOGoPermissions.h"
#import "SOGoUser.h"
#import "SOGoDAVAuthenticator.h"
@implementation SOGoDAVAuthenticator
+ (id) sharedSOGoDAVAuthenticator
{
static SOGoDAVAuthenticator *auth = nil;
if (!auth)
auth = [self new];
return auth;
}
- (BOOL) checkLogin: (NSString *) _login
password: (NSString *) _pwd
{
SOGoPasswordPolicyError perr;
int expire, grace;
BOOL b;
perr = PolicyNoError;
b = [[SOGoUserManager sharedUserManager] checkLogin: _login
password: _pwd
perr: &perr
expire: &expire
grace: &grace];
if (b && perr == PolicyNoError)
return YES;
return NO;
}
- (NSString *) passwordInContext: (WOContext *) context
{
NSString *auth, *password;
NSArray *creds;
password = nil;
auth = [[context request] headerForKey: @"authorization"];
if (auth)
{
creds = [self parseCredentials: auth];
if ([creds count] > 1)
password = [creds objectAtIndex: 1];
}
return password;
}
- (NSString *) imapPasswordInContext: (WOContext *) context
forServer: (NSString *) imapServer
forceRenew: (BOOL) renew
{
return [self passwordInContext: context];
}
/* create SOGoUser */
- (SOGoUser *) userInContext: (WOContext *)_ctx
{
static SOGoUser *anonymous = nil;
SOGoUser *user;
NSArray *traversalPath;
NSString *login;
if (!anonymous)
anonymous
= [[SOGoUser alloc] initWithLogin: @"anonymous"
roles: [NSArray arrayWithObject: SoRole_Anonymous]];
login = [self checkCredentialsInContext:_ctx];
if (login)
{
if ([login isEqualToString: @"anonymous"])
{
traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
user = anonymous;
}
else
{
user = [SOGoUser userWithLogin: login
roles: [self rolesForLogin: login]];
[user setCurrentPassword: [self passwordInContext: _ctx]];
}
}
else
user = nil;
return user;
}
@end /* SOGoDAVAuthenticator */