Commit 21f5808c authored by Yadd's avatar Yadd
Browse files

LEMONLDAP::NG : Notification system is running now (for file storage only)....

LEMONLDAP::NG : Notification system is running now (for file storage only). TODO: Soapservice to accept notifications

parent 2540bb36
......@@ -9,6 +9,7 @@ lib/Lemonldap/NG/Common/Conf/Constants.pm
lib/Lemonldap/NG/Common/Conf/DBI.pm
lib/Lemonldap/NG/Common/Conf/File.pm
lib/Lemonldap/NG/Common/Conf/SOAP.pm
lib/Lemonldap/NG/Common/Crypto.pm
Makefile.PL
MANIFEST
META.yml Module meta-data (added by MakeMaker)
......
......@@ -11,8 +11,8 @@ use strict;
no strict 'refs';
use Data::Dumper;
use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Common::Crypto;
use Regexp::Assemble;
use Crypt::Rijndael;
use constant DEFAULTCONFFILE => "/etc/lemonldap-ng/storage.conf";
......@@ -179,7 +179,9 @@ sub getConf {
$r = $self->getDBConf($args);
}
}
$r->{cipher} = Crypt::Rijndael->new( $r->{key} || 'lemonldap-ng-key', Crypt::Rijndael::MODE_CBC() );
$r->{cipher} =
Lemonldap::NG::Common::Crypto->new( $r->{key} || 'lemonldap-ng-key',
Crypt::Rijndael::MODE_CBC() );
return $r;
}
}
......
##@file
# Extend Crypt::Rijndael to add base64 encoding to cypher functions
##@class
# Extend Crypt::Rijndael to add base64 encoding to cypher functions.
# $Lemonldap::NG::Common::Crypto::msg contains Crypt::Rijndael errors.
package Lemonldap::NG::Common::Crypto;
use strict;
use Crypt::Rijndael;
use MIME::Base64;
use base qw(Crypt::Rijndael);
our $msg;
## @cmethod Lemonldap::NG::Common::Crypto new(array param)
# Constructor
# @param @param Crypt::Rijndael::new() parameters
# @return Lemonldap::NG::Common::Crypto object
sub new {
my $class = shift;
my $self = Crypt::Rijndael->new(@_);
return bless $self, $class;
}
## @method string encrypt(string data)
# Encrypt $data and return it in Base64 format
# @param data datas to encrypt
# @return encrypted datas in Base64 format
sub encrypt {
my $self = shift;
my $tmp;
eval { $tmp = encode_base64( $self->SUPER::encrypt(@_), '' ); };
if ($@) {
$msg = "Crypt::Rijndael error : $@";
return undef;
}
else {
$msg = '';
return $tmp;
}
}
## @method string decrypt(string data)
# Decrypt $data and return it in
# @param data datas to decrypt in Base64 format
# @return decrypted datas
sub decrypt {
my $self = shift;
my $tmp = shift;
$tmp =~ s/%2B/\+/ig;
$tmp =~ s/%2F/\//ig;
$tmp =~ s/%3D/=/ig;
eval { $tmp = $self->SUPER::decrypt( decode_base64($tmp) ); };
if ($@) {
$msg = "Crypt::Rijndael error : $@";
return undef;
}
else {
$msg = '';
return $tmp;
}
}
1;
......@@ -136,8 +136,7 @@ sub group {
# Redirects the user to the portal and exit.
sub goToPortal {
my $self = shift;
my $tmp = encode_base64( $self->_uri );
$tmp =~ s/[\r\n]//sg;
my $tmp = encode_base64( $self->_uri, '' );
print CGI::redirect( -uri => "$portal?url=$tmp" );
exit;
}
......
......@@ -713,9 +713,7 @@ sub encodeUrl {
. $portString
. $url;
}
$u = encode_base64($u);
$u =~ s/[\r\n\s]//sg;
return $u;
return encode_base64( $u, '' );
}
## @rmethod protected int goToPortal(string url, string arg)
......
......@@ -129,6 +129,20 @@ sub new {
}
if ( $self->{notification} ) {
require Lemonldap::NG::Portal::Notification;
my $tmp;
if ( $self->{notificationStorage} ) {
$tmp = $self->{notificationStorage};
}
else {
$tmp = $self->{lmConf};
$self->abort( "notificationStorage not defined",
"This parameter is required to use notification system" )
unless ( ref($tmp) );
$tmp->{table} = 'notifications';
}
$self->{notifObject} = Lemonldap::NG::Portal::Notification->new($tmp);
$self->abort($Lemonldap::NG::Portal::Notification::msg)
unless ( $self->{notifObject} );
}
if ( $self->{Soap} ) {
require SOAP::Lite;
......@@ -344,6 +358,8 @@ sub _subProcess {
my $err = undef;
foreach my $sub (@subs) {
#print STDERR "DEBUG : $sub\n";
if ( $self->{$sub} ) {
last if ( $err = &{ $self->{$sub} }($self) );
}
......@@ -465,7 +481,7 @@ sub process {
my ($self) = @_;
$self->{error} = PE_OK;
$self->{error} = $self->_subProcess(
qw(checkNotifBack controlUrlOrigin controlExistingSession authInit
qw(controlUrlOrigin checkNotifBack controlExistingSession authInit
extractFormInfo userDBInit getUser setAuthSessionInfo setSessionInfo
setMacros setGroups authenticate store buildCookie log
checkNotification autoRedirect)
......@@ -474,18 +490,8 @@ sub process {
return ( ( $self->{error} > 0 ) ? 0 : 1 );
}
##@method int checkNotifBack()
# 1) Checks if a message has to be notified to the connected user.
#@return Lemonldap::NG::Portal error code
sub checkNotifBack {
my $self = shift;
# TODO
PE_OK;
}
##@method int controlUrlOrigin()
# 2) If the user was redirected here, loads 'url' parameter.
# 1) If the user was redirected here, loads 'url' parameter.
#@return Lemonldap::NG::Portal constant
sub controlUrlOrigin {
my $self = shift;
......@@ -515,24 +521,50 @@ m#^https?://(?:$self->{reVHosts}|(?:[^/]*)?$self->{domain})(?:/.*)?$#
PE_OK;
}
##@method int controlExistingSession()
##@method int checkNotifBack()
# 2) Checks if a message has been notified to the connected user.
# Call Lemonldap::NG::Portal::Notification::checkNotification()
#@return Lemonldap::NG::Portal error code
sub checkNotifBack {
my $self = shift;
if ( $self->{notification} and grep( /^reference/, $self->param() ) ) {
unless ( $self->{notifObject}->checkNotification($self) ) {
$self->{_notification} =
$self->{notifObject}->getNotification($self);
return PE_NOTIFICATION;
}
else {
$self->{error} =
$self->_subProcess(qw(log checkNotification autoRedirect));
return $self->{error} || PE_DONE;
}
}
PE_OK;
}
##@method int controlExistingSession(string id)
# 3) Control existing sessions.
# To overload to control what to do with existing sessions.
# what to do with existing sessions ?
# - nothing: user is authenticated and process returns true (default)
# - delete and create a new session (not implemented)
# - re-authentication (set existingSession => sub{PE_OK})
#@param $id optional value of the session-id else cookies are examinated.
#@return Lemonldap::NG::Portal constant
sub controlExistingSession {
my $self = shift;
my %cookies = fetch CGI::Cookie;
my ( $self, $id ) = @_;
my %cookies;
%cookies = fetch CGI::Cookie unless ($id);
# Store IP address
$self->{sessionInfo}->{ipAddr} = $ENV{REMOTE_ADDR};
# Test if Lemonldap::NG cookie is available
if ( $cookies{ $self->{cookieName} }
and my $id = $cookies{ $self->{cookieName} }->value )
if (
$id
or ( $cookies{ $self->{cookieName} }
and $id = $cookies{ $self->{cookieName} }->value )
)
{
my %h;
......@@ -729,26 +761,15 @@ sub log {
##@method int checkNotification()
# 16) Check if messages has to be notified.
# Call Lemonldap::NG::Portal::Notification::getNotification().
#@return Lemonldap::NG::Portal constant
sub checkNotification {
my $self = shift;
if ( $self->{notification} ) {
my $tmp;
if ( $self->{notificationStorage} ) {
$tmp = $self->{notificationStorage};
}
else {
$tmp = $self->{lmConf};
$self->abort( "notificationStorage not defined",
"This parameter is required to use notification system" )
unless ( ref($tmp) );
$tmp->{table} = 'notifications';
}
my $obj = Lemonldap::NG::Portal::Notification->new($tmp);
$self->abort($Lemonldap::NG::Portal::Notification::msg) unless ($obj);
if ( $self->{_notification} = $obj->getNotification($self) ) {
return PE_NOTIFICATION;
}
if ( $self->{notification}
and $self->{_notification} =
$self->{notifObject}->getNotification($self) )
{
return PE_NOTIFICATION;
}
return PE_OK;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment