LEMONLDAP::NG : error display in SOAP

This commit is contained in:
Xavier Guimard 2008-12-07 20:07:52 +00:00
parent b9ba2337e4
commit 16a29be9fa
3 changed files with 142 additions and 36 deletions

View File

@ -19,12 +19,14 @@ system.
use Lemonldap::NG::Portal::SharedConf; use Lemonldap::NG::Portal::SharedConf;
my $portal = new Lemonldap::NG::Portal::SharedConf ( my $portal = new Lemonldap::NG::Portal::SharedConf (
configStorage => { configStorage => {
type => 'DBI', type => 'DBI',
dbiChain => "dbi:mysql:database=lmSessions;host=1.2.3.4", dbiChain => "dbi:mysql:database=lmSessions;host=1.2.3.4",
dbiUser => "lemon", dbiUser => "lemon",
dbiPassword => "pass", dbiPassword => "pass",
}, },
# Activate SOAP service
Soap => 1
); );
@ -59,6 +61,36 @@ system.
print '</form>'; print '</form>';
} }
SOAP mode authentication (client) :
#!/usr/bin/perl -l
use SOAP::Lite;
use Data::Dumper;
my $soap =
SOAP::Lite->proxy('http://auth.example.com/')
->uri('urn:/Lemonldap::NG::Portal::SharedConf');
my $r = $soap->getCookies( 'user', 'password' );
# Catch SOAP errors
if ( $r->fault ) {
print STDERR "SOAP Error: " . $r->fault->{faultstring};
}
else {
my $res = $r->result();
# If authentication failed, display error
if ( $res->{error} ) {
print STDERR "Error: " . $soap->error( 'fr', $res->{error} )->result();
}
# print session-ID
else {
print "Cookie: lemonldap=" . $res->{cookies}->{lemonldap};
}
}
=head1 DESCRIPTION =head1 DESCRIPTION
Lemonldap::NG is a modular Web-SSO based on Apache::Session modules. It Lemonldap::NG is a modular Web-SSO based on Apache::Session modules. It

View File

@ -112,6 +112,8 @@ compatible portals using a central configuration database.
dbiPassword => "password", dbiPassword => "password",
dbiTable => "lmConfig", dbiTable => "lmConfig",
}, },
# Activate SOAP service
Soap => 1
} ); } );
if($portal->process()) { if($portal->process()) {
@ -139,6 +141,36 @@ compatible portals using a central configuration database.
print '</form>'; print '</form>';
} }
SOAP mode authentication (client) :
#!/usr/bin/perl -l
use SOAP::Lite;
use Data::Dumper;
my $soap =
SOAP::Lite->proxy('http://auth.example.com/')
->uri('urn:/Lemonldap::NG::Portal::SharedConf');
my $r = $soap->getCookies( 'user', 'password' );
# Catch SOAP errors
if ( $r->fault ) {
print STDERR "SOAP Error: " . $r->fault->{faultstring};
}
else {
my $res = $r->result();
# If authentication failed, display error
if ( $res->{error} ) {
print STDERR "Error: " . $soap->error( 'fr', $res->{error} )->result();
}
# print session-ID
else {
print "Cookie: lemonldap=" . $res->{cookies}->{lemonldap};
}
}
=head1 DESCRIPTION =head1 DESCRIPTION
Lemonldap::NG::Portal::SharedConf is the base module for building Lemonldap::NG Lemonldap::NG::Portal::SharedConf is the base module for building Lemonldap::NG

View File

@ -132,7 +132,7 @@ sub new {
} }
if ( $self->{Soap} ) { if ( $self->{Soap} ) {
require SOAP::Lite; require SOAP::Lite;
$self->soapTest("${class}::getCookies"); $self->soapTest("${class}::getCookies ${class}::error");
} }
return $self; return $self;
} }
@ -154,25 +154,27 @@ sub getConf {
} }
## @method protected string error($lang) ## @method protected string error($lang)
# error calls Portal/_i18n.pm to display error in the wanted language # error calls Portal/_i18n.pm to display error in the wanted language.
# @param lang optional (browser language is used instead) # @param lang optional (browser language is used instead)
# @return error message # @return error message
sub error { sub error {
my $self = shift; my $self = shift;
return &Lemonldap::NG::Portal::_i18n::error( $self->{error}, my $lang = shift || $ENV{HTTP_ACCEPT_LANGUAGE};
shift || $ENV{HTTP_ACCEPT_LANGUAGE} ); my $code = $self->{error} || shift;
return &Lemonldap::NG::Portal::_i18n::error( $code, $lang );
} }
## @method int error_type() ## @method int error_type()
# error_type tells if error is positive, warning or negative # error_type tells if error is positive, warning or negative
sub error_type { sub error_type {
my $self = shift; my $self = shift;
my $code = shift || $self->{error};
# Positive errors # Positive errors
return "positive" return "positive"
if ( if (
scalar( scalar(
grep { /^$self->{error}$/ } ( grep { /^$code$/ } (
-2, #PE_REDIRECT -2, #PE_REDIRECT
-1, #PE_DONE, -1, #PE_DONE,
0, #PE_OK 0, #PE_OK
@ -185,7 +187,7 @@ sub error_type {
return "warning" return "warning"
if ( if (
scalar( scalar(
grep { /^$self->{error}$/ } ( grep { /^$code$/ } (
1, #PE_SESSIONEXPIRED 1, #PE_SESSIONEXPIRED
2, #PE_FORMEMPTY 2, #PE_FORMEMPTY
9, #PE_FIRSTACCESS 9, #PE_FIRSTACCESS
@ -326,7 +328,6 @@ sub _subProcess {
my $err = undef; my $err = undef;
foreach my $sub (@subs) { foreach my $sub (@subs) {
print STDERR "$sub\n";
if ( $self->{$sub} ) { if ( $self->{$sub} ) {
last if ( $err = &{ $self->{$sub} }($self) ); last if ( $err = &{ $self->{$sub} }($self) );
} }
@ -359,39 +360,21 @@ sub get_url {
return if ( $self->param('url') =~ m#[^A-Za-z0-9\+/=]# ); return if ( $self->param('url') =~ m#[^A-Za-z0-9\+/=]# );
return $self->param('url'); return $self->param('url');
} }
###############################################################
# MAIN subroutine: call all steps until one returns something #
# different than PE_OK #
###############################################################
# Process call functions issued from : ####################
# * itself : controlUrlOrigin, controlExistingSession, setMacros, setGroups, # SOAP subroutines #
# store, buildCookie, log, autoredirect ####################
# * authentication module : extractFormInfo, setAuthSessionInfo, authenticate
# * user database module : getUser, setSessionInfo
sub process { ##@method string SOAP::Data getCookies($user,$password)
my ($self) = @_; # Called in SOAP context, returns cookies in an array.
$self->{error} = PE_OK; # This subroutine works only for portals working with user and password
$self->{error} = $self->_subProcess(
qw(checkNotifBack controlUrlOrigin controlExistingSession authInit
extractFormInfo userDBInit getUser setAuthSessionInfo setSessionInfo
setMacros setGroups authenticate store buildCookie log
checkNotification autoRedirect)
);
$self->updateStatus;
return ( ( $self->{error} > 0 ) ? 0 : 1 );
}
##@method string SOAPResponse getCookies($user,$password)
# Called in SOAP context, returns cookies in an array
#@param user uid #@param user uid
#@param password password #@param password password
#@return session => { error => code , cookies => { cookieName1 => value ,... } } #@return session => { error => code , cookies => { cookieName1 => value ,... } }
sub getCookies { sub getCookies {
my $class = shift; my $class = shift;
$self->{error} = PE_OK; $self->{error} = PE_OK;
( $self->{user}, $self->{password} ) = @_; ( $self->{user}, $self->{password} ) = ( shift, shift );
unless ( $self->{user} && $self->{password} ) { unless ( $self->{user} && $self->{password} ) {
$self->{error} = PE_FORMEMPTY; $self->{error} = PE_FORMEMPTY;
} }
@ -412,9 +395,36 @@ sub getCookies {
); );
} }
my $res = SOAP::Data->name( session => \SOAP::Data->value(@tmp) ); my $res = SOAP::Data->name( session => \SOAP::Data->value(@tmp) );
$self->updateStatus;
return $res; return $res;
} }
###############################################################
# MAIN subroutine: call all steps until one returns something #
# different than PE_OK #
###############################################################
##@method boolean process()
# Main method.
# process() call functions issued from :
# - itself : controlUrlOrigin, controlExistingSession, setMacros, setGroups, store, buildCookie, log, autoredirect
# - authentication module : extractFormInfo, setAuthSessionInfo, authenticate
# - user database module : getUser, setSessionInfo
#@return 1 if user is all is OK, 0 if session isn't created or a notification has to be done
sub process {
my ($self) = @_;
$self->{error} = PE_OK;
$self->{error} = $self->_subProcess(
qw(checkNotifBack controlUrlOrigin controlExistingSession authInit
extractFormInfo userDBInit getUser setAuthSessionInfo setSessionInfo
setMacros setGroups authenticate store buildCookie log
checkNotification autoRedirect)
);
$self->updateStatus;
return ( ( $self->{error} > 0 ) ? 0 : 1 );
}
## @method error_code checkNotifBack() ## @method error_code checkNotifBack()
# 1) Checks if a message has to be notified to the connected user. # 1) Checks if a message has to be notified to the connected user.
# @return error code # @return error code
@ -749,9 +759,11 @@ Lemonldap::NG::Portal::Simple - Base module for building Lemonldap::NG compatibl
cn => 'cn', cn => 'cn',
mail => 'mail', mail => 'mail',
appli => 'appli', appli => 'appli',
} },
# Activate SOAP service
Soap => 1
); );
if($portal->process()) { if($portal->process()) {
# Write here the menu with CGI methods. This page is displayed ONLY IF # Write here the menu with CGI methods. This page is displayed ONLY IF
# the user was not redirected here. # the user was not redirected here.
@ -777,6 +789,36 @@ Lemonldap::NG::Portal::Simple - Base module for building Lemonldap::NG compatibl
print '</form>'; print '</form>';
} }
SOAP mode authentication (client) :
#!/usr/bin/perl -l
use SOAP::Lite;
use Data::Dumper;
my $soap =
SOAP::Lite->proxy('http://auth.example.com/')
->uri('urn:/Lemonldap::NG::Portal::SharedConf');
my $r = $soap->getCookies( 'user', 'password' );
# Catch SOAP errors
if ( $r->fault ) {
print STDERR "SOAP Error: " . $r->fault->{faultstring};
}
else {
my $res = $r->result();
# If authentication failed, display error
if ( $res->{error} ) {
print STDERR "Error: " . $soap->error( 'fr', $res->{error} )->result();
}
# print session-ID
else {
print "Cookie: lemonldap=" . $res->{cookies}->{lemonldap};
}
}
=head1 DESCRIPTION =head1 DESCRIPTION
Lemonldap::NG::Portal::Simple is the base module for building Lemonldap::NG Lemonldap::NG::Portal::Simple is the base module for building Lemonldap::NG