Core.pm untested

filter: Statementstmt 0.0% 0 / 122 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 173 CC 15 SCAR 32.1
CC
15
Cov
0%
Check_Refresh
72.0
locationRules
6.0
forgeHeader
6.0
CRAP 24.8
1 package Lemonldap::Handlers::Core;
2 use strict;
3 #A retirer en prod
4 use Data::Dumper;
5 our ( @ISA, $VERSION, @EXPORTS );
6 $VERSION = '3.1.0';
7 our $VERSION_LEMONLDAP = "3.1.0";
8 our $VERSION_INTERNAL = "3.1.0";
9  
10 sub locationRules {
11 my %param = @_;
12 # first retrieve session
13 my $id = $param{'id'} ;
14 my $config =$param{'config'} ;
15 my $uri = $param{'uri'};
16 my $host = $param{'host'};
17 my $target =$param{'target'};
18 my $_session = Lemonldap::Handlers::Session->get ('id' => $id ,
19 'config' => $config) ;
20  
21  
22 if (keys(%{$_session}) == 0){
23 return 0;
24 }
25  
26  
27 my $_trust = Lemonldap::Handlers::Policy->get (
28 'session' =>$_session ,
29 'parameters' => \%param );
30 my $result =$_trust->{profil} ;
31 my $response = $_trust->{response} ;
32  
33 my $h = {dn => $_session->{dn} ,uid=>$_session->{uid}, string => $_trust->{profil} , response => $_trust->{response} , clientIPAdress => $_session->{clientIPAdress} , SessExpTime => $_session->{SessExpTime} };
34  
35 return $h;
36 }
37  
38 sub getHeader {
39 my %param = @_;
40 # first retrieve session
41 my $result = $param{'profil'} ;
42 my $config =$param{'config'} ;
43 my $uid = $param{'uid'};
44 my $dn = $param{'dn'};
45 return Lemonldap::Handlers::Header->get('profil' => $result ,
46 'dn' => $dn ,
47 'config' => $config,
48 'uid' => $uid);
49 }
50  
51 sub forgeHeader {
52 my %param = @_;
53 # first retrieve session
54 my $result = $param{'line'} ;
55 my $config =$param{'config'} ;
56 my $reponse= Lemonldap::Handlers::Header->forge('line' => $result ,
57 'config' => $config,);
58 my $h;
59 if ( $reponse != 0 ){
60 $h ={header => $reponse->{header},content => $reponse->{content} ,decoded =>$reponse->{decoded} ,user =>$reponse->{user}};
61 }
62 return $h;
63 }
64 sub ParseHtml {
65 my %param = @_;
66 # first retrieve session
67 my $html = $param{'html'} ;
68 my $uri = $param{'uri'} ;
69 my $env = $param{'https'} ;
70 my $config =$param{'config'} ;
71 my $host= $param{'host'};
72 my $target= $param{'target'};
73 return Lemonldap::Handlers::Html->get('html' => $html ,
74 'host' => $host,
75 'uri' => $uri,
76 'target' => $target,
77 'config' => $config,
78 'https' =>$env,);
79 }
80  
81 ##########################################################
82 #Return code for Check refresh : #
83 # 0 : The sessExpTime hasn't been depassed yet #
84 # 1 : The request LDAP has to be done #
85 # 2 : The request LDAP hasn't to be done #
86 ##########################################################
87  
88 sub Check_Refresh {
89 my %param = @_;
90 # first retrieve session
91 my $id = $param{'id'} ;
92 my $config = $param{'config'} ;
93 my $uri = $param{'uri'};
94 my $host = $param{'host'};
95 my $sessExpTime = $param{'ExpTime'};
96 my $target = $param{'target'};
97 my $log = $param{'logs'};
98 if ( time() > $sessExpTime ) {
99  
100 #The request must been done on the central Memcached, so we have to delete temporarly the local server
101
102  
103 my $local = $config->{SERVERS}->{'local'};
104
105 #We check if a level 4 memcached has been configured
106 if ($config->{SERVERS}->{'servers'}){
107 my $local = $config->{SERVERS}->{'local'};
108 delete $config->{SERVERS}->{'local'};
109 }
110 #On effectue la requete sur le serveur principal
111 my $HashSession = Lemonldap::Handlers::Session->get ('id' => $id ,
112 'config' => $config);
113 if ($config->{SERVERS}->{'servers'}){
114 $config->{SERVERS}->{'local'} = $local;
115 }
116  
117 if (keys(%{$HashSession}) == 0 ){
118 #the memcached is unreachable
119 $log->warn("$config->{HANDLERID}: The central memcached is unreachable.Please check if your server is on or if your configuration file is correct.");
120 unless($config->{SERVERS}->{'local'}){
121 $log->err("$config->{HANDLERID}: Can't acces to any memcached server => Internal error");
122 #On a effectué une recherche infructueuse sur le serveur principal et il n'y a pas de serveur loca
123 #if the search has been done on the level 3 (means that there is no level 4) we must invite the user to re-authentification
124 return (-1,{},0,0);
125 }
126 #if not we must try to do it again on the level 3 cache
127
128 my $central = $config->{SERVERS}->{'servers'};
129 delete $config->{SERVERS}->{'servers'};
130  
131 #On effectue la requete sur le serveur local
132 $HashSession = Lemonldap::Handlers::Session->get ('id' => $id ,
133 'config' => $config);
134  
135 $config->{SERVERS}->{'servers'}= $central;
136  
137 if (keys(%{$HashSession}) == 0){
138 return (-1,{},0,0);
139 $log->err("$config->{HANDLERID}: Can't acces to the local memcached server => Internal error");
140 }
141  
142 }
143
144 my $_trust = Lemonldap::Handlers::Policy->get ('session' =>$HashSession ,
145 'parameters' => \%param);
146  
147  
148 my $test = $HashSession->{SessExpTime};
149 if ( $HashSession->{SessExpTime} eq $sessExpTime){
150 #This Httpd process must refresh the cache by requesting the LDAP server
151 return (1,$HashSession,$_trust->{profil},$_trust->{response});
152 }else{
153 #The request LDAP has already be done by another process
154 return (2,$HashSession,$_trust->{profil},$_trust->{response});
155 }
156 }else {
157 #The sessExptime is not yet expired
158 return (0,{},undef);
159 }
160 }
161  
162  
163  
164  
165 package Lemonldap::Handlers::Html ;
166 sub get {
167 my $class= shift;
168 my %_param = @_;
169 $_param{config}->{'REWRITEHTMLPLUGIN'}= 'Lemonldap::Handlers::RewriteHTML' unless $_param{config}->{'REWRITEHTMLPLUGIN'} ;
170 my $api = $_param{config}->{'REWRITEHTMLPLUGIN'} ;
171 eval "use $api;";
172 my $session =$api->get(%_param) ;
173 # bless $session, $class;
174 return $session;
175  
176  
177 }
178 package Lemonldap::Handlers::Session ;
179 use Data::Dumper;
180 sub get {
181 my $class= shift;
182 my %_param = @_;
183 $_param{config}->{'SESSIONSTOREPLUGIN'}= 'Lemonldap::Handlers::Memsession' unless $_param{config}->{'SESSIONSTOREPLUGIN'} ;
184 my $api = $_param{config}->{'SESSIONSTOREPLUGIN'} ;
185 eval "use $api;";
186 my $html =$api->get(%_param) ;
187 # bless $session, $class;
188  
189  
190  
191  
192  
193 return $html;
194 }
195  
196 package Lemonldap::Handlers::Policy ;
197  
198 sub get {
199 my $class=shift;
200 my %_param = @_;
201 $_param{parameters}->{config}->{'PLUGINPOLICY'}= 'Lemonldap::Handlers::MatrixPolicy' unless $_param{parameters}->{config}->{'PLUGINPOLICY'} ;
202 my $api = $_param{parameters}->{config}->{'PLUGINPOLICY'} ;
203 eval "use $api;" ;;
204 my $trust =$api->get(%_param) ;
205 # bless $trust , $class;
206 return $trust;
207 }
208 package Lemonldap::Handlers::Header ;
209 sub get {
210 my $class=shift;
211 my %_param = @_;
212 $_param{config}->{'PLUGINHEADER'}= 'Lemonldap::Handlers::AuthorizationHeader' unless $_param{config}->{'PLUGINHEADER'} ;
213 my $api = $_param{config}->{'PLUGINHEADER'} ;
214 print STDERR "ERIC A SUP $api\n";
215 eval "use $api;";
216 my $header =$api->get(%_param) ;
217 # bless $header , $class;
218 return $header;
219 }
220 sub forge {
221 my $class=shift;
222 my %_param = @_;
223 $_param{config}->{'PLUGINHEADER'}= 'Lemonldap::Handlers::AuthorizationHeader' unless $_param{config}->{'PLUGINHEADER'} ;
224 my $api = $_param{config}->{'PLUGINHEADER'} ;
225 eval "use $api;";
226 my $header =$api->forge(%_param) ;
227 # bless $header , $class;
228 return $header;
229 }
230  
231
232  
233  
234 1;