Portal: catch ENV exportedVars for all UserDB modules (#58)

This commit is contained in:
Clément Oudot 2010-05-07 21:33:57 +00:00
parent f7fc51100c
commit 2d88be8222
4 changed files with 13 additions and 68 deletions

View File

@ -1147,6 +1147,7 @@ sub setSessionInfo {
$xheader =~ s/(.*?)(\,)+.*/$1/ if $xheader;
$self->{sessionInfo}->{xForwardedForAddr} = $xheader || $ENV{REMOTE_ADDR};
# Date and time
if ( $self->{updateSession} ) {
$self->{sessionInfo}->{updateTime} =
&POSIX::strftime( "%Y%m%d%H%M%S", localtime() );
@ -1156,6 +1157,17 @@ sub setSessionInfo {
$self->{sessionInfo}->{startTime} =
&POSIX::strftime( "%Y%m%d%H%M%S", localtime() );
}
# Get environment variables matching exportedVars
foreach ( keys %{ $self->{exportedVars} } ) {
if ( my $tmp = $ENV{ $self->{exportedVars}->{$_} } ) {
$tmp =~ s/[\r\n]/ /gs;
$self->{sessionInfo}->{$_} = $tmp;
delete $self->{exportedVars}->{$_};
}
}
# Call UserDB setSessionInfo
return $self->SUPER::setSessionInfo();
}

View File

@ -1,59 +0,0 @@
## @file
# Env userDB mechanism
## @class
# Env userDB mechanism class
package Lemonldap::NG::Portal::UserDBEnv;
use strict;
use Lemonldap::NG::Portal::Simple;
our $VERSION = '0.1';
## @apmethod int userDBInit()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub userDBInit {
PE_OK;
}
## @apmethod int getUser()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub getUser {
PE_OK;
}
## @apmethod int setSessionInfo()
# Fetch all environment variables declared in exportedVars
# @return Lemonldap::NG::Portal constant
sub setSessionInfo {
my $self = shift;
# Check access to %ENV
unless ( defined %ENV ) {
$self->lmLog( "No environment variables available", 'error' );
return PE_ERROR;
}
# Parse exportedVars
if ( ref( $self->{exportedVars} ) eq 'HASH' ) {
foreach ( keys %{ $self->{exportedVars} } ) {
if ( exists $ENV{ $self->{exportedVars}->{$_} } ) {
$self->{sessionInfo}->{$_} =
$ENV{ $self->{exportedVars}->{$_} };
}
}
}
PE_OK;
}
## @apmethod int setGroups()
# Do nothing
# @return Lemonldap::NG::Portal constant
sub setGroups {
PE_OK;
}
1;

View File

@ -100,20 +100,12 @@ sub setSessionInfo {
}
elsif ( ref( $self->{exportedVars} ) eq 'HASH' ) {
foreach ( keys %{ $self->{exportedVars} } ) {
# Special code to catch env var
if ( my $tmp = $ENV{$_} ) {
$tmp =~ s/[\r\n]/ /gs;
$self->{sessionInfo}->{$_} = $tmp;
}
else {
$self->{sessionInfo}->{$_} =
$self->{ldap}
->getLdapValue( $self->{entry}, $self->{exportedVars}->{$_} )
|| "";
}
}
}
else {
$self->abort('Only hash reference are supported now in exportedVars');
}

View File

@ -28,7 +28,6 @@ sub getUser {
# Do nothing
# @return Lemonldap::NG::Portal constant
sub setSessionInfo {
my $self = shift;
PE_OK;
}
@ -38,5 +37,6 @@ sub setSessionInfo {
sub setGroups {
PE_OK;
}
1;