blib/lib/Lemonldap/NG/Portal/Auth/WebID.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 84 CC 6 SCAR 24.7
CC
6
Cov
0%
extractFormInfo
30.0
init
6.0
authenticate
2.0
CRAP 11.9
1 package Lemonldap::NG::Portal::Auth::WebID;
2  
3 use strict;
4 use Mouse;
5 use Regexp::Assemble;
6 use Web::ID;
7 use Lemonldap::NG::Portal::Main::Constants qw(
8 PE_OK
9 PE_BADPARTNER
10 PE_BADCERTIFICATE
11 PE_BADCREDENTIALS
12 PE_CERTIFICATEREQUIRED
13  
14 );
15  
16 our $VERSION = '2.0.12';
17  
18 extends 'Lemonldap::NG::Portal::Main::Auth';
19  
20 # PROPERTIES
21  
22 has SSLField => (
23 is => 'rw',
24 lazy => 1,
25 default => sub {
26 return ( $_[0]->{conf}->{SSLVar} || 'SSL_CLIENT_S_DN_Email' );
27 }
28 );
29  
30 has reWebIDWhitelist => ( is => 'rw' );
31  
32 # INITIALIZATION
33  
34 sub init {
35 my ($self) = @_;
36 my @hosts = split /\s+/, $self->{conf}->{webIDWhitelist};
37 unless (@hosts) {
38 $self->error(
39 'WebID white list is empty. Set it in manager, use * to accept all FOAF providers'
40 );
41 return 0;
42 }
43 my $re = Regexp::Assemble->new();
44 foreach my $h (@hosts) {
45 $self->logger->debug("Add $h in WebID whitelist");
46 $h = quotemeta($h);
47 $h =~ s/\\\*/\.\*\?/g;
48 $re->add($h);
49 }
50 my $reString = '^https?://' . $re->as_string . '(?:/.*|)$';
51 $self->reWebIDWhitelist(qr($reString));
52 return 1;
53 }
54  
55 # Read username in SSL environment variables, or return an error
56 # @return Lemonldap::NG::Portal constant
57 sub extractFormInfo {
58 my ( $self, $req ) = @_;
59  
60 # 1. Verify SSL exchange
61 unless ( $req->{SSL_CLIENT_S_DN} ) {
62 $self->userLogger->warn( 'No certificate found for ' . $req->address );
63 return PE_CERTIFICATEREQUIRED;
64 }
65  
66 # 2. Verify that certificate is WebID compliant
67 # NB: WebID URI is used as user field
68 eval {
69 $req->data->{_webid} =
70 Web::ID->new( certificate => $req->{SSL_CLIENT_CERT} );
71 $req->user( $req->data->{_webid}->uri->as_string );
72 };
73 return PE_BADCERTIFICATE if ( $@ or not( $req->user ) );
74  
75 # 3. Verify that FOAF host is in white list
76 return PE_BADPARTNER unless ( $req->user =~ $self->reWebIDWhitelist );
77  
78 # 4. Verify FOAF document
79 return PE_BADCREDENTIALS unless ( $req->data->{_webid}->valid() );
80 $req->data->{_webIdAuthDone}++;
81  
82 # 5. OK, access granted
83 return PE_OK;
84 }
85  
86 sub authenticate {
87 return PE_OK;
88 }
89  
90 sub setAuthSessionInfo {
91 my ( $self, $req ) = @_;
92 $req->{sessionInfo}->{authenticationLevel} = $self->conf->{webIDAuthnLevel};
93 return PE_OK;
94 }
95  
96 sub getDisplayType {
97 return "logo";
98 }
99  
100 1;