« blib/lib/Lemonldap/NG/Manager/Api/Providers/SamlSp.pm
↑ Summary
blib/lib/Lemonldap/NG/Manager/Api/Menu/Cat.pm »
| 1 | package Lemonldap::NG::Manager::Api::Providers::CasApp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 28 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Lemonldap::NG::Manager::Api; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 28 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Lemonldap::NG::Manager::Conf::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 28 | extends 'Lemonldap::NG::Manager::Api::Common'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 12 | ▶ | sub getCasAppByConfKey { | ||||||||||||||||||||||||||
|
Subroutine
getCasAppByConfKey: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 12 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 12 | ▶ | my $confKey = $req->params('confKey') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | or return $self->sendError( $req, 'confKey is missing', 400 ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 12 | $self->logger->debug("[API] CAS App $confKey configuration requested"); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Get latest configuration | ||||||||||||||||||||||||||||
| 23 | 12 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 12 | my $casApp = $self->_getCasAppByConfKey( $conf, $confKey ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Return 404 if not found | ||||||||||||||||||||||||||||
| 28 | 12 | ▶ | return $self->sendError( $req, "CAS application '$confKey' not found", 404 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | unless ( defined $casApp ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | return $self->sendJSONresponse( $req, $casApp ); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | ▶ | sub findCasAppByConfKey { | ||||||||||||||||||||||||||
|
Subroutine
findCasAppByConfKey: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 6 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | my $pattern = ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | defined $req->params('uPattern') | ||||||||||||||||||||||||||||
| 39 | ? $req->params('uPattern') | ||||||||||||||||||||||||||||
| 40 | : ( defined $req->params('pattern') ? $req->params('pattern') : undef ) | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6 | ▶ | return $self->sendError( $req, 'Invalid input: pattern is missing', 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | unless ( defined $pattern ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6 | ▶ | unless ( $pattern = $self->_getRegexpFromPattern($pattern) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 2 | return $self->sendError( $req, 'Invalid input: pattern is invalid', | |||||||||||||||||||||||||||
| 48 | 400 ); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 52 | 4 | "[API] Find CAS Apps by confKey regexp $pattern requested"); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Get latest configuration | ||||||||||||||||||||||||||||
| 55 | 4 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | my @casApps = | ||||||||||||||||||||||||||||
| 58 | 8 | ▶ | map { $_ =~ $pattern ? $self->_getCasAppByConfKey( $conf, $_ ) : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 4 | keys %{ $conf->{casAppMetaDataOptions} }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | return $self->sendJSONresponse( $req, [@casApps] ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub findCasAppsByServiceUrl { | ||||||||||||||||||||||||||
|
Subroutine
findCasAppsByServiceUrl: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 2 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | my $serviceUrl = ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | defined $req->params('uServiceUrl') ? $req->params('uServiceUrl') | ||||||||||||||||||||||||||||
| 69 | : ( | ||||||||||||||||||||||||||||
| 70 | defined $req->params('serviceUrl') ? $req->params('serviceUrl') | ||||||||||||||||||||||||||||
| 71 | : undef | ||||||||||||||||||||||||||||
| 72 | ) | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return $self->sendError( $req, 'Invalid input: serviceUrl is missing', 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | unless ( defined $serviceUrl ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | $self->logger->debug( | |||||||||||||||||||||||||||
| 79 | "[API] Find CAS Apps by service URL $serviceUrl requested"); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Get latest configuration | ||||||||||||||||||||||||||||
| 82 | 2 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | my $casApp = $self->_getCasAppByServiceUrl( $conf, $serviceUrl ); | |||||||||||||||||||||||||||
| 85 | 2 | ▶ | return $self->sendError( $req, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | "CAS application with service '$serviceUrl' not found", 404 ) | ||||||||||||||||||||||||||||
| 87 | unless ( defined $casApp ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | return $self->sendJSONresponse( $req, $casApp ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | ▶ | sub addCasApp { | ||||||||||||||||||||||||||
|
Subroutine
addCasApp: called CC=11 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 5 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 94 | 5 | my $add = $req->jsonBodyToObj; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 5 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | unless ($add); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | return $self->sendError( $req, 'Invalid input: confKey is missing', 400 ) | ||||||||||||||||||||||||||||
| 100 | 5 | ▶ | unless ( defined $add->{confKey} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | return $self->sendError( $req, 'Invalid input: confKey is not a string', | ||||||||||||||||||||||||||||
| 103 | 400 ) | ||||||||||||||||||||||||||||
| 104 | 5 | ▶ | if ( ref $add->{confKey} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | return $self->sendError( $req, 'Invalid input: confKey is empty', 400 ) | ||||||||||||||||||||||||||||
| 107 | 5 | ▶ | unless ( $add->{confKey} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | return $self->sendError( $req, 'Invalid input: service is missing', 400 ) | ||||||||||||||||||||||||||||
| 110 | 5 | ▶ | unless ( defined $add->{options}->{service} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | return $self->sendError( $req, 'Invalid input: service must be an array', | ||||||||||||||||||||||||||||
| 113 | 400 ) | ||||||||||||||||||||||||||||
| 114 | 5 | ▶ | unless ( ref $add->{options}->{service} eq "ARRAY" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | $self->logger->debug( | |||||||||||||||||||||||||||
| 117 | "[API] Add CAS App with confKey $add->{confKey} requested"); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Get latest configuration | ||||||||||||||||||||||||||||
| 120 | 5 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | return $self->sendError( | ||||||||||||||||||||||||||||
| 123 | $req, | ||||||||||||||||||||||||||||
| 124 | "Invalid input: A CAS App with confKey $add->{confKey} already exists", | ||||||||||||||||||||||||||||
| 125 | 409 | ||||||||||||||||||||||||||||
| 126 | 5 | ▶ | ) if ( defined $self->_getCasAppByConfKey( $conf, $add->{confKey} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 4 | for my $serviceUrl ( @{ $add->{options}->{service} } ) { | |||||||||||||||||||||||||||
| 129 | 5 | my $res = $self->_getCasAppByServiceUrl( $conf, $serviceUrl ); | |||||||||||||||||||||||||||
| 130 | 5 | ▶ | if ( defined $res ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | return $self->sendError( | |||||||||||||||||||||||||||
| 132 | $req, | ||||||||||||||||||||||||||||
| 133 | "Invalid input: A CAS application with service URL $serviceUrl already exists", | ||||||||||||||||||||||||||||
| 134 | 409 | ||||||||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 3 | my $res = $self->_pushCasApp( $conf, $add->{confKey}, $add, 1 ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||
| 142 | 3 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | return $self->sendJSONresponse( | |||||||||||||||||||||||||||
| 145 | $req, | ||||||||||||||||||||||||||||
| 146 | { message => "Successful operation" }, | ||||||||||||||||||||||||||||
| 147 | code => 201 | ||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 4 | ▶ | sub updateCasApp { | ||||||||||||||||||||||||||
|
Subroutine
updateCasApp: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 153 | 4 | ▶ | my $confKey = $req->params('confKey') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | or return $self->sendError( $req, 'confKey is missing', 400 ); | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | my $update = $req->jsonBodyToObj; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | unless ($update); | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 4 | $self->logger->debug( | |||||||||||||||||||||||||||
| 162 | "[API] CAS App $confKey configuration update requested"); | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # Get latest configuration | ||||||||||||||||||||||||||||
| 165 | 4 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 4 | my $current = $self->_getCasAppByConfKey( $conf, $confKey ); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Return 404 if not found | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 4 | ▶ | return $self->sendError( $req, "CAS application '$confKey' not found", 404 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | unless ( defined $current ); | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # check if new clientID exists already | ||||||||||||||||||||||||||||
| 175 | 3 | my $res = $self->_isNewCasAppServiceUrlUnique( $conf, $confKey, $update ); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | return $self->sendError( $req, $res->{msg}, 409 ) | ||||||||||||||||||||||||||||
| 178 | 3 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 2 | $res = $self->_pushCasApp( $conf, $confKey, $update, 0 ); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||
| 183 | 2 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 1 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 4 | ▶ | sub replaceCasApp { | ||||||||||||||||||||||||||
|
Subroutine
replaceCasApp: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 190 | 4 | ▶ | my $confKey = $req->params('confKey') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | or return $self->sendError( $req, 'confKey is missing', 400 ); | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 4 | my $replace = $req->jsonBodyToObj; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 4 | ▶ | return $self->sendError( $req, "Invalid input: " . $req->error, 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | unless ($replace); | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 4 | $self->logger->debug( | |||||||||||||||||||||||||||
| 199 | "[API] CAS App $confKey configuration replace requested"); | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # Get latest configuration | ||||||||||||||||||||||||||||
| 202 | 4 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # Return 404 if not found | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 4 | ▶ | return $self->sendError( $req, "CAS application '$confKey' not found", 404 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | unless ( defined $self->_getCasAppByConfKey( $conf, $confKey ) ); | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # check if new clientID exists already | ||||||||||||||||||||||||||||
| 210 | 3 | my $res = $self->_isNewCasAppServiceUrlUnique( $conf, $confKey, $replace ); | |||||||||||||||||||||||||||
| 211 | return $self->sendError( $req, $res->{msg}, 409 ) | ||||||||||||||||||||||||||||
| 212 | 3 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 3 | $res = $self->_pushCasApp( $conf, $confKey, $replace, 1 ); | |||||||||||||||||||||||||||
| 215 | return $self->sendError( $req, $res->{msg}, 400 ) | ||||||||||||||||||||||||||||
| 216 | 3 | ▶ | unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 1 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 3 | ▶ | sub deleteCasApp { | ||||||||||||||||||||||||||
|
Subroutine
deleteCasApp: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 3 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 223 | 3 | ▶ | my $confKey = $req->params('confKey') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | or return $self->sendError( $req, 'confKey is missing', 400 ); | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 3 | $self->logger->debug( | |||||||||||||||||||||||||||
| 227 | "[API] CAS App $confKey configuration delete requested"); | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Get latest configuration | ||||||||||||||||||||||||||||
| 230 | 3 | my $conf = $self->_confAcc->getConf( { noCache => 1 } ); | |||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 3 | my $delete = $self->_getCasAppByConfKey( $conf, $confKey ); | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # Return 404 if not found | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 3 | ▶ | return $self->sendError( $req, "CAS application '$confKey' not found", 404 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | unless ( defined $delete ); | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 2 | delete $conf->{casAppMetaDataOptions}->{$confKey}; | |||||||||||||||||||||||||||
| 240 | 2 | delete $conf->{casAppMetaDataExportedVars}->{$confKey}; | |||||||||||||||||||||||||||
| 241 | 2 | delete $conf->{casAppMetaDataMacros}->{$confKey}; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Save configuration | ||||||||||||||||||||||||||||
| 244 | 2 | $self->_saveApplyConf($conf); | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 2 | return $self->sendJSONresponse( $req, undef, code => 204 ); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 41 | ▶ | sub _getCasAppByConfKey { | ||||||||||||||||||||||||||
|
Subroutine
_getCasAppByConfKey: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 250 | 41 | my ( $self, $conf, $confKey ) = @_; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | # Check if confKey is defined | ||||||||||||||||||||||||||||
| 253 | 41 | ▶ | return undef unless ( defined $conf->{casAppMetaDataOptions}->{$confKey} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | # Get exported vars | ||||||||||||||||||||||||||||
| 256 | 34 | my $exportedVars = $conf->{casAppMetaDataExportedVars}->{$confKey}; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # # Get extra claim | ||||||||||||||||||||||||||||
| 259 | # my $extraClaims = $conf->{casAppMetaDataOptionsExtraClaims}->{$confKey}; | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | # Get macros | ||||||||||||||||||||||||||||
| 262 | 34 | ▶ | my $macros = $conf->{casAppMetaDataMacros}->{$confKey} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{'casAppMetaDataMacros'}{$confKey} || {}
MC/DC0%0/1
$conf->{'casAppMetaDataMacros'}{$confKey} || {}
$conf->{'casAppMetaDataMacros'}{$confKey}
Truth table50%1/2
A
A= $conf->{'casAppMetaDataMacros'}{$confKey}
| |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | # Get options | ||||||||||||||||||||||||||||
| 265 | 34 | my $options = {}; | |||||||||||||||||||||||||||
| 266 | 34 | for | |||||||||||||||||||||||||||
| 267 | 34 | my $configOption ( keys %{ $conf->{casAppMetaDataOptions}->{$confKey} } ) | |||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||
| 269 | 89 | my $optionName = $self->_translateOptionConfToApi($configOption); | |||||||||||||||||||||||||||
| 270 | my $optionValue = $self->_translateValueConfToApi( $configOption, | ||||||||||||||||||||||||||||
| 271 | 89 | $conf->{casAppMetaDataOptions}->{$confKey}->{$configOption} ); | |||||||||||||||||||||||||||
| 272 | 89 | $options->{$optionName} = $optionValue; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | return { | ||||||||||||||||||||||||||||
| 276 | 34 | confKey => $confKey, | |||||||||||||||||||||||||||
| 277 | exportedVars => $exportedVars, | ||||||||||||||||||||||||||||
| 278 | macros => $macros, | ||||||||||||||||||||||||||||
| 279 | options => $options | ||||||||||||||||||||||||||||
| 280 | }; | ||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 9 | ▶ | sub _getCasAppByServiceUrl { | ||||||||||||||||||||||||||
|
Subroutine
_getCasAppByServiceUrl: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 284 | 9 | my ( $self, $conf, $serviceUrl ) = @_; | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 9 | my ($serviceHost) = $serviceUrl =~ m#^(https?://[^/]+)(?:/.*)?$#; | |||||||||||||||||||||||||||
| 287 | 9 | ▶ | return undef unless $serviceHost; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 8 | for my $confKey ( keys %{ $conf->{casAppMetaDataOptions} } ) { | |||||||||||||||||||||||||||
| 289 | 7 | for my $url ( | |||||||||||||||||||||||||||
| 290 | split( | ||||||||||||||||||||||||||||
| 291 | /\s+/, | ||||||||||||||||||||||||||||
| 292 | $conf->{casAppMetaDataOptions}->{$confKey} | ||||||||||||||||||||||||||||
| 293 | ->{casAppMetaDataOptionsService} | ||||||||||||||||||||||||||||
| 294 | ) | ||||||||||||||||||||||||||||
| 295 | ) | ||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||
| 297 | 8 | my ($curHost) = $url =~ m#^(https?://[^/]+)(?:/.*)?$#; | |||||||||||||||||||||||||||
| 298 | 8 | ▶ | if ( $serviceHost eq $curHost ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 2 | return $self->_getCasAppByConfKey( $conf, $confKey ); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 6 | return undef; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 6 | ▶ | sub _isNewCasAppServiceUrlUnique { | ||||||||||||||||||||||||||
|
Subroutine
_isNewCasAppServiceUrlUnique: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 308 | 6 | my ( $self, $conf, $confKey, $casApp ) = @_; | |||||||||||||||||||||||||||
| 309 | my $curServiceUrl = | ||||||||||||||||||||||||||||
| 310 | 6 | $self->_getCasAppByConfKey( $conf, $confKey )->{options}->{service}; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | # Check service paramater | ||||||||||||||||||||||||||||
| 313 | 6 | ▶ | unless ( ref $casApp->{options}->{service} eq "ARRAY" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | return { | ||||||||||||||||||||||||||||
| 315 | 1 | res => 'ko', | |||||||||||||||||||||||||||
| 316 | msg => "The parameter 'service' must be an array", | ||||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 5 | ▶ | my $newService = $casApp->{options}->{service} || []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$casApp->{'options'}{'service'} || []
MC/DC0%0/1
$casApp->{'options'}{'service'} || []
$casApp->{'options'}{'service'}
Truth table50%1/2
A
A= $casApp->{'options'}{'service'}
| |||||||||||||||||||||||||||||
| 321 | 5 | for my $newServiceUrl (@$newService) { | |||||||||||||||||||||||||||
| 322 | 5 | ▶ | if ( $newServiceUrl ne '' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$newServiceUrl ne "" and not grep(/^$newServiceUrl$/, @$curServiceUrl)
MC/DC50%1/2
$newServiceUrl ne "" and not grep(/^$newServiceUrl$/, @$curServiceUrl)
$newServiceUrl ne ""
not grep(/^$newServiceUrl$/, @$curServiceUrl)
Truth table66%2/3
A and not(B)
A= $newServiceUrl ne ""B= not grep(/^$newServiceUrl$/, @$curServiceUrl)
| |||||||||||||||||||||||||||||
| 323 | && !grep( /^$newServiceUrl$/, @$curServiceUrl ) ) | ||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | return { | ||||||||||||||||||||||||||||
| 326 | 2 | ▶ | res => 'ko', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | msg => | ||||||||||||||||||||||||||||
| 328 | "A CAS application with service URL '$newServiceUrl' already exists" | ||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | if ( | ||||||||||||||||||||||||||||
| 331 | defined $self->_getCasAppByServiceUrl( $conf, $newServiceUrl ) | ||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 5 | return { res => 'ok' }; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 8 | ▶ | sub _pushCasApp { | ||||||||||||||||||||||||||
|
Subroutine
_pushCasApp: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||
| 340 | 8 | my ( $self, $conf, $confKey, $push, $replace ) = @_; | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 8 | my $translatedOptions = {}; | |||||||||||||||||||||||||||
| 343 | 8 | ▶ | if ($replace) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 6 | $conf->{casAppMetaDataOptions}->{$confKey} = {}; | |||||||||||||||||||||||||||
| 345 | 6 | $conf->{casAppMetaDataExportedVars}->{$confKey} = {}; | |||||||||||||||||||||||||||
| 346 | 6 | $conf->{casAppMetaDataMacros}->{$confKey} = {}; | |||||||||||||||||||||||||||
| 347 | 6 | $translatedOptions = $self->_getDefaultValues('casAppMetaDataNodes'); | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 8 | ▶ | if ( defined $push->{options} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 8 | foreach ( keys %{ $push->{options} } ) { | |||||||||||||||||||||||||||
| 353 | 20 | my $optionName = $self->_translateOptionApiToConf( $_, 'casApp' ); | |||||||||||||||||||||||||||
| 354 | my $optionValue = | ||||||||||||||||||||||||||||
| 355 | $self->_translateValueApiToConf( $optionName, | ||||||||||||||||||||||||||||
| 356 | 20 | $push->{options}->{$_} ); | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 20 | $translatedOptions->{$optionName} = $optionValue; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 8 | my $res = $self->_hasAllowedAttributes( $translatedOptions, | |||||||||||||||||||||||||||
| 362 | 'casAppMetaDataNode' ); | ||||||||||||||||||||||||||||
| 363 | 8 | ▶ | return $res unless ( $res->{res} eq 'ok' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 5 | $self->_merge_hash( $conf, 'casAppMetaDataOptions', $confKey, | |||||||||||||||||||||||||||
| 366 | $translatedOptions ); | ||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 5 | ▶ | if ( defined $push->{exportedVars} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 5 | ▶ | if ( $self->_isSimpleKeyValueHash( $push->{exportedVars} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | $self->_merge_hash( | ||||||||||||||||||||||||||||
| 372 | $conf, 'casAppMetaDataExportedVars', | ||||||||||||||||||||||||||||
| 373 | $confKey, $push->{exportedVars} | ||||||||||||||||||||||||||||
| 374 | 5 | ); | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | else { | ||||||||||||||||||||||||||||
| 377 | return { | ||||||||||||||||||||||||||||
| 378 | 0 | res => 'ko', | |||||||||||||||||||||||||||
| 379 | msg => | ||||||||||||||||||||||||||||
| 380 | "Invalid input: exportedVars is not a hash object with \"key\":\"value\" attributes" | ||||||||||||||||||||||||||||
| 381 | }; | ||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 5 | ▶ | if ( defined $push->{macros} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 5 | ▶ | if ( $self->_isSimpleKeyValueHash( $push->{macros} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | $self->_merge_hash( $conf, 'casAppMetaDataMacros', $confKey, | ||||||||||||||||||||||||||||
| 388 | 5 | $push->{macros} ); | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | else { | ||||||||||||||||||||||||||||
| 391 | return { | ||||||||||||||||||||||||||||
| 392 | 0 | res => 'ko', | |||||||||||||||||||||||||||
| 393 | msg => | ||||||||||||||||||||||||||||
| 394 | "Invalid input: macros is not a hash object with \"key\":\"value\" attributes" | ||||||||||||||||||||||||||||
| 395 | }; | ||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | # Test new configuration | ||||||||||||||||||||||||||||
| 400 | 5 | my $parser = Lemonldap::NG::Manager::Conf::Parser->new( { | |||||||||||||||||||||||||||
| 401 | refConf => $self->_confAcc->getConf( { noCache => 1 } ), | ||||||||||||||||||||||||||||
| 402 | newConf => $conf, | ||||||||||||||||||||||||||||
| 403 | req => {}, | ||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | ); | ||||||||||||||||||||||||||||
| 406 | 5 | ▶ | unless ( $parser->testNewConf( $self->p ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | return { | ||||||||||||||||||||||||||||
| 408 | res => 'ko', | ||||||||||||||||||||||||||||
| 409 | code => 400, | ||||||||||||||||||||||||||||
| 410 | msg => "Configuration error: " | ||||||||||||||||||||||||||||
| 411 | 1 | . join( ". ", map { $_->{message} } @{ $parser->errors } ), | |||||||||||||||||||||||||||
| 412 | }; | ||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | # Save configuration | ||||||||||||||||||||||||||||
| 416 | 4 | $self->_saveApplyConf($conf); | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 4 | return { res => 'ok' }; | |||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 28 | 1; | |||||||||||||||||||||||||||