Lemonldap-NG-Handler
view release on metacpan or search on metacpan
lib/Lemonldap/NG/Handler/Main/Run.pm view on Meta::CPAN
$class->logger->debug( "User "
. $session->{ $class->tsv->{whatToTrace} }
. " was granted access to $uri" );
# Catch POST rules
$class->postOutputFilter( $req, $session, $uri );
$class->postInputFilter( $req, $session, $uri );
return ( $class->OK, $session );
}
elsif ( $protection == $class->UNPROTECT ) {
# Ignore unprotected URIs
$class->logger->debug("No valid session but unprotected access");
$class->updateStatus( $req, 'UNPROTECT' );
$class->hideCookie($req);
$class->cleanHeaders($req);
return $class->OK;
}
elsif ( $protection == $class->MAYSKIP
and $class->grant( $req, $session, $uri, $cond ) eq '999_SKIP' )
{
$class->logger->debug("Access control skipped");
$class->updateStatus( $req, 'SKIP' );
$class->hideCookie($req);
$class->cleanHeaders($req);
return $class->OK;
}
else {
# Redirect user to the portal
$class->logger->debug("No cookie found")
unless ($id);
# if the cookie was fetched, a log is sent by retrieveSession()
$class->updateStatus( $req, $id ? 'EXPIRED' : 'REDIRECT' );
return $class->goToPortal( $req, $req->{env}->{REQUEST_URI} );
}
}
## @rmethod protected int unlog()
# Call localUnlog() then goToPortal() to unlog the current user.
# @return Constant value returned by goToPortal()
sub unlog {
my ( $class, $req ) = @_;
$class->localUnlog( $req, @_ );
$class->updateStatus( $req, 'LOGOUT' );
return $class->goToPortal( $req, '/', 'logout=1' );
}
# INTERNAL METHODS
## @rmethod protected void updateStatus(string action,string user,string url)
# Inform the status process of the result of the request if it is available
# @param action string Result of access control (as $class->OK, $class->SKIP, LOGOUT...)
# @param optional user string Username to log, if undefined defaults to remote IP
# @param optional url string URL to log, if undefined defaults to request URI
sub updateStatus {
my ( $class, $req, $action, $user, $url ) = @_;
$user ||= $req->address;
$url ||= $req->{env}->{REQUEST_URI};
$class->publishStatus(
user => $user,
url => $req->{env}->{HTTP_HOST} . $url,
handlerAction => $action
);
}
## @rmethod void lmLog(string msg, string level)
# Wrapper for Apache log system
# @param $msg message to log
# @param $level string (emerg|alert|crit|error|warn|notice|info|debug)
sub lmLog {
my ( $class, $msg, $level ) = @_;
return $class->logger->$level($msg);
}
sub auditLog {
my ( $class, $req, %info ) = @_;
$class->_auditLogger->log( $req, %info );
}
## @rmethod protected boolean checkMaintenanceMode
# Check if we are in maintenance mode
# @return true if maintenance mode is enabled
sub checkMaintenanceMode {
my ( $class, $req ) = @_;
my $vhost = $class->resolveAlias($req);
my $_maintenance =
( defined $class->tsv->{maintenance}->{$vhost} )
? $class->tsv->{maintenance}->{$vhost}
: $class->tsv->{maintenance}->{_};
if ($_maintenance) {
$class->logger->debug("Maintenance mode enabled");
return 1;
}
return 0;
}
## @rmethod int getLevel(string uri, string $vhost)
# Return required authentication level for this URI
# default to vhost authentication level
# @param $uri URI
# @param $vhost vhost name, default to current request
sub getLevel {
my ( $class, $req, $uri, $vhost ) = @_;
my $level;
$vhost ||= $class->resolveAlias($req);
# Using URL authentification level if exists
for (
my $i = 0 ;
$i < ( $class->tsv->{locationCount}->{$vhost} || 0 ) ;
$i++
)
{
if ( $uri && $uri =~ $class->tsv->{locationRegexp}->{$vhost}->[$i] ) {
( run in 2.032 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )