OpenInteract2/Auth.pm

filter: Statementstmt 18.5% 25 / 135 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 42.8% 6 / 14 Podpod 20.0% 1 / 5 totaltotal 12.0% 32 / 265 CC 47 SCAR 45.5
CC
47
Cov
11%
_check_login_required
240.0
run_custom_handler
90.0
new
72.0
CRAP 94.8
« OpenInteract2/Action.pm ↑ Summary OpenInteract2/Observer.pm »
1 package OpenInteract2::Auth;
2  
3 # $Id: Auth.pm,v 1.22 2005/03/17 14:57:57 sjn Exp $
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Log::Log4perl qw( get_logger );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 $OpenInteract2::Auth::VERSION = sprintf("%d.%02d", q$Revision: 1.22 $ =~ /(\d+)\.(\d+)/);
13  
14 2 my @FIELDS = qw( user groups );
15 2 __PACKAGE__->mk_accessors( @FIELDS );
16  
17 2 my ( $AUTH_USER_CLASS, $AUTH_GROUP_CLASS, $AUTH_ADMIN_CLASS );
18 2 my ( $USE_CUSTOM, $CUSTOM_CLASS, $CUSTOM_METHOD, $CUSTOM_FAIL_METHOD );
19  
20 2 my ( $log );
21  
22 0 ▶sub new {
Subroutine new: not called CC=8 SCAR=42.8
Pod documented
23 0 my ( $class, $params ) = @_;
24 0 ▶ unless ( $AUTH_USER_CLASS and $AUTH_GROUP_CLASS and $AUTH_ADMIN_CLASS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($AUTH_USER_CLASS and $AUTH_GROUP_CLASS and $AUTH_ADMIN_CLASS) 0 0 0
Condition0%0/6
$AUTH_USER_CLASS and $AUTH_GROUP_CLASS and $AUTH_ADMIN_CLASS
!ll&&!rl&&r
000
$AUTH_USER_CLASS and $AUTH_GROUP_CLASS
!ll&&!rl&&r
000
MC/DC0%0/3
$AUTH_USER_CLASS and $AUTH_GROUP_CLASS and $AUTH_ADMIN_CLASS
$AUTH_USER_CLASS $AUTH_GROUP_CLASS $AUTH_ADMIN_CLASS
Truth table0%0/4
A and B and C
A= $AUTH_USER_CLASSB= $AUTH_GROUP_CLASSC= $AUTH_ADMIN_CLASS
ABCresult
0XX0
10X0
1100
1111
25 0 $class->_include_impl_classes;
26 }
27 0 my $self = bless( {}, $class );
28 0 ▶ $self->user( $params->{user} ) if ( $params->{user} );
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"user"} 0 0 0
29 0 ▶ $self->groups( $params->{groups} ) if ( $params->{groups} );
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"groups"} 0 0 0
30 0 ▶ $self->is_logged_in( 'yes' ) if ( $params->{is_logged_in} eq 'yes' );
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"is_logged_in"} eq "yes" 0 0 0
31 0 ▶ $self->is_admin( 'yes' ) if ( $params->{is_admin} eq 'yes' );
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"is_admin"} eq "yes" 0 0 0
32 0 return $self;
33 }
34  
35 0 ▶sub is_admin {
Subroutine is_admin: not called CC=3 SCAR=24.8
Pod undocumented
36 0 my ( $self, $is ) = @_;
37 0 ▶ if ( $is ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is) 0 0 0
38 0 ▶ if ( $is eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is eq 'yes') { } 0 0 0
39 0 $self->{is_admin} = $is;
40 }
41 else {
42 0 $self->{is_admin} = undef;
43 }
44 }
45 0 return $self->{is_admin};
46 }
47  
48 0 ▶sub is_logged_in {
Subroutine is_logged_in: not called CC=3 SCAR=24.8
Pod undocumented
49 0 my ( $self, $is ) = @_;
50 0 ▶ if ( $is ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is) 0 0 0
51 0 ▶ if ( $is eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is eq 'yes') { } 0 0 0
52 0 $self->{is_logged_in} = $is;
53 }
54 else {
55 0 $self->{is_logged_in} = undef;
56 }
57 }
58 0 return $self->{is_logged_in};
59 }
60  
61 0 ▶sub login {
Subroutine login: not called CC=7 SCAR=40.3
Pod undocumented
62 0 my ( $self ) = @_;
63 0 ▶ $log ||= get_logger( LOG_AUTH );
Condition0%0/3
$log ||= get_logger("OI2.AUTH")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.AUTH")
$log get_logger("OI2.AUTH")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.AUTH")
ABresult
1X1
011
000
64 0 my $request = CTX->request;
65  
66 0 my ( $is_logged_in );
67  
68 0 ▶ if ( $self->user ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->user) { } 0 0 0
69 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("User object passed in with constructor, no ", "need to get user manually.") 0 0 0
70 $log->info( "User object passed in with constructor, no ",
71 "need to get user manually." );
72 0 $self->is_logged_in( 'yes' );
73 }
74 else {
75 0 $AUTH_USER_CLASS->get_user( $self );
76 }
77  
78 # TODO: Throw exception here?
79  
80 0 ▶ unless ( $self->user ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->user) 0 0 0
81 0 $log->error( "No user returned from '$AUTH_USER_CLASS'; this is a ",
82 "serious error with the authentication class since ",
83 "it should always return a user object" );
84 0 return;
85 }
86 0 $request->auth_user( $self->user );
87 0 $request->auth_is_logged_in( $self->is_logged_in );
88  
89 # Now that we have the user created we can create the theme...
90  
91 0 $request->create_theme;
92  
93 # ...and load the languages
94  
95 0 $request->assign_languages;
96  
97 0 ▶ unless ( ref $self->groups eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->groups eq "ARRAY") 0 0 0
98 0 $AUTH_GROUP_CLASS->get_groups( $self );
99 }
100 0 ▶ return unless ( ref $self->groups eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->groups eq "ARRAY" 0 0 0
101 0 $request->auth_group( $self->groups );
102  
103 0 $AUTH_ADMIN_CLASS->is_admin( $self );
104 0 $request->auth_is_admin( $self->is_admin );
105  
106 0 $self->_check_login_required;
107  
108 0 $self->run_custom_handler;
109 0 return $self;
110 }
111  
112 0 ▶sub _check_login_required {
Subroutine _check_login_required: not called CC=15 SCAR=54.8
113 0 my ( $self ) = @_;
114 0 my $login_info = CTX->lookup_login_config;
115 0 ▶ return unless ( $login_info->{required} and ! $self->is_logged_in );
Branch: 1 branch
BranchTrueFalseTotal
unless $login_info->{"required"} and not $self->is_logged_in 0 0 0
Condition0%0/3
$login_info->{"required"} and not $self->is_logged_in
!ll&&!rl&&r
000
MC/DC0%0/2
$login_info->{"required"} and not $self->is_logged_in
$login_info->{"required"} not $self->is_logged_in
Truth table0%0/3
A and not(B)
A= $login_info->{"required"}B= not $self->is_logged_in
ABresult
0X0
100
111
116 0 ▶ $log ||= get_logger( LOG_AUTH );
Condition0%0/3
$log ||= get_logger("OI2.AUTH")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.AUTH")
$log get_logger("OI2.AUTH")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.AUTH")
ABresult
1X1
011
000
117 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Logins are required and user is not logged in; ", "checking to see if URL is okay for display") 0 0 0
118 $log->info( "Logins are required and user is not logged in; ",
119 "checking to see if URL is okay for display" );
120 0 ▶ if ( my $skip_urls = $login_info->{required_skip} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $skip_urls = $login_info->{"required_skip"}) 0 0 0
121 my @all_skip_urls = ( ref $skip_urls eq 'ARRAY' )
122 0 ▶ ? @{ $skip_urls } : ( $skip_urls );
Branch: 1 branch
BranchTrueFalseTotal
ref $skip_urls eq 'ARRAY' ? : 0 0 0
123 0 my $requested_url = CTX->request->url_relative;
124 0 foreach my $url_pat ( @all_skip_urls ) {
125 0 ▶ next unless ( $url_pat );
Branch: 1 branch
BranchTrueFalseTotal
unless $url_pat 0 0 0
126 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Checking URL against pattern '${url_pat}'") 0 0 0
127 $log->debug( "Checking URL against pattern '$url_pat'" );
128 0 ▶ if ( $requested_url =~ /$url_pat/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($requested_url =~ /$url_pat/) 0 0 0
129 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("URL matches, not modifying request URL") 0 0 0
130 $log->debug( "URL matches, not modifying request URL" );
131 0 return;
132 }
133 $log->is_debug &&
134 0 ▶ $log->debug( "URL doesn't match" );
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("URL doesn't match") 0 0 0
135 }
136 }
137 0 my $required_url = $login_info->{required_url};
138 0 ▶ if ( $required_url ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($required_url) { } 0 0 0
139 my $url_path =
140 0 OpenInteract2::URL->create( $login_info->{required_url} );
141 0 ▶ $log->is_info &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_info and $log->info("Assigning new request URL of '${url_path}' ", "since user not logged in and logins are ", "required (specified in server ", "configuration under 'login.required')") 0 0 0
142 $log->info( "Assigning new request URL of '$url_path' ",
143 "since user not logged in and logins are ",
144 "required (specified in server ",
145 "configuration under 'login.required')" );
146 0 CTX->request->assign_request_url( $url_path );
147 }
148 else {
149 0 $log->error( "You have 'login.required' enabled so I'm ensuring ",
150 "that all users have a login, but you don't have ",
151 "'login.required_url' set to a URL where I should ",
152 "send them. Ignoring login requirement setting..." );
153 }
154 }
155  
156 0 ▶sub run_custom_handler {
Subroutine run_custom_handler: not called CC=9 SCAR=45.0
Pod undocumented
157 0 my ( $self ) = @_;
158 0 ▶ $log ||= get_logger( LOG_AUTH );
Condition0%0/3
$log ||= get_logger("OI2.AUTH")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.AUTH")
$log get_logger("OI2.AUTH")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.AUTH")
ABresult
1X1
011
000
159 0 ▶ unless ( $USE_CUSTOM ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($USE_CUSTOM) 0 0 0
160 0 $USE_CUSTOM = $self->_include_custom_class;
161 }
162 0 ▶ return if ( $USE_CUSTOM eq 'no' );
Branch: 1 branch
BranchTrueFalseTotal
if $USE_CUSTOM eq "no" 0 0 0
163 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Custom login handler/method being used: ", "'${CUSTOM_CLASS}' '${CUSTOM_METHOD}'") 0 0 0
164 $log->debug( "Custom login handler/method being used: ",
165 "'$CUSTOM_CLASS' '$CUSTOM_METHOD'" );
166 0 eval {
167 0 $CUSTOM_CLASS->$CUSTOM_METHOD( $self );
168 };
169 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
170 0 $log->error( "Custom login handler died with: $@" );
171 0 ▶ if ( $CUSTOM_FAIL_METHOD ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CUSTOM_FAIL_METHOD) 0 0 0
172 0 ▶ $log->is_debug &&
Branch: 1 branch
BranchTrueFalseTotal
$log->is_debug and $log->debug("Custom login handler failure method: ", "'${CUSTOM_CLASS}' '${CUSTOM_FAIL_METHOD}'") 0 0 0
173 $log->debug( "Custom login handler failure method: ",
174 "'$CUSTOM_CLASS' '$CUSTOM_FAIL_METHOD'" );
175 0 eval {
176 0 $CUSTOM_CLASS->$CUSTOM_FAIL_METHOD( $self );
177  
178 };
179 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
180 0 $log->error( "Custom login handler failure method ",
181 "died with: $@" );
182 }
183 }
184 }
185 }
186  
187 0 ▶sub _include_impl_classes {
Subroutine _include_impl_classes: not called CC=4 SCAR=30.0
188 0 my ( $class ) = @_;
189 0 my $login_config = CTX->lookup_login_config;
190 0 $AUTH_USER_CLASS = $login_config->{auth_user_class};
191 0 eval "require $AUTH_USER_CLASS";
192 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
193 0 oi_error "Failed to require user auth class '$AUTH_USER_CLASS'";
194 }
195 0 $AUTH_GROUP_CLASS = $login_config->{auth_group_class};
196 0 eval "require $AUTH_GROUP_CLASS";
197 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
198 0 oi_error "Failed to require group auth class '$AUTH_GROUP_CLASS'";
199 }
200 0 $AUTH_ADMIN_CLASS = $login_config->{auth_admin_class};
201 0 eval "require $AUTH_ADMIN_CLASS";
202 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
203 0 oi_error "Failed to require admin auth class '$AUTH_ADMIN_CLASS'";
204 }
205 }
206  
207 0 ▶sub _include_custom_class {
Subroutine _include_custom_class: not called CC=5 SCAR=34.0
208 0 my ( $class ) = @_;
209 0 ▶ $log ||= get_logger( LOG_AUTH );
Condition0%0/3
$log ||= get_logger("OI2.AUTH")
l!l&&r!l&&!r
000
MC/DC0%0/2
$log ||= get_logger("OI2.AUTH")
$log get_logger("OI2.AUTH")
Truth table0%0/3
A ||= B
A= $logB= get_logger("OI2.AUTH")
ABresult
1X1
011
000
210 0 my $login_config = CTX->lookup_login_config;
211 0 $CUSTOM_CLASS = $login_config->{custom_handler};
212 0 ▶ unless ( $CUSTOM_CLASS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CUSTOM_CLASS) 0 0 0
213 0 return 'no';
214 }
215 0 eval "require $CUSTOM_CLASS";
216 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
217 0 $log->error( "Tried to use custom login handler '$CUSTOM_CLASS'",
218 "but requiring the class failed: $@" );
219 0 return 'no';
220 }
221 $CUSTOM_METHOD = $login_config->{custom_method}
222 0 ▶ || 'handler';
Condition0%0/2
$login_config->{'custom_method'} || 'handler'
l!l
00
MC/DC0%0/1
$login_config->{'custom_method'} || 'handler'
$login_config->{'custom_method'}
Truth table0%0/2
A
A= $login_config->{'custom_method'}
Aresult
11
00
223 0 $CUSTOM_FAIL_METHOD = $login_config->{custom_fail_method};
224 0 return 'yes';
225 }
226  
227 2 1;
228  
229 __END__
« OpenInteract2/Action.pm ↑ Summary OpenInteract2/Observer.pm »