* AuthBasic now use SOAP request to create the new session

* perltidy
This commit is contained in:
Xavier Guimard 2009-02-10 11:10:12 +00:00
parent 6b821a21dd
commit ab1b201e71
3 changed files with 71 additions and 41 deletions

View File

@ -10,6 +10,7 @@ use strict;
use MIME::Base64;
use Time::Local;
use CGI;
#inherits Lemonldap::NG::Common::CGI::SOAPServer
our $VERSION = '0.31';
@ -26,10 +27,16 @@ sub soapTest {
# If non form encoded datas are posted, we call SOAP Services
if ( $ENV{HTTP_SOAPACTION} ) {
require Lemonldap::NG::Common::CGI::SOAPServer; #link protected dispatcher
require Lemonldap::NG::Common::CGI::SOAPService; #link protected soapService
my @func = ( ref($soapFunctions) ? @$soapFunctions : split /\s+/, $soapFunctions );
my $dispatcher = Lemonldap::NG::Common::CGI::SOAPService->new($obj||$self,@func);
require
Lemonldap::NG::Common::CGI::SOAPServer; #link protected dispatcher
require
Lemonldap::NG::Common::CGI::SOAPService; #link protected soapService
my @func = (
ref($soapFunctions) ? @$soapFunctions : split /\s+/,
$soapFunctions
);
my $dispatcher =
Lemonldap::NG::Common::CGI::SOAPService->new( $obj || $self, @func );
Lemonldap::NG::Common::CGI::SOAPServer->dispatch_to($dispatcher)
->handle($self);
exit;
@ -99,9 +106,7 @@ sub abort {
my $cgi = CGI->new;
my ( $t1, $t2 ) = @_;
$t2 ||= "See Apache's logs";
print $cgi->header(
-type => 'text/html; charset=utf8',
);
print $cgi->header( -type => 'text/html; charset=utf8', );
print $cgi->start_html(
-title => $t1,
-encoding => 'utf8',

View File

@ -8,11 +8,13 @@ package Lemonldap::NG::Handler::AuthBasic;
use strict;
use Lemonldap::NG::Handler::SharedConf qw(:all);
use Lemonldap::NG::Portal::SharedConf; #inherits
use Digest::MD5 qw(md5_base64);
use MIME::Base64;
use SOAP::Lite; # link protected portalRequest
use base qw(Lemonldap::NG::Handler::SharedConf);
use utf8;
no utf8;
our $VERSION = '0.1';
@ -38,9 +40,9 @@ sub run ($$) {
my $class;
( $class, $apacheRequest ) = @_;
if ( time() - $lastReload > $reloadTime ) {
unless ( $class->localConfUpdate($apacheRequest) == OK ) {
unless ( my $tmp = $class->testConf(1) == OK ) {
$class->lmLog( "$class: No configuration found", 'error' );
return SERVER_ERROR;
return $tmp;
}
}
return DECLINED unless ( $apacheRequest->is_initial_req );
@ -69,34 +71,57 @@ sub run ($$) {
# 2.2 search in the local cache if exists
unless ( $refLocalStorage and $datas = $refLocalStorage->get($id) ) {
# 2.3 Authentication by Lemonldap::NG::Portal
my $portal = Lemonldap::NG::Portal::SharedConf->new(
{
configStorage => $Lemonldap::NG::Conf::configStorage,
controlUrlOrigin => sub { PE_OK },
controlExistingSession => sub { PE_OK },
extractFormInfo => sub {
return PE_FORMEMPTY
unless ( length( $self->{'user'} )
&& length( $self->{'password'} ) );
PE_OK;
},
store => sub { PE_OK },
buildCookie => sub { PE_OK },
autoRedirect => sub { PE_OK },
}
# 2.3 Authentication by Lemonldap::NG::Portal using SOAP request
my $soap =
SOAP::Lite->proxy($portal)
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
$user = decode_base64($user);
( $user, $pass ) = split /:/, $user;
my $r = $soap->getCookies( $user, $pass );
# Catch SOAP errors
if ( $r->fault ) {
$class->lmLog(
"SOAP request to the portal failed: "
. $r->fault->{faultstring},
'error'
);
return SERVER_ERROR;
}
else {
my $res = $r->result();
# If authentication failed, display error
if ( $res->{error} ) {
$class->lmLog(
"Authentication failed for $user "
. $soap->error( 'fr', $res->{error} )->result(),
'notice'
);
( $portal->{user}, $portal->{password} ) = split /:/,
decode_base64($user);
unless ( $portal->process() ) {
$class->lmLog( "Fail to authenticate user $user", 'notice' );
lmSetErrHeaderOut( $apacheRequest,
'WWW-Authenticate' => 'Basic realm="Lemonldap::NG"' );
return AUTH_REQUIRED;
}
$datas->{$_} = $portal->{sessionInfo}->{$_}
foreach ( keys %{ $portal->{sessionInfo} } );
$datas->{_session_id} = $id;
$id = $res->{cookies}->{$cookieName};
}
# Now, normal work to find session
my %h;
eval { tie %h, $globalStorage, $id, $globalStorageOptions; };
if ($@) {
# The cookie isn't yet available
$class->lmLog( "The cookie $id isn't yet available: $@",
'info' );
$class->updateStatus( $apacheRequest->connection->remote_ip,
$apacheRequest->uri, 'EXPIRED' );
return $class->goToPortal($uri);
}
$datas->{$_} = $h{$_} foreach ( keys %h );
# Store now the user in the local storage
if ($refLocalStorage) {
$refLocalStorage->set( $id, $datas, "10 minutes" );
}
untie %h;
# Store now the user in the local storage
if ($refLocalStorage) {

View File

@ -75,7 +75,7 @@ if ( $portal->process() ) {
);
# Menu creation
use Lemonldap::NG::Portal::Menu;
require Lemonldap::NG::Portal::Menu;
my $menu = Lemonldap::NG::Portal::Menu->new(
{
portalObject => $portal,