Raise an error if notification connector fails (#595)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 8 years ago
parent b63305b641
commit 17a3b5e976
  1. 4
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/DBI.pm
  2. 11
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Notifications/LDAP.pm
  3. 15
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm
  4. 18
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm

@ -48,7 +48,7 @@ has _dbh => (
my $self = shift;
my $r = DBI->connect_cached(
$self->{dbiChain}, $self->{dbiUser},
$self->{dbiPassword}, { RaiseError => 0 }
$self->{dbiPassword}, { RaiseError => 1 }
);
$self->logger->error($DBI::errstr) unless ($r);
return $r;
@ -196,7 +196,7 @@ sub getDone {
# @return number of lines touched or 1 if select succeed
sub _execute {
my ( $self, $query, @args ) = @_;
my $dbh = $self->_dbh or return 0;
my $dbh = $self->_dbh or die "DB connection unavailable";
unless ( $self->sth( $dbh->prepare($query) ) ) {
$self->logger->warn( $dbh->errstr() );
return 0;

@ -226,7 +226,7 @@ sub getDone {
sub _search {
my ( $self, $filter ) = @_;
my $ldap = _ldap($self) or return ();
my $ldap = _ldap($self);
my $search = $ldap->search(
base => $self->{ldapConfBase},
@ -386,8 +386,7 @@ sub _ldap {
);
unless ($ldap) {
$self->logger->error( 'connexion failed: ' . $@ );
return;
die 'connexion failed: ' . $@;
}
# Start TLS if needed
@ -397,8 +396,7 @@ sub _ldap {
$h{capath} = $self->{caPath} if ( $self->{caPath} );
my $start_tls = $ldap->start_tls(%h);
if ( $start_tls->code ) {
$self->logger->error( 'tls failed: ' . $start_tls->error );
return;
die 'tls failed: ' . $start_tls->error;
}
}
@ -406,8 +404,7 @@ sub _ldap {
my $bind =
$ldap->bind( $self->{ldapBindDN}, password => $self->{ldapBindPassword} );
if ( $bind->code ) {
$self->logger->error( 'bind failed: ' . $bind->error );
return;
die 'bind failed: ' . $bind->error;
}
$self->{ldap} = $ldap;

@ -87,17 +87,20 @@ sub getNotifBack {
return $self->p->sendError( $req, 'No cookie found', 401 );
}
$id = $self->p->HANDLER->tsv->{cipher}->decrypt($id)
or return $self->sendError( $req, 'Unable to decrypt', 500 );
or return $self->p->sendError( $req, 'Unable to decrypt', 400 );
# Verify that session exists
$req->userData( $self->p->HANDLER->retrieveSession( $req, $id ) )
or return $self->sendError( $req, 'Unknown session', 401 );
or return $self->p->sendError( $req, 'Unknown session', 401 );
# Restore datas
$self->p->importHandlerDatas($req);
my $uid = $req->sessionInfo->{ $self->notifObject->notifField };
my ( $notifs, $forUser ) = $self->notifObject->getNotifications($uid);
my ( $notifs, $forUser );
eval { ( $notifs, $forUser ) = $self->notifObject->getNotifications($uid) };
return $self->p->sendError( $req, $@, 500 ) if ($@);
if ($notifs) {
# Get accepted notifications
@ -206,14 +209,16 @@ sub toForm {
$_->{id} = "1x$i";
$_;
} @notifs;
return $self->loadTemplate('notifinclude', params => {notifications => \@notifs});
return $self->loadTemplate( 'notifinclude',
params => { notifications => \@notifs } );
}
sub notificationServer {
my ( $self, $req ) = @_;
return $self->p->sendError( $req, 'Only JSON requests here', 400 )
unless ( $req->wantJSON );
my $res = $self->notifObject->newNotification( $req->content );
my $res = eval { $self->notifObject->newNotification( $req->content ) };
return $self->p->sendError( $req, $@, 500 ) if ($@);
return $self->p->sendError( $req, 'Bad request', 400 ) unless ($res);
return $self->p->sendJSONresponse( $req, { result => $res } );
}

@ -13,7 +13,11 @@ package Lemonldap::NG::Portal::Plugins::Notifications;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_NOTIFICATION);
use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
PE_NOTIFICATION
PE_OK
);
our $VERSION = '2.0.0';
@ -104,9 +108,15 @@ sub init {
sub checkNotifDuringAuth {
my ( $self, $req ) = @_;
if ( $req->{datas}->{notification} =
$self->module->checkForNotifications($req) )
{
eval {
$req->{datas}->{notification} =
$self->module->checkForNotifications($req);
};
if ($@) {
$self->logger->error($@);
return PE_ERROR;
}
if ( $req->{datas}->{notification} ) {
$self->p->rebuildCookies($req);
# Restore and cipher cookies

Loading…
Cancel
Save