« blib/lib/Lemonldap/NG/Portal/UserDB/Facebook.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/2F/Radius.pm »
| 1 | package Lemonldap::NG::Portal::Auth::Radius; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use Mouse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | ▶ | use Lemonldap::NG::Portal::Lib::Radius; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | PE_OK | ||||||||||||
| 8 | PE_BADCREDENTIALS | ||||||||||||
| 9 | PE_RADIUSCONNECTFAILED | ||||||||||||
| 10 | 3 | ); | |||||||||||
| 11 | |||||||||||||
| 12 | 3 | extends qw(Lemonldap::NG::Portal::Auth::_WebForm); | |||||||||||
| 13 | |||||||||||||
| 14 | 3 | our $VERSION = '2.20'; | |||||||||||
| 15 | |||||||||||||
| 16 | # PROPERTIES | ||||||||||||
| 17 | |||||||||||||
| 18 | 3 | has modulename => ( is => 'ro', default => 'radius' ); | |||||||||||
| 19 | 3 | has radiusLib => ( is => 'rw' ); | |||||||||||
| 20 | |||||||||||||
| 21 | # conf radiusExportedVars with key,value swapped. | ||||||||||||
| 22 | has sessionKeys => ( | ||||||||||||
| 23 | is => 'ro', | ||||||||||||
| 24 | lazy => 1, | ||||||||||||
| 25 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 26 | 0 | my $self = shift; | |||||||||||
| 27 | 0 | my $sessionKeys = {}; | |||||||||||
| 28 | 0 | my $attributeMap = $self->conf->{radiusExportedVars}; | |||||||||||
| 29 | 0 | ▶ | if ($attributeMap) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | |||||||||||||
| 31 | # Swap key value {session => radius} to {radius => session} | ||||||||||||
| 32 | 0 | ▶ | while ( my ( $k, $v ) = each %{$attributeMap} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 0 | $sessionKeys->{$v} = $k; | |||||||||||
| 34 | } | ||||||||||||
| 35 | } | ||||||||||||
| 36 | 0 | return $sessionKeys; | |||||||||||
| 37 | } | ||||||||||||
| 38 | 3 | ); | |||||||||||
| 39 | |||||||||||||
| 40 | # INITIALIZATION | ||||||||||||
| 41 | |||||||||||||
| 42 | 2 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 43 | 2 | my $self = shift; | |||||||||||
| 44 | $self->radiusLib( | ||||||||||||
| 45 | Lemonldap::NG::Portal::Lib::Radius->new( | ||||||||||||
| 46 | radius_dictionary => $self->conf->{radiusDictionaryFile}, | ||||||||||||
| 47 | radius_req_attribute_config => | ||||||||||||
| 48 | $self->conf->{radiusRequestAttributes}, | ||||||||||||
| 49 | radius_secret => $self->conf->{radiusSecret}, | ||||||||||||
| 50 | radius_server => $self->conf->{radiusServer}, | ||||||||||||
| 51 | radius_timeout => $self->conf->{radiusTimeout}, | ||||||||||||
| 52 | radius_msgauth => $self->conf->{radiusMsgAuth}, | ||||||||||||
| 53 | 2 | modulename => "radius", | |||||||||||
| 54 | logger => $self->logger, | ||||||||||||
| 55 | p => $self->p, | ||||||||||||
| 56 | ) | ||||||||||||
| 57 | ); | ||||||||||||
| 58 | 2 | return $self->Lemonldap::NG::Portal::Auth::_WebForm::init(); | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | # RUNNING METHODS | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub authenticate { | ||||||||||
|
Subroutine
authenticate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 64 | 0 | my ( $self, $req ) = @_; | |||||||||||
| 65 | |||||||||||||
| 66 | 0 | $self->logger->debug( "Send authentication request ($req->{user})" | |||||||||||
| 67 | . " to Radius server ($self->{conf}->{radiusServer})" ); | ||||||||||||
| 68 | |||||||||||||
| 69 | # Session info is empty or unknown at this step | ||||||||||||
| 70 | my $res = $self->radiusLib->check_pwd( $req, {}, $req->user, | ||||||||||||
| 71 | 0 | $req->data->{password} ); | |||||||||||
| 72 | 0 | ▶ | return PE_RADIUSCONNECTFAILED unless $res; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 0 | ▶ | unless ( $res->{result} == 1 ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | $self->userLogger->warn( | ||||||||||||
| 75 | 0 | "Radius authentication failed for user " . $req->{user} ); | |||||||||||
| 76 | 0 | $self->setSecurity($req); | |||||||||||
| 77 | 0 | return PE_BADCREDENTIALS; | |||||||||||
| 78 | } | ||||||||||||
| 79 | 0 | $self->logger->debug("Radius auth OK"); | |||||||||||
| 80 | |||||||||||||
| 81 | # in case of a valid response $self->radius->{'attributes'} | ||||||||||||
| 82 | # is filled with response attributes | ||||||||||||
| 83 | 0 | $req->data->{_radiusAttributes} = $res->{attributes}; | |||||||||||
| 84 | |||||||||||||
| 85 | 0 | return PE_OK; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 0 | ▶ | sub setAuthSessionInfo { | ||||||||||
|
Subroutine
setAuthSessionInfo: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 89 | 0 | my ( $self, $req ) = @_; | |||||||||||
| 90 | 0 | my $attributeMap = $self->sessionKeys; | |||||||||||
| 91 | $req->{sessionInfo}->{authenticationLevel} = | ||||||||||||
| 92 | 0 | $self->conf->{radiusAuthnLevel}; | |||||||||||
| 93 | |||||||||||||
| 94 | 0 | ▶ | if ($attributeMap) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | ▶ | while ( my ( $attr_radname, $attr_value ) = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 0 | ▶ | each %{ $req->data->{_radiusAttributes} || {} } ) | ||||||||||
|
Condition0%0/2
$req->data->{'_radiusAttributes'} || {}
MC/DC0%0/1
$req->data->{'_radiusAttributes'} || {}
$req->data->{'_radiusAttributes'}
Truth table0%0/2
A
A= $req->data->{'_radiusAttributes'}
| |||||||||||||
| 97 | { | ||||||||||||
| 98 | 0 | my $sessionAttributeName = $attributeMap->{$attr_radname}; | |||||||||||
| 99 | 0 | ▶ | if ($sessionAttributeName) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | 0 | $req->sessionInfo->{$sessionAttributeName} = $attr_value; | |||||||||||
| 101 | } | ||||||||||||
| 102 | } | ||||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 0 | return PE_OK; | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 0 | ▶ | sub authLogout { | ||||||||||
|
Subroutine
authLogout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 109 | 0 | return PE_OK; | |||||||||||
| 110 | } | ||||||||||||
| 111 | |||||||||||||
| 112 | 3 | 1; | |||||||||||