2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 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-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-09-07 00:21:16 +02:00
|
|
|
#import <NGExtensions/NGBase64Coding.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
|
|
|
|
2007-09-04 17:41:59 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoWebAuthenticator.h>
|
2007-09-04 17:00:44 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
#import "SOGoRootPage.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoRootPage
|
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[userName release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2007-09-04 17:00:44 +02:00
|
|
|
- (void) setUserName: (NSString *) _value
|
|
|
|
{
|
|
|
|
ASSIGNCOPY (userName, _value);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-09-04 17:00:44 +02:00
|
|
|
|
|
|
|
- (NSString *) userName
|
|
|
|
{
|
|
|
|
return userName;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
- (NSString *) connectURL
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@connect", [self applicationPath]];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
/* actions */
|
|
|
|
- (id <WOActionResults>) connectAction
|
2007-09-04 17:00:44 +02:00
|
|
|
{
|
2007-09-07 00:21:16 +02:00
|
|
|
WOResponse *response;
|
|
|
|
WOCookie *authCookie;
|
2007-09-04 17:41:59 +02:00
|
|
|
SOGoWebAuthenticator *auth;
|
2007-09-07 00:21:16 +02:00
|
|
|
NSString *cookieValue, *cookieString;
|
|
|
|
|
|
|
|
auth = [[WOApplication application]
|
|
|
|
authenticatorInContext: context];
|
|
|
|
response = [context response];
|
|
|
|
cookieString = [NSString stringWithFormat: @"%@:%@",
|
|
|
|
[self queryParameterForKey: @"userName"],
|
|
|
|
[self queryParameterForKey: @"password"]];
|
|
|
|
cookieValue = [NSString stringWithFormat: @"basic%@",
|
|
|
|
[cookieString stringByEncodingBase64]];
|
|
|
|
authCookie = [WOCookie cookieWithName: [auth cookieNameInContext: context]
|
|
|
|
value: cookieValue];
|
|
|
|
[authCookie setPath: @"/"];
|
|
|
|
[response setStatus: 204];
|
|
|
|
[response addCookie: authCookie];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - (id <WOActionResults>) defaultAction
|
|
|
|
// {
|
|
|
|
// WOResponse *r;
|
|
|
|
// NSString *login, *rhk;
|
|
|
|
// SOGoWebAuthenticator *auth;
|
|
|
|
// SOGoUser *user;
|
|
|
|
// SOGoUserFolder *home;
|
|
|
|
// WOApplication *base;
|
|
|
|
|
|
|
|
// /*
|
|
|
|
// Note: ctx.activeUser is NOT set here. Don't know why, so we retrieve
|
|
|
|
// the user from the authenticator.
|
|
|
|
// */
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// auth = [[self clientObject] authenticatorInContext: context];
|
|
|
|
// user = [auth userInContext: context];
|
|
|
|
// login = [user login];
|
2007-09-04 17:41:59 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// if ([login isEqualToString:@"anonymous"]) {
|
|
|
|
// /* use root page for unauthenticated users */
|
|
|
|
// return self;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// /* check base */
|
2007-09-04 17:00:44 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// base = [self application];
|
|
|
|
// rhk = [[context request] requestHandlerKey];
|
|
|
|
// if (([rhk length] == 0) || ([base requestHandlerForKey:rhk] == nil)) {
|
|
|
|
// base = [base lookupName: @"so" inContext: context acquire: NO];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// if (![base isNotNull] || [base isKindOfClass:[NSException class]]) {
|
|
|
|
// /* use root page if home could not be found */
|
|
|
|
// [self errorWithFormat:@"Did not find 'so' request handler!"];
|
|
|
|
// return self;
|
|
|
|
// }
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// /* lookup home-page */
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// home = [base lookupName: login inContext: context acquire: NO];
|
|
|
|
// if (![home isNotNull] || [home isKindOfClass:[NSException class]]) {
|
|
|
|
// /* use root page if home could not be found */
|
|
|
|
// return self;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// /* redirect to home-page */
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// r = [context response];
|
|
|
|
// [r setStatus: 302 /* moved */];
|
|
|
|
// [r setHeader: [home baseURLInContext: context]
|
|
|
|
// forKey: @"location"];
|
2007-09-04 17:00:44 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// return r;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* response generation */
|
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// - (void) appendToResponse: (WOResponse *) response
|
|
|
|
// inContext: (WOContext *) ctx
|
|
|
|
// {
|
|
|
|
// NSString *rhk;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// // TODO: we might also want to look into the HTTP basic-auth to redirect to
|
|
|
|
// // the login URL!
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// rhk = [[ctx request] requestHandlerKey];
|
|
|
|
// if ([rhk length] == 0
|
|
|
|
// || [[self application] requestHandlerForKey: rhk] == nil)
|
|
|
|
// {
|
|
|
|
// /* a small hack to redirect to a valid URL */
|
|
|
|
// NSString *url;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-07 00:21:16 +02:00
|
|
|
// url = [ctx urlWithRequestHandlerKey: @"so" path: @"/" queryString: nil];
|
|
|
|
// [response setStatus: 302 /* moved */];
|
|
|
|
// [response setHeader: url forKey: @"location"];
|
|
|
|
// [self logWithFormat: @"URL: %@", url];
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// [response setHeader: @"text/html" forKey: @"content-type"];
|
|
|
|
// [super appendToResponse: response inContext: ctx];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-09-05 19:56:39 +02:00
|
|
|
- (BOOL) isPublicInContext: (WOContext *) localContext
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoRootPage */
|