2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2010-03-15 00:07:42 +01:00
|
|
|
|
2014-01-10 03:06:31 +01:00
|
|
|
Copyright (C) 2006-2014 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
2010-03-15 00:07:42 +01:00
|
|
|
This file is part of SOGo.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-03-15 00:07:42 +01:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
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.
|
|
|
|
|
2010-03-15 00:07:42 +01:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
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
|
2010-03-15 00:07:42 +01:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-02-18 22:39:25 +01:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2010-01-28 22:42:03 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-12-13 20:26:47 +01:00
|
|
|
#import <Foundation/NSException.h>
|
2010-02-18 22:39:25 +01:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2010-01-28 22:42:03 +01:00
|
|
|
#import <Foundation/NSURL.h>
|
2010-03-08 16:18:05 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-12-13 20:26:47 +01:00
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-08-06 16:06:27 +02:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
|
|
|
#import <NGObjWeb/WOContext.h>
|
2007-09-04 17:00:44 +02:00
|
|
|
#import <NGObjWeb/WOCookie.h>
|
2007-08-06 16:06:27 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-12-05 22:05:04 +01:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
#import <NGExtensions/NGBase64Coding.h>
|
2010-02-18 22:39:25 +01:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2007-08-06 16:06:27 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2007-09-04 17:00:44 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-04-19 23:30:25 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
|
|
|
|
2010-10-26 20:20:46 +02:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2012-12-21 19:55:03 +01:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2010-01-28 22:42:03 +01:00
|
|
|
#import <SOGo/SOGoCache.h>
|
|
|
|
#import <SOGo/SOGoCASSession.h>
|
2012-12-21 19:55:03 +01:00
|
|
|
#import <SOGo/SOGoConstants.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoDomainDefaults.h>
|
2012-11-02 20:31:49 +01:00
|
|
|
#if defined(SAML2_CONFIG)
|
|
|
|
#import <SOGo/SOGoSAML2Session.h>
|
|
|
|
#endif /* SAML2_ENABLE */
|
2012-12-21 19:55:03 +01:00
|
|
|
#import <SOGo/SOGoSession.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2010-03-08 16:18:05 +01:00
|
|
|
#import <SOGo/SOGoUserManager.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoWebAuthenticator.h>
|
2010-03-08 16:18:05 +01:00
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
#import "SOGoRootPage.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoRootPage
|
|
|
|
|
2011-10-25 22:58:18 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
cookieLogin = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[cookieLogin release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* accessors */
|
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
- (NSString *) connectURL
|
|
|
|
{
|
2009-11-10 22:39:40 +01:00
|
|
|
return [NSString stringWithFormat: @"%@/connect", [self applicationPath]];
|
2007-09-07 00:21:16 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2011-10-25 22:58:18 +02:00
|
|
|
- (NSString *) cookieUsername
|
|
|
|
{
|
|
|
|
NSString *value;
|
|
|
|
|
|
|
|
if (cookieLogin == nil)
|
|
|
|
{
|
|
|
|
value = [[context request] cookieValueForKey: @"SOGoLogin"];
|
|
|
|
cookieLogin = [value isNotNull]? [value stringByDecodingBase64] : @"";
|
|
|
|
[cookieLogin retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cookieLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) rememberLogin
|
|
|
|
{
|
|
|
|
return ([[self cookieUsername] length]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOCookie *) _cookieWithUsername: (NSString *) username
|
|
|
|
{
|
|
|
|
WOCookie *loginCookie;
|
|
|
|
NSString *appName;
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
appName = [[context request] applicationName];
|
2011-12-09 17:33:43 +01:00
|
|
|
date = [NSCalendarDate calendarDate];
|
|
|
|
[date setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
2011-10-25 22:58:18 +02:00
|
|
|
if (username)
|
|
|
|
{
|
2011-12-09 17:33:43 +01:00
|
|
|
// Cookie expires in one month
|
2011-10-25 22:58:18 +02:00
|
|
|
loginCookie = [WOCookie cookieWithName: @"SOGoLogin"
|
2011-12-09 17:33:43 +01:00
|
|
|
value: [username stringByEncodingBase64]
|
|
|
|
path: nil
|
|
|
|
domain: nil
|
|
|
|
expires: [date dateByAddingYears:0 months:1 days:0
|
|
|
|
hours:0 minutes:0 seconds:0]
|
|
|
|
isSecure: NO];
|
2011-10-25 22:58:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loginCookie = [WOCookie cookieWithName: @"SOGoLogin"
|
|
|
|
value: nil];
|
|
|
|
[loginCookie setExpires: [date yesterday]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[loginCookie setPath: [NSString stringWithFormat: @"/%@/", appName]];
|
|
|
|
|
|
|
|
return loginCookie;
|
|
|
|
}
|
|
|
|
|
2012-11-02 20:31:49 +01:00
|
|
|
- (WOCookie *) _authLocationCookie: (BOOL) cookieReset
|
|
|
|
withName: (NSString *) cookieName
|
2010-02-18 22:39:25 +01:00
|
|
|
{
|
|
|
|
WOCookie *locationCookie;
|
|
|
|
NSString *appName;
|
|
|
|
WORequest *rq;
|
|
|
|
NSCalendarDate *date;
|
|
|
|
|
|
|
|
rq = [context request];
|
2012-11-02 20:31:49 +01:00
|
|
|
locationCookie = [WOCookie cookieWithName: cookieName value: [rq uri]];
|
2010-02-18 22:39:25 +01:00
|
|
|
appName = [rq applicationName];
|
|
|
|
[locationCookie setPath: [NSString stringWithFormat: @"/%@/", appName]];
|
|
|
|
if (cookieReset)
|
|
|
|
{
|
|
|
|
date = [NSCalendarDate calendarDate];
|
|
|
|
[date setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
|
|
|
[locationCookie setExpires: [date yesterday]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return locationCookie;
|
|
|
|
}
|
|
|
|
|
2010-12-28 18:42:50 +01:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2010-03-08 21:52:37 +01:00
|
|
|
- (WOResponse *) _responseWithLDAPPolicyError: (int) error
|
|
|
|
{
|
|
|
|
NSDictionary *jsonError;
|
|
|
|
|
|
|
|
jsonError
|
|
|
|
= [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: error]
|
|
|
|
forKey: @"LDAPPasswordPolicyError"];
|
2010-03-09 21:33:00 +01:00
|
|
|
return [self responseWithStatus: 403
|
|
|
|
andJSONRepresentation: jsonError];
|
2010-03-08 21:52:37 +01:00
|
|
|
}
|
|
|
|
|
2013-06-11 15:41:17 +02:00
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2007-09-07 00:21:16 +02:00
|
|
|
- (id <WOActionResults>) connectAction
|
2007-09-04 17:00:44 +02:00
|
|
|
{
|
2007-09-07 00:21:16 +02:00
|
|
|
WOResponse *response;
|
2007-11-21 17:42:58 +01:00
|
|
|
WORequest *request;
|
2007-09-07 00:21:16 +02:00
|
|
|
WOCookie *authCookie;
|
2007-09-04 17:41:59 +02:00
|
|
|
SOGoWebAuthenticator *auth;
|
2010-04-19 23:30:25 +02:00
|
|
|
SOGoAppointmentFolders *calendars;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2010-04-19 23:30:25 +02:00
|
|
|
SOGoUser *loggedInUser;
|
2013-02-06 15:23:47 +01:00
|
|
|
NSString *username, *password, *language, *domain, *remoteHost;
|
2009-11-29 05:19:32 +01:00
|
|
|
NSArray *supportedLanguages;
|
2010-03-08 16:18:05 +01:00
|
|
|
|
|
|
|
SOGoPasswordPolicyError err;
|
|
|
|
int expire, grace;
|
2011-10-25 22:58:18 +02:00
|
|
|
BOOL rememberLogin, b;
|
2010-03-08 16:18:05 +01:00
|
|
|
|
|
|
|
err = PolicyNoError;
|
2010-03-15 00:07:42 +01:00
|
|
|
expire = grace = -1;
|
2010-03-08 16:18:05 +01:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
auth = [[WOApplication application]
|
2010-03-08 16:18:05 +01:00
|
|
|
authenticatorInContext: context];
|
2007-11-21 17:42:58 +01:00
|
|
|
request = [context request];
|
2010-01-28 22:42:03 +01:00
|
|
|
username = [request formValueForKey: @"userName"];
|
2008-08-26 19:42:03 +02:00
|
|
|
password = [request formValueForKey: @"password"];
|
2008-11-05 18:26:02 +01:00
|
|
|
language = [request formValueForKey: @"language"];
|
2011-10-25 22:58:18 +02:00
|
|
|
rememberLogin = [[request formValueForKey: @"rememberLogin"] boolValue];
|
2011-06-24 21:19:50 +02:00
|
|
|
domain = [request formValueForKey: @"domain"];
|
2013-02-06 15:23:47 +01:00
|
|
|
/* this will always be set to something more or less useful by
|
|
|
|
* [WOHttpTransaction applyAdaptorHeadersWithHttpRequest] */
|
|
|
|
remoteHost = [request headerForKey:@"x-webobjects-remote-host"];
|
2010-03-08 16:18:05 +01:00
|
|
|
|
2011-07-16 00:22:11 +02:00
|
|
|
if ((b = [auth checkLogin: username password: password domain: &domain
|
2013-02-02 01:58:25 +01:00
|
|
|
perr: &err expire: &expire grace: &grace useCache: NO])
|
2010-03-15 00:07:42 +01:00
|
|
|
&& (err == PolicyNoError)
|
|
|
|
// no password policy
|
|
|
|
&& ((expire < 0 && grace < 0) // no password policy or everything is alright
|
|
|
|
|| (expire < 0 && grace > 0) // password expired, grace still permits login
|
2010-03-29 02:49:29 +02:00
|
|
|
|| (expire >= 0 && grace == -1))) // password about to expire OR ppolicy activated and passwd never changed
|
2008-08-26 19:42:03 +02:00
|
|
|
{
|
2010-03-15 00:07:42 +01:00
|
|
|
NSDictionary *json;
|
|
|
|
|
2013-02-06 15:23:47 +01:00
|
|
|
[self logWithFormat: @"successful login from '%@' for user '%@' - expire = %d grace = %d", remoteHost, username, expire, grace];
|
2010-03-15 00:07:42 +01:00
|
|
|
|
|
|
|
json = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: expire], @"expire",
|
2011-06-24 21:19:50 +02:00
|
|
|
[NSNumber numberWithInt: grace], @"grace", nil];
|
2010-03-15 00:07:42 +01:00
|
|
|
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andJSONRepresentation: json];
|
2015-08-21 16:30:47 +02:00
|
|
|
|
|
|
|
// We get the proper username for cookie creation. If we are using a multidomain
|
|
|
|
// environment with SOGoEnableDomainBasedUID, we could have to append the domain
|
|
|
|
// to the username. Also when SOGoEnableDomainBasedUID is enabled, we could be in
|
|
|
|
// the DomainLessLogin situation, so we would NOT add the domain. -getUIDForEmail
|
|
|
|
// has all the logic for this, so lets use it.
|
2011-06-24 21:19:50 +02:00
|
|
|
if ([domain isNotNull])
|
2011-07-25 16:28:15 +02:00
|
|
|
{
|
2015-08-21 16:30:47 +02:00
|
|
|
username = [[SOGoUserManager sharedUserManager] getUIDForEmail: username];
|
2011-07-25 16:28:15 +02:00
|
|
|
}
|
2011-06-24 21:19:50 +02:00
|
|
|
|
2012-11-02 20:31:49 +01:00
|
|
|
authCookie = [auth cookieWithUsername: username
|
|
|
|
andPassword: password
|
|
|
|
inContext: context];
|
2008-08-26 19:42:03 +02:00
|
|
|
[response addCookie: authCookie];
|
2008-11-05 18:26:02 +01:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
supportedLanguages = [[SOGoSystemDefaults sharedSystemDefaults]
|
|
|
|
supportedLanguages];
|
2010-04-19 23:30:25 +02:00
|
|
|
loggedInUser = [SOGoUser userWithLogin: username];
|
|
|
|
[context setActiveUser: loggedInUser];
|
2008-12-18 23:11:13 +01:00
|
|
|
if (language && [supportedLanguages containsObject: language])
|
2008-11-05 18:26:02 +01:00
|
|
|
{
|
2010-04-19 23:30:25 +02:00
|
|
|
ud = [loggedInUser userDefaults];
|
2009-11-29 05:19:32 +01:00
|
|
|
[ud setLanguage: language];
|
|
|
|
[ud synchronize];
|
2008-11-05 18:26:02 +01:00
|
|
|
}
|
2010-04-19 23:30:25 +02:00
|
|
|
|
|
|
|
calendars = [loggedInUser calendarsFolderInContext: context];
|
|
|
|
if ([calendars respondsToSelector: @selector (reloadWebCalendars:)])
|
|
|
|
[calendars reloadWebCalendars: NO];
|
2008-08-26 19:42:03 +02:00
|
|
|
}
|
|
|
|
else
|
2008-09-11 23:55:21 +02:00
|
|
|
{
|
2013-02-06 15:23:47 +01:00
|
|
|
[self logWithFormat:@"Login from '%@' for user '%@' might not have worked - password policy: %d grace: %d expire: %d bound: %d",
|
|
|
|
remoteHost, username, err, grace, expire, b];
|
2010-03-08 21:52:37 +01:00
|
|
|
|
|
|
|
response = [self _responseWithLDAPPolicyError: err];
|
2008-09-11 23:55:21 +02:00
|
|
|
}
|
2007-09-07 00:21:16 +02:00
|
|
|
|
2011-10-25 22:58:18 +02:00
|
|
|
if (rememberLogin)
|
|
|
|
[response addCookie: [self _cookieWithUsername: username]];
|
|
|
|
else
|
|
|
|
[response addCookie: [self _cookieWithUsername: nil]];
|
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (NSDictionary *) _casRedirectKeys
|
2007-09-12 15:01:17 +02:00
|
|
|
{
|
2010-01-28 22:42:03 +01:00
|
|
|
NSDictionary *redirectKeys;
|
|
|
|
NSURL *soURL;
|
2013-06-20 20:32:14 +02:00
|
|
|
NSString *serviceURL;
|
2010-01-28 22:42:03 +01:00
|
|
|
|
|
|
|
soURL = [[WOApplication application] soURL];
|
2013-06-20 20:32:14 +02:00
|
|
|
// appending 'index' to /SOGo/so/. Matches serviceURL sent by _pgtUrlFromURL
|
|
|
|
serviceURL = [NSString stringWithFormat: @"%@index", [soURL absoluteString]];
|
2010-01-28 22:42:03 +01:00
|
|
|
|
2013-06-20 20:32:14 +02:00
|
|
|
redirectKeys = [NSDictionary dictionaryWithObject: serviceURL
|
2010-01-28 22:42:03 +01:00
|
|
|
forKey: @"service"];
|
|
|
|
|
|
|
|
return redirectKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) casProxyAction
|
|
|
|
{
|
|
|
|
SOGoCache *cache;
|
|
|
|
WORequest *request;
|
|
|
|
NSString *pgtId, *pgtIou;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
pgtId = [request formValueForKey: @"pgtId"];
|
|
|
|
pgtIou = [request formValueForKey: @"pgtIou"];
|
|
|
|
if ([pgtId length] && [pgtIou length])
|
|
|
|
{
|
|
|
|
cache = [SOGoCache sharedCache];
|
|
|
|
[cache setCASPGTId: pgtId forPGTIOU: pgtIou];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self responseWithStatus: 200];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) _casDefaultAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2013-06-20 20:32:14 +02:00
|
|
|
NSString *login, *logoutRequest, *newLocation, *oldLocation, *ticket;
|
2010-01-28 22:42:03 +01:00
|
|
|
SOGoCASSession *casSession;
|
|
|
|
SOGoWebAuthenticator *auth;
|
2010-02-18 22:39:25 +01:00
|
|
|
WOCookie *casCookie, *casLocationCookie;
|
|
|
|
WORequest *rq;
|
2010-01-28 22:42:03 +01:00
|
|
|
|
|
|
|
casCookie = nil;
|
2010-02-18 22:39:25 +01:00
|
|
|
casLocationCookie = nil;
|
|
|
|
|
|
|
|
newLocation = nil;
|
2007-09-12 15:01:17 +02:00
|
|
|
|
|
|
|
login = [[context activeUser] login];
|
2010-01-28 22:42:03 +01:00
|
|
|
if ([login isEqualToString: @"anonymous"])
|
|
|
|
login = nil;
|
|
|
|
if (!login)
|
|
|
|
{
|
2010-02-18 22:39:25 +01:00
|
|
|
rq = [context request];
|
|
|
|
ticket = [rq formValueForKey: @"ticket"];
|
2010-01-28 22:42:03 +01:00
|
|
|
if ([ticket length])
|
|
|
|
{
|
2010-06-10 23:29:55 +02:00
|
|
|
casSession = [SOGoCASSession CASSessionWithTicket: ticket
|
|
|
|
fromProxy: NO];
|
2010-01-28 22:42:03 +01:00
|
|
|
login = [casSession login];
|
|
|
|
if ([login length])
|
|
|
|
{
|
|
|
|
auth = [[WOApplication application]
|
|
|
|
authenticatorInContext: context];
|
2012-11-02 20:31:49 +01:00
|
|
|
casCookie = [auth cookieWithUsername: login
|
|
|
|
andPassword: [casSession identifier]
|
|
|
|
inContext: context];
|
2010-01-28 22:42:03 +01:00
|
|
|
[casSession updateCache];
|
2010-02-18 22:39:25 +01:00
|
|
|
newLocation = [rq cookieValueForKey: @"cas-location"];
|
|
|
|
/* login callback, we expire the "cas-location" cookie, created
|
|
|
|
below */
|
2012-11-02 20:31:49 +01:00
|
|
|
casLocationCookie = [self _authLocationCookie: YES
|
|
|
|
withName: @"cas-location"];
|
2010-01-28 22:42:03 +01:00
|
|
|
}
|
|
|
|
}
|
2013-06-20 20:32:14 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* anonymous and no ticket, possibly a logout request from CAS
|
|
|
|
* See: https://wiki.jasig.org/display/CASUM/Single+Sign+Out
|
|
|
|
*/
|
|
|
|
logoutRequest = [rq formValueForKey: @"logoutRequest"];
|
|
|
|
if ([logoutRequest length])
|
|
|
|
{
|
|
|
|
[SOGoCASSession handleLogoutRequest: logoutRequest];
|
|
|
|
return [self responseWithStatus: 200];
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 22:42:03 +01:00
|
|
|
}
|
2010-02-18 22:39:25 +01:00
|
|
|
else
|
|
|
|
ticket = nil;
|
2010-01-28 22:42:03 +01:00
|
|
|
|
|
|
|
if (login)
|
|
|
|
{
|
2014-12-19 01:34:05 +01:00
|
|
|
/* We redirect the user to their "homepage" when newLocation could not be
|
2010-02-18 22:39:25 +01:00
|
|
|
deduced from the "cas-location" cookie and the current action is not a
|
|
|
|
login callback (ticket != nil). */
|
|
|
|
if (!newLocation || !ticket)
|
|
|
|
{
|
|
|
|
oldLocation = [[self clientObject] baseURLInContext: context];
|
|
|
|
newLocation = [NSString stringWithFormat: @"%@%@",
|
|
|
|
oldLocation, [login stringByEscapingURL]];
|
|
|
|
}
|
2010-01-28 22:42:03 +01:00
|
|
|
}
|
2007-09-12 15:01:17 +02:00
|
|
|
else
|
2010-02-18 22:39:25 +01:00
|
|
|
{
|
|
|
|
newLocation
|
|
|
|
= [SOGoCASSession CASURLWithAction: @"login"
|
|
|
|
andParameters: [self _casRedirectKeys]];
|
2012-11-02 20:31:49 +01:00
|
|
|
casLocationCookie = [self _authLocationCookie: NO
|
|
|
|
withName: @"cas-location"];
|
2010-02-18 22:39:25 +01:00
|
|
|
}
|
2010-01-28 22:42:03 +01:00
|
|
|
response = [self redirectToLocation: newLocation];
|
|
|
|
if (casCookie)
|
|
|
|
[response addCookie: casCookie];
|
2010-02-18 22:39:25 +01:00
|
|
|
if (casLocationCookie)
|
|
|
|
[response addCookie: casLocationCookie];
|
2010-01-28 22:42:03 +01:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2012-11-02 20:31:49 +01:00
|
|
|
#if defined(SAML2_CONFIG)
|
|
|
|
- (id <WOActionResults>) _saml2DefaultAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *login, *newLocation, *oldLocation;
|
|
|
|
WOCookie *saml2LocationCookie;
|
|
|
|
WORequest *rq;
|
|
|
|
|
|
|
|
saml2LocationCookie = nil;
|
|
|
|
|
|
|
|
newLocation = nil;
|
|
|
|
|
|
|
|
login = [[context activeUser] login];
|
|
|
|
if ([login isEqualToString: @"anonymous"])
|
|
|
|
login = nil;
|
|
|
|
|
|
|
|
if (login)
|
|
|
|
{
|
|
|
|
rq = [context request];
|
|
|
|
newLocation = [rq cookieValueForKey: @"saml2-location"];
|
|
|
|
if (newLocation)
|
|
|
|
saml2LocationCookie = [self _authLocationCookie: YES
|
|
|
|
withName: @"saml2-location"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oldLocation = [[self clientObject] baseURLInContext: context];
|
|
|
|
newLocation = [NSString stringWithFormat: @"%@%@",
|
|
|
|
oldLocation, [login stringByEscapingURL]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newLocation = [SOGoSAML2Session authenticationURLInContext: context];
|
|
|
|
saml2LocationCookie = [self _authLocationCookie: NO
|
|
|
|
withName: @"saml2-location"];
|
|
|
|
}
|
|
|
|
|
|
|
|
response = [self redirectToLocation: newLocation];
|
|
|
|
if (saml2LocationCookie)
|
|
|
|
[response addCookie: saml2LocationCookie];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
#endif /* SAML2_CONFIG */
|
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (id <WOActionResults>) _standardDefaultAction
|
|
|
|
{
|
|
|
|
NSObject <WOActionResults> *response;
|
|
|
|
NSString *login, *oldLocation;
|
|
|
|
|
|
|
|
login = [[context activeUser] login];
|
|
|
|
if ([login isEqualToString: @"anonymous"])
|
|
|
|
login = nil;
|
|
|
|
|
|
|
|
if (login)
|
2007-09-12 15:01:17 +02:00
|
|
|
{
|
|
|
|
oldLocation = [[self clientObject] baseURLInContext: context];
|
|
|
|
response
|
2010-01-28 22:42:03 +01:00
|
|
|
= [self redirectToLocation: [NSString stringWithFormat: @"%@%@",
|
2009-09-11 16:38:43 +02:00
|
|
|
oldLocation,
|
|
|
|
[login stringByEscapingURL]]];
|
2007-09-12 15:01:17 +02:00
|
|
|
}
|
2010-01-28 22:42:03 +01:00
|
|
|
else
|
2010-02-03 15:56:38 +01:00
|
|
|
{
|
|
|
|
oldLocation = [[context request] uri];
|
2010-02-03 17:09:18 +01:00
|
|
|
if ([context clientObject]
|
|
|
|
&& ![oldLocation hasSuffix: @"/"]
|
2010-02-03 15:56:38 +01:00
|
|
|
&& ![oldLocation hasSuffix: @"/view"])
|
|
|
|
response = [self redirectToLocation:
|
|
|
|
[NSString stringWithFormat: @"%@/", oldLocation]];
|
|
|
|
else
|
|
|
|
response = self;
|
|
|
|
}
|
2007-09-12 15:01:17 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (id <WOActionResults>) defaultAction
|
|
|
|
{
|
2012-11-02 20:31:49 +01:00
|
|
|
NSString *authenticationType;
|
|
|
|
id <WOActionResults> result;
|
|
|
|
|
|
|
|
authenticationType = [[SOGoSystemDefaults sharedSystemDefaults]
|
|
|
|
authenticationType];
|
|
|
|
if ([authenticationType isEqualToString: @"cas"])
|
|
|
|
result = [self _casDefaultAction];
|
|
|
|
#if defined(SAML2_CONFIG)
|
|
|
|
else if ([authenticationType isEqualToString: @"saml2"])
|
|
|
|
result = [self _saml2DefaultAction];
|
|
|
|
#endif /* SAML2_CONFIG */
|
|
|
|
else
|
|
|
|
result = [self _standardDefaultAction];
|
2010-01-28 22:42:03 +01:00
|
|
|
|
2012-11-02 20:31:49 +01:00
|
|
|
return result;
|
2010-01-28 22:42:03 +01:00
|
|
|
}
|
|
|
|
|
2007-09-05 19:56:39 +02:00
|
|
|
- (BOOL) isPublicInContext: (WOContext *) localContext
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:56:18 +02:00
|
|
|
- (NSString *) loginSuffix
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults] loginSuffix];
|
2008-05-22 17:56:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasLoginSuffix
|
|
|
|
{
|
|
|
|
return ([[self loginSuffix] length]);
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
- (NSArray *) loginDomains
|
|
|
|
{
|
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults] loginDomains];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasLoginDomains
|
|
|
|
{
|
|
|
|
return ([[self loginDomains] count] > 0);
|
|
|
|
}
|
|
|
|
|
2008-11-05 18:26:02 +01:00
|
|
|
- (void) setItem: (id) _item
|
|
|
|
{
|
|
|
|
ASSIGN (item, _item);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) item
|
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) languages
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [[SOGoSystemDefaults sharedSystemDefaults] supportedLanguages];
|
2008-11-05 18:26:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) languageText
|
|
|
|
{
|
|
|
|
NSString *text;
|
|
|
|
|
|
|
|
text = [self labelForKey: item];
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2009-03-19 03:42:35 +01:00
|
|
|
- (NSString *) version
|
|
|
|
{
|
|
|
|
NSString *aString;
|
|
|
|
|
2014-01-10 03:06:31 +01:00
|
|
|
aString = [NSString stringWithString: SOGoVersion];
|
2009-03-19 03:42:35 +01:00
|
|
|
|
|
|
|
return aString;
|
|
|
|
}
|
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
- (WOResponse *) changePasswordAction
|
|
|
|
{
|
2011-06-24 21:19:50 +02:00
|
|
|
NSString *username, *domain, *password, *newPassword, *value;
|
2011-07-25 16:28:15 +02:00
|
|
|
NSDictionary *message;
|
|
|
|
WOCookie *authCookie;
|
|
|
|
NSArray *creds;
|
2010-03-08 16:18:05 +01:00
|
|
|
SOGoUserManager *um;
|
|
|
|
SOGoPasswordPolicyError error;
|
2011-07-25 16:28:15 +02:00
|
|
|
SOGoSystemDefaults *sd;
|
|
|
|
SOGoWebAuthenticator *auth;
|
2010-03-08 16:18:05 +01:00
|
|
|
WOResponse *response;
|
|
|
|
WORequest *request;
|
|
|
|
|
|
|
|
request = [context request];
|
2010-10-26 20:20:46 +02:00
|
|
|
message = [[request contentAsString] objectFromJSONString];
|
2010-12-28 18:42:50 +01:00
|
|
|
|
|
|
|
auth = [[WOApplication application]
|
|
|
|
authenticatorInContext: context];
|
|
|
|
value = [[context request]
|
|
|
|
cookieValueForKey: [auth cookieNameInContext: context]];
|
|
|
|
creds = [auth parseCredentials: value];
|
|
|
|
|
|
|
|
[SOGoSession decodeValue: [SOGoSession valueForSessionKey: [creds objectAtIndex: 1]]
|
2011-06-24 21:19:50 +02:00
|
|
|
usingKey: [creds objectAtIndex: 0]
|
|
|
|
login: &username
|
|
|
|
domain: &domain
|
|
|
|
password: &password];
|
2010-12-28 18:42:50 +01:00
|
|
|
|
2010-03-08 16:18:05 +01:00
|
|
|
newPassword = [message objectForKey: @"newPassword"];
|
|
|
|
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
|
|
|
// This will also update the cached password in memcached.
|
|
|
|
if ([um changePasswordForLogin: username
|
2011-06-24 21:19:50 +02:00
|
|
|
inDomain: domain
|
|
|
|
oldPassword: password
|
|
|
|
newPassword: newPassword
|
|
|
|
perr: &error])
|
2010-03-08 16:18:05 +01:00
|
|
|
{
|
2010-12-28 18:42:50 +01:00
|
|
|
// We delete the previous session
|
|
|
|
[SOGoSession deleteValueForSessionKey: [creds objectAtIndex: 1]];
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
if ([domain isNotNull])
|
2011-07-25 16:28:15 +02:00
|
|
|
{
|
|
|
|
sd = [SOGoSystemDefaults sharedSystemDefaults];
|
2015-05-19 19:48:59 +02:00
|
|
|
if ([sd enableDomainBasedUID] &&
|
|
|
|
[username rangeOfString: @"@"].location == NSNotFound)
|
2011-07-25 16:28:15 +02:00
|
|
|
username = [NSString stringWithFormat: @"%@@%@", username, domain];
|
|
|
|
}
|
|
|
|
|
2010-03-08 21:52:37 +01:00
|
|
|
response = [self responseWith204];
|
2012-11-02 20:31:49 +01:00
|
|
|
authCookie = [auth cookieWithUsername: username
|
|
|
|
andPassword: newPassword
|
|
|
|
inContext: context];
|
2010-03-08 21:52:37 +01:00
|
|
|
[response addCookie: authCookie];
|
2010-03-08 16:18:05 +01:00
|
|
|
}
|
2010-03-08 21:52:37 +01:00
|
|
|
else
|
|
|
|
response = [self _responseWithLDAPPolicyError: error];
|
2010-03-08 16:18:05 +01:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoRootPage */
|