2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
2008-07-29 18:36:16 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-06-18 17:37:37 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2008-07-24 20:00:21 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2006-07-07 18:04:46 +02:00
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
#import "SOGoConstants.h"
|
2009-09-25 16:42:33 +02:00
|
|
|
#import "SOGoUserManager.h"
|
2007-06-18 17:37:37 +02:00
|
|
|
#import "SOGoPermissions.h"
|
|
|
|
#import "SOGoUser.h"
|
2007-05-09 21:21:01 +02:00
|
|
|
|
2007-09-04 17:40:26 +02:00
|
|
|
#import "SOGoDAVAuthenticator.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-04 17:40:26 +02:00
|
|
|
@implementation SOGoDAVAuthenticator
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-04 17:40:26 +02:00
|
|
|
+ (id) sharedSOGoDAVAuthenticator
|
2006-07-07 18:04:46 +02:00
|
|
|
{
|
2007-09-04 17:40:26 +02:00
|
|
|
static SOGoDAVAuthenticator *auth = nil;
|
2007-06-14 23:23:14 +02:00
|
|
|
|
|
|
|
if (!auth)
|
|
|
|
auth = [self new];
|
2007-07-04 22:13:08 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return auth;
|
|
|
|
}
|
|
|
|
|
2006-07-07 18:04:46 +02:00
|
|
|
- (BOOL) checkLogin: (NSString *) _login
|
|
|
|
password: (NSString *) _pwd
|
|
|
|
{
|
2010-03-08 16:18:05 +01:00
|
|
|
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;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-07-10 16:16:52 +02:00
|
|
|
- (NSString *) passwordInContext: (WOContext *) context
|
2007-06-18 17:37:37 +02:00
|
|
|
{
|
|
|
|
NSString *auth, *password;
|
|
|
|
NSArray *creds;
|
|
|
|
|
|
|
|
password = nil;
|
2007-06-22 21:54:05 +02:00
|
|
|
auth = [[context request] headerForKey: @"authorization"];
|
2007-06-18 17:37:37 +02:00
|
|
|
if (auth)
|
|
|
|
{
|
|
|
|
creds = [self parseCredentials: auth];
|
|
|
|
if ([creds count] > 1)
|
|
|
|
password = [creds objectAtIndex: 1];
|
|
|
|
}
|
2007-07-10 16:16:52 +02:00
|
|
|
|
2007-06-18 17:37:37 +02:00
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (NSString *) imapPasswordInContext: (WOContext *) context
|
|
|
|
forServer: (NSString *) imapServer
|
|
|
|
forceRenew: (BOOL) renew
|
|
|
|
{
|
|
|
|
return [self passwordInContext: context];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* create SOGoUser */
|
|
|
|
|
2007-03-07 23:31:02 +01:00
|
|
|
- (SOGoUser *) userInContext: (WOContext *)_ctx
|
2006-07-07 18:04:46 +02:00
|
|
|
{
|
2007-06-26 23:48:52 +02:00
|
|
|
static SOGoUser *anonymous = nil;
|
2007-03-18 16:22:05 +01:00
|
|
|
SOGoUser *user;
|
2007-01-26 23:25:23 +01:00
|
|
|
NSArray *traversalPath;
|
|
|
|
NSString *login;
|
|
|
|
|
2006-07-07 18:04:46 +02:00
|
|
|
if (!anonymous)
|
|
|
|
anonymous
|
2007-05-09 21:21:01 +02:00
|
|
|
= [[SOGoUser alloc] initWithLogin: @"anonymous"
|
2006-07-07 18:04:46 +02:00
|
|
|
roles: [NSArray arrayWithObject: SoRole_Anonymous]];
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-01-26 23:25:23 +01:00
|
|
|
login = [self checkCredentialsInContext:_ctx];
|
|
|
|
if (login)
|
|
|
|
{
|
|
|
|
if ([login isEqualToString: @"anonymous"])
|
|
|
|
{
|
|
|
|
traversalPath = [_ctx objectForKey: @"SoRequestTraversalPath"];
|
2007-06-26 23:48:52 +02:00
|
|
|
user = anonymous;
|
2007-01-26 23:25:23 +01:00
|
|
|
}
|
|
|
|
else
|
2007-06-18 17:37:37 +02:00
|
|
|
{
|
|
|
|
user = [SOGoUser userWithLogin: login
|
|
|
|
roles: [self rolesForLogin: login]];
|
2007-07-10 16:16:52 +02:00
|
|
|
[user setCurrentPassword: [self passwordInContext: _ctx]];
|
2007-06-18 17:37:37 +02:00
|
|
|
}
|
2007-01-26 23:25:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
user = nil;
|
2006-07-07 18:04:46 +02:00
|
|
|
|
2007-01-26 23:25:23 +01:00
|
|
|
return user;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-09-04 17:40:26 +02:00
|
|
|
@end /* SOGoDAVAuthenticator */
|