LEMONLDAP::NG : * new feature in devel : notification system

* now, there is a shared key that can be use to crypt datas
                  (used in notification to hide cookie value)
This commit is contained in:
Xavier Guimard 2009-01-28 17:37:10 +00:00
parent 477aa41115
commit 2540bb36f0
9 changed files with 84 additions and 31 deletions

View File

@ -14,6 +14,7 @@ requires:
Regexp::Assemble: 0 Regexp::Assemble: 0
Storable: 0 Storable: 0
SOAP::Lite: 0 SOAP::Lite: 0
Crypt::Rijndael: 0
meta-spec: meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.3.html url: http://module-build.sourceforge.net/META-spec-v1.3.html
version: 1.3 version: 1.3

View File

@ -26,8 +26,9 @@ WriteMakefile(
'DBI' => 0, 'DBI' => 0,
'Storable' => 0, 'Storable' => 0,
'Regexp::Assemble' => 0, 'Regexp::Assemble' => 0,
'Cache::Cache' => 0, 'Cache::Cache' => 0,
'SOAP::Lite' => 0, 'SOAP::Lite' => 0,
'Crypt::Rijndael' => 0,
}, # e.g., Module::Name => 1.1 }, # e.g., Module::Name => 1.1
#EXE_FILES => [ 'scripts/lmConfig_File2MySQL', ], #EXE_FILES => [ 'scripts/lmConfig_File2MySQL', ],
( (

View File

@ -12,6 +12,7 @@ no strict 'refs';
use Data::Dumper; use Data::Dumper;
use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Common::Conf::Constants;
use Regexp::Assemble; use Regexp::Assemble;
use Crypt::Rijndael;
use constant DEFAULTCONFFILE => "/etc/lemonldap-ng/storage.conf"; use constant DEFAULTCONFFILE => "/etc/lemonldap-ng/storage.conf";
@ -164,16 +165,22 @@ sub getConf {
} }
else { else {
$args->{cfgNum} ||= $self->lastCfg; $args->{cfgNum} ||= $self->lastCfg;
my $r;
unless ( ref( $self->{refLocalStorage} ) ) { unless ( ref( $self->{refLocalStorage} ) ) {
$msg = "get remote configuration (localStorage unavailable)"; $msg = "get remote configuration (localStorage unavailable)";
return $self->getDBConf($args); $r = $self->getDBConf($args);
} }
my $r = $self->{refLocalStorage}->get('conf'); else {
$r = $self->{refLocalStorage}->get('conf');
if ( $r->{cfgNum} == $args->{cfgNum} ) { if ( $r->{cfgNum} == $args->{cfgNum} ) {
$msg = "configuration unchanged, get configuration from cache"; $msg = "configuration unchanged, get configuration from cache";
return $r;
} }
return $self->getDBConf($args); else {
$r = $self->getDBConf($args);
}
}
$r->{cipher} = Crypt::Rijndael->new( $r->{key} || 'lemonldap-ng-key', Crypt::Rijndael::MODE_CBC() );
return $r;
} }
} }

View File

@ -8,11 +8,13 @@ our $VERSION = 0.22;
sub prereq { sub prereq {
my $self = shift; my $self = shift;
unless ( $self->{dirName} ) { unless ( $self->{dirName} ) {
$Lemonldap::NG::Common::Conf::msg = '"dirName" is required in "File" configuration type !'; $Lemonldap::NG::Common::Conf::msg =
'"dirName" is required in "File" configuration type !';
return 0; return 0;
} }
unless ( -d $self->{dirName} ) { unless ( -d $self->{dirName} ) {
$Lemonldap::NG::Common::Conf::msg = "Directory \"$self->{dirName}\" does not exist !"; $Lemonldap::NG::Common::Conf::msg =
"Directory \"$self->{dirName}\" does not exist !";
return 0; return 0;
} }
1; 1;
@ -35,12 +37,13 @@ sub lastCfg {
sub lock { sub lock {
my $self = shift; my $self = shift;
if( $self->isLocked ) { if ( $self->isLocked ) {
sleep 2; sleep 2;
return 0 if( $self->isLocked ); return 0 if ( $self->isLocked );
} }
unless( open F, ">".$self->{dirName} . "/lmConf.lock" ) { unless ( open F, ">" . $self->{dirName} . "/lmConf.lock" ) {
$Lemonldap::NG::Common::Conf::msg = "Unable to lock (".$self->{dirName}."/lmConf.lock)\n"; $Lemonldap::NG::Common::Conf::msg =
"Unable to lock (" . $self->{dirName} . "/lmConf.lock)\n";
return 0; return 0;
} }
print F $$; print F $$;
@ -61,8 +64,10 @@ sub unlock {
sub store { sub store {
my ( $self, $fields ) = @_; my ( $self, $fields ) = @_;
my $mask = umask; my $mask = umask;
umask ( oct ( '0027' ) ); umask( oct('0027') );
unless( open FILE, '>' . $self->{dirName} . "/lmConf-" . $fields->{cfgNum} ) { unless ( open FILE,
'>' . $self->{dirName} . "/lmConf-" . $fields->{cfgNum} )
{
$Lemonldap::NG::Common::Conf::msg = "Open file failed: $!"; $Lemonldap::NG::Common::Conf::msg = "Open file failed: $!";
$self->unlock; $self->unlock;
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
@ -71,7 +76,7 @@ sub store {
print FILE "$k\n\t$v\n\n"; print FILE "$k\n\t$v\n\n";
} }
close FILE; close FILE;
umask( $mask ); umask($mask);
$self->unlock; $self->unlock;
return $fields->{cfgNum}; return $fields->{cfgNum};
} }
@ -98,7 +103,8 @@ sub load {
sub delete { sub delete {
my ( $self, $cfgNum ) = @_; my ( $self, $cfgNum ) = @_;
unlink ( $self->{dirName} . "/lmConf-$cfgNum" ); unlink( $self->{dirName} . "/lmConf-$cfgNum" );
} }
1;
__END__ __END__

View File

@ -89,6 +89,7 @@ lib/Lemonldap/NG/Portal/AuthSSL.pm
lib/Lemonldap/NG/Portal/CDA.pm lib/Lemonldap/NG/Portal/CDA.pm
lib/Lemonldap/NG/Portal/Error.pm lib/Lemonldap/NG/Portal/Error.pm
lib/Lemonldap/NG/Portal/Menu.pm lib/Lemonldap/NG/Portal/Menu.pm
lib/Lemonldap/NG/Portal/Notification.pm
lib/Lemonldap/NG/Portal/SharedConf.pm lib/Lemonldap/NG/Portal/SharedConf.pm
lib/Lemonldap/NG/Portal/Simple.pm lib/Lemonldap/NG/Portal/Simple.pm
lib/Lemonldap/NG/Portal/UserDBLDAP.pm lib/Lemonldap/NG/Portal/UserDBLDAP.pm

View File

@ -44,6 +44,10 @@ my $portal = Lemonldap::NG::Portal::SharedConf->new(
#customFunctions => 'function1 function2', #customFunctions => 'function1 function2',
#customFunctions => 'Package::func1 Package::func2', #customFunctions => 'Package::func1 Package::func2',
# NOTIFICATIONS SERVICE
# Use it to be able to notify messages during authentication
#notification => 1,
# OTHERS # OTHERS
# You can also overload any parameter issued from manager # You can also overload any parameter issued from manager
# configuration. Example: # configuration. Example:
@ -104,6 +108,21 @@ if ( $portal->process() ) {
print $portal->header('text/html; charset=utf8'); print $portal->header('text/html; charset=utf8');
print $template->output; print $template->output;
} }
elsif( my $notif = $portal->notification ) {
my $template = HTML::Template->new(
filename => "$skin_dir/$skin/notification.tpl",
die_on_bad_params => 0,
cache => 0,
filter => sub { $portal->translate_template(@_) }
);
$template->param( AUTH_ERROR => $portal->error );
$template->param( AUTH_ERROR_TYPE => $portal->error_type );
$template->param( AUTH_URL => $portal->get_url );
$template->param( NOTIFICATION => $notif );
print $portal->header('text/html; charset=utf8');
print $template->output;
}
else { else {
# HTML::Template object creation # HTML::Template object creation

View File

@ -6,6 +6,19 @@
<div class="loginlogo"></div> <div class="loginlogo"></div>
<TMPL_VAR NAME="NOTIFICATION"> <form action="#" method="post" class="login">
<h3><lang en="New message(s)" fr="Nouveaux messages"/>&nbsp;:</h3>
<table>
<tr><td>
<TMPL_VAR NAME="NOTIFICATION">
<div class="buttons">
<button type="submit" class="positive">
<img src="skins/pastel/accept.png" alt="" />
<lang en="Accept" fr="Accepter" />
</button>
</div>
</td></tr>
</table>
</form>
<TMPL_INCLUDE NAME="footer.tpl"> <TMPL_INCLUDE NAME="footer.tpl">

View File

@ -672,7 +672,8 @@ L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
=head1 COPYRIGHT AND LICENSE =head1 COPYRIGHT AND LICENSE
Copyright (C) 2005-2007 by Xavier Guimard E<lt>x.guimard@free.frE<gt> Copyright (C) 2005-2007 by Clement OUDOT E<lt>clement@oodo.netE<gt>
E<lt>coudot@linagora.comE<gt>
This library is free software; you can redistribute it and/or modify This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.4 or, it under the same terms as Perl itself, either Perl version 5.8.4 or,

View File

@ -128,7 +128,7 @@ sub new {
%$self = ( %h, %$self ); %$self = ( %h, %$self );
} }
if ( $self->{notification} ) { if ( $self->{notification} ) {
require Lemonldap::NG::Common::Notification; require Lemonldap::NG::Portal::Notification;
} }
if ( $self->{Soap} ) { if ( $self->{Soap} ) {
require SOAP::Lite; require SOAP::Lite;
@ -572,17 +572,19 @@ sub controlExistingSession {
$self->{id} = $id; $self->{id} = $id;
# A session has been find => calling &existingSession # A session has been find => calling &existingSession
my ( $r, $datas ); my ($r);
%$datas = %h; %{ $self->{sessionInfo} } = %h;
untie(%h); untie(%h);
if ( $self->{existingSession} ) { if ( $self->{existingSession} ) {
$r = &{ $self->{existingSession} }( $self, $id, $datas ); $r =
&{ $self->{existingSession} }( $self, $id, $self->{sessionInfo} );
} }
else { else {
$r = $self->existingSession( $id, $datas ); $r = $self->existingSession( $id, $self->{sessionInfo} );
} }
if ( $r == PE_DONE ) { if ( $r == PE_DONE ) {
$self->{error} = $self->_subProcess(qw(log autoRedirect)); $self->{error} =
$self->_subProcess(qw(log checkNotification autoRedirect));
return $self->{error} || PE_DONE; return $self->{error} || PE_DONE;
} }
else { else {
@ -732,17 +734,19 @@ sub checkNotification {
my $self = shift; my $self = shift;
if ( $self->{notification} ) { if ( $self->{notification} ) {
my $tmp; my $tmp;
if ( ref( $self->{notification} ) ) { if ( $self->{notificationStorage} ) {
$tmp = $self->{notification}; $tmp = $self->{notificationStorage};
} }
else { else {
$tmp = $self->{configStorage}; $tmp = $self->{lmConf};
$tmp->{dbiTable} = 'notifications'; $self->abort( "notificationStorage not defined",
"This parameter is required to use notification system" )
unless ( ref($tmp) );
$tmp->{table} = 'notifications';
} }
if ( $self->{_notification} = my $obj = Lemonldap::NG::Portal::Notification->new($tmp);
Lemonldap::NG::Common::Notification->new($tmp) $self->abort($Lemonldap::NG::Portal::Notification::msg) unless ($obj);
->getNotification( $self->{user} ) ) if ( $self->{_notification} = $obj->getNotification($self) ) {
{
return PE_NOTIFICATION; return PE_NOTIFICATION;
} }
} }