blib/lib/OxdPackages/OxdConfig.pm

filter: Statementstmt 8.3% 14 / 167 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 9.5% 4 / 42 Podpod n/a totaltotal 6.8% 18 / 264 CC 27 SCAR 27.5
CC
27
Cov
6%
json_read
90.0
setOpHost
6.0
setOxdHostPort
6.0
CRAP 15.7
↑ Summary blib/lib/OxdPackages/UpdateRegistration.pm »
1 #!/usr/bin/perl
2 # OxdConfig.pm, a number as an object
3
4 #
5 # Gluu-oxd-library
6 #
7 # An open source application library for Perl
8 #
9 # This content is released under the MIT License (MIT)
10 #
11 # Copyright (c) 2018, Gluu inc, USA, Austin
12 #
13 # Permission is hereby granted, free of charge, to any person obtaining a copy
14 # of this software and associated documentation files (the "Software"), to deal
15 # in the Software without restriction, including without limitation the rights
16 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 # copies of the Software, and to permit persons to whom the Software is
18 # furnished to do so, subject to the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included in
21 # all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 # THE SOFTWARE.
30 #
31 # @package Gluu-oxd-library
32 # @version 3.1.2
33 # @author Ourdesignz, Sobhan Panda
34 # @author gaurav.chhabra6785@gmail.com, sobhan@centroxy.com
35 # @copyright Copyright (c) 2018, Gluu inc federation (https://gluu.org/)
36 # @license http://opensource.org/licenses/MIT MIT License
37 # @link https://gluu.org/
38 # @since Version 3.1.2
39 # @filesource
40 #/
41
42 #
43 # Oxd RP config
44 #
45 # Class OxdConfig, setting all configuration
46 #
47 # @package Gluu-oxd-library
48 # @subpackage Libraries
49 # @category Base class for all protocols
50 # @author Ourdesignz
51 # @author gaurav.chhabra6785@gmail.com
52 #/
53 package OxdConfig;
54 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 $VERSION = '0.01';
56 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
59
60 sub new{
61 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
62
63 0 my $self = {
64
65 # @static
66 # @var string $op_host Gluu server url, which need to connect
67 _op_host => shift,
68
69 # @static
70 # @var int $oxd_host_port Socket connection port
71 _oxd_host_port => shift,
72
73 # @static
74 # @var string $authorization_redirect_uri Site authorization redirect uri
75 _authorization_redirect_uri => shift,
76
77 # @static
78 # @var string $post_logout_redirect_uri Site logout redirect uri
79 _post_logout_redirect_uri => shift,
80
81 # @static
82 # @var string $client_frontchannel_logout_uris Client logout uri
83 _client_frontchannel_logout_uris => shift,
84 # @static
85 # @var array $scope For getting needed scopes from gluu-server
86 _scope => shift,
87
88 # @static
89 # @var string $application_type web or mobile
90 _application_type => shift,
91
92 # @static
93 # @var array $response_types OpenID Authentication response types
94 _response_types => shift,
95
96 # @static
97 # @var array $grant_types OpenID Token Request type
98 _grant_types => shift,
99
100 # @static
101 # @var array $acr_values Gluu login acr type, can be basic, duo, u2f, gplus and etc.
102 _acr_values => shift,
103
104 # @static
105 # @var array $rest_service_url Gluu rest service url
106 _rest_service_url => shift,
107
108 # @static
109 # @var array $connection_type Connection type, can be Socket or http.
110 _connection_type => shift,
111
112 _oxd_id => shift,
113 _client_name => shift,
114 _client_id => shift,
115 _client_secret => shift,
116 _claims_redirect_uri => shift,
117 _resource_end_point => shift
118 };
119
120 # Print all the values just for clarification.
121 #print "OP HOST is :". $self->{_op_host};
122 #print "<br>";
123 #print "OXD HOST PORT is :".$self->{_oxd_host_port};
124 0 our $oxdHostPort;
125 0 $oxdHostPort = 'package';
126
127 0 bless $self, $class;
128 0 $self->json_read;
129 0 return $self;
130 }
131
132 sub setOpHost {
133 #my ( $self, $op_host,$oxd_host_port,$authorization_redirect_uri,$post_logout_redirect_uri,$scope,$application_type,$response_types,$grant_types,$acr_values ) = @_;
134 0 ▶ my ( $self, $op_host ) = @_;
Subroutine setOpHost: not called CC=2 SCAR=17.9
135 0 ▶ $self->{_op_host} = $op_host if defined($op_host);
Branch: 1 branch
BranchTrueFalseTotal
if defined $op_host 0 0 0
136 0 return $self->{_op_host};
137 }
138
139 sub getOpHost {
140 0 ▶ my( $self ) = @_;
Subroutine getOpHost: not called CC=1 SCAR=6.9
141 0 return $self->{_op_host};
142 }
143
144 sub setOxdHostPort {
145 0 ▶ my ( $self, $oxd_host_port ) = @_;
Subroutine setOxdHostPort: not called CC=2 SCAR=17.9
146 0 ▶ $self->{_oxd_host_port} = $oxd_host_port if defined($oxd_host_port);
Branch: 1 branch
BranchTrueFalseTotal
if defined $oxd_host_port 0 0 0
147 0 return $self->{_oxd_host_port};
148 }
149
150 sub getOxdHostPort {
151 0 ▶ my( $self ) = @_;
Subroutine getOxdHostPort: not called CC=1 SCAR=6.9
152 0 return $self->{_oxd_host_port};
153 }
154
155 sub setAuthorizationRedirectUrl {
156 0 ▶ my ( $self, $authorization_redirect_uri ) = @_;
Subroutine setAuthorizationRedirectUrl: not called CC=2 SCAR=17.9
157 0 ▶ $self->{_authorization_redirect_uri} = $authorization_redirect_uri if defined($authorization_redirect_uri);
Branch: 1 branch
BranchTrueFalseTotal
if defined $authorization_redirect_uri 0 0 0
158 0 return $self->{_authorization_redirect_uri};
159 }
160
161 sub getAuthorizationRedirectUrl {
162 0 ▶ my( $self ) = @_;
Subroutine getAuthorizationRedirectUrl: not called CC=1 SCAR=6.9
163 0 return $self->{_authorization_redirect_uri};
164 }
165
166 sub setPostLogoutRedirectUrl {
167 0 ▶ my ( $self, $post_logout_redirect_uri ) = @_;
Subroutine setPostLogoutRedirectUrl: not called CC=2 SCAR=17.9
168 0 ▶ $self->{_post_logout_redirect_uri} = $post_logout_redirect_uri if defined($post_logout_redirect_uri);
Branch: 1 branch
BranchTrueFalseTotal
if defined $post_logout_redirect_uri 0 0 0
169 0 return $self->{_post_logout_redirect_uri};
170 }
171
172 sub getPostLogoutRedirectUrl {
173 0 ▶ my( $self ) = @_;
Subroutine getPostLogoutRedirectUrl: not called CC=1 SCAR=6.9
174 0 return $self->{_post_logout_redirect_uri};
175 }
176
177
178 sub setClientFrontChannelLogoutUris {
179 0 ▶ my ( $self, $client_frontchannel_logout_uris ) = @_;
Subroutine setClientFrontChannelLogoutUris: not called CC=2 SCAR=17.9
180 0 ▶ $self->{_client_frontchannel_logout_uris} = $client_frontchannel_logout_uris if defined($client_frontchannel_logout_uris);
Branch: 1 branch
BranchTrueFalseTotal
if defined $client_frontchannel_logout_uris 0 0 0
181 0 return $self->{_client_frontchannel_logout_uris};
182 }
183
184 sub getClientFrontChannelLogoutUris {
185 0 ▶ my( $self ) = @_;
Subroutine getClientFrontChannelLogoutUris: not called CC=1 SCAR=6.9
186 0 return $self->{_client_frontchannel_logout_uris};
187 }
188
189
190 sub setScope {
191 0 ▶ my ( $self, $scope ) = @_;
Subroutine setScope: not called CC=2 SCAR=17.9
192 0 ▶ $self->{_scope} = $scope if defined($scope);
Branch: 1 branch
BranchTrueFalseTotal
if defined $scope 0 0 0
193 0 return $self->{_scope};
194 }
195
196 sub getScope {
197 0 ▶ my( $self ) = @_;
Subroutine getScope: not called CC=1 SCAR=6.9
198 0 return $self->{_scope};
199 }
200
201 sub setApplicationType {
202 0 ▶ my ( $self, $application_type ) = @_;
Subroutine setApplicationType: not called CC=2 SCAR=17.9
203 0 ▶ $self->{_application_type} = $application_type if defined($application_type);
Branch: 1 branch
BranchTrueFalseTotal
if defined $application_type 0 0 0
204 0 return $self->{_application_type};
205 }
206
207 sub getApplicationType {
208 0 ▶ my( $self ) = @_;
Subroutine getApplicationType: not called CC=1 SCAR=6.9
209 0 return $self->{_application_type};
210 }
211
212 sub setResponseType {
213 0 ▶ my ( $self, $response_types ) = @_;
Subroutine setResponseType: not called CC=2 SCAR=17.9
214 0 ▶ $self->{_response_types} = $response_types if defined($response_types);
Branch: 1 branch
BranchTrueFalseTotal
if defined $response_types 0 0 0
215 0 return $self->{_response_types};
216 }
217
218 sub getResponseType {
219 0 ▶ my( $self ) = @_;
Subroutine getResponseType: not called CC=1 SCAR=6.9
220 0 return $self->{_response_types};
221 }
222
223 sub setGrantTypes {
224 0 ▶ my ( $self, $grant_types ) = @_;
Subroutine setGrantTypes: not called CC=2 SCAR=17.9
225 0 ▶ $self->{_grant_types} = $grant_types if defined($grant_types);
Branch: 1 branch
BranchTrueFalseTotal
if defined $grant_types 0 0 0
226 0 return $self->{_grant_types};
227 }
228
229 sub getGrantTypes {
230 0 ▶ my( $self ) = @_;
Subroutine getGrantTypes: not called CC=1 SCAR=6.9
231 0 return $self->{_grant_types};
232 }
233
234 sub setAcrValues {
235 0 ▶ my ( $self, $acr_values ) = @_;
Subroutine setAcrValues: not called CC=2 SCAR=17.9
236 0 ▶ $self->{_acr_values} = $acr_values if defined($acr_values);
Branch: 1 branch
BranchTrueFalseTotal
if defined $acr_values 0 0 0
237 0 return $self->{_acr_values};
238 }
239
240 sub getAcrValues {
241 0 ▶ my( $self ) = @_;
Subroutine getAcrValues: not called CC=1 SCAR=6.9
242 0 return $self->{_acr_values};
243 }
244
245 sub setRestServiceUrl {
246 0 ▶ my ( $self, $rest_service_url ) = @_;
Subroutine setRestServiceUrl: not called CC=2 SCAR=17.9
247 0 ▶ $self->{_rest_service_url} = $rest_service_url if defined($rest_service_url);
Branch: 1 branch
BranchTrueFalseTotal
if defined $rest_service_url 0 0 0
248 0 return $self->{_rest_service_url};
249 }
250
251 sub getRestServiceUrl {
252 0 ▶ my( $self ) = @_;
Subroutine getRestServiceUrl: not called CC=1 SCAR=6.9
253 0 return $self->{_rest_service_url};
254 }
255
256 sub setConnectionType {
257 0 ▶ my ( $self, $connection_type ) = @_;
Subroutine setConnectionType: not called CC=2 SCAR=17.9
258 0 ▶ $self->{_connection_type} = $connection_type if defined($connection_type);
Branch: 1 branch
BranchTrueFalseTotal
if defined $connection_type 0 0 0
259 0 return $self->{_connection_type};
260 }
261
262 sub getConnectionType {
263 0 ▶ my( $self ) = @_;
Subroutine getConnectionType: not called CC=1 SCAR=6.9
264 0 return $self->{_connection_type};
265 }
266
267
268 sub setOxdId {
269 0 ▶ my ( $self, $oxd_id ) = @_;
Subroutine setOxdId: not called CC=2 SCAR=17.9
270 0 ▶ $self->{_oxd_id} = $oxd_id if defined($oxd_id);
Branch: 1 branch
BranchTrueFalseTotal
if defined $oxd_id 0 0 0
271 0 return $self->{_oxd_id};
272 }
273
274 sub getOxdId {
275 0 ▶ my( $self ) = @_;
Subroutine getOxdId: not called CC=1 SCAR=6.9
276 0 return $self->{_oxd_id};
277 }
278
279
280 sub setClientName {
281 0 ▶ my ( $self, $clientName ) = @_;
Subroutine setClientName: not called CC=2 SCAR=17.9
282 0 ▶ $self->{_client_name} = $clientName if defined($clientName);
Branch: 1 branch
BranchTrueFalseTotal
if defined $clientName 0 0 0
283 0 return $self->{_client_name};
284 }
285
286 sub getClientName {
287 0 ▶ my( $self ) = @_;
Subroutine getClientName: not called CC=1 SCAR=6.9
288 0 return $self->{_client_name};
289 }
290
291
292 sub setClientId {
293 0 ▶ my ( $self, $client_id ) = @_;
Subroutine setClientId: not called CC=2 SCAR=17.9
294 0 ▶ $self->{_client_id} = $client_id if defined($client_id);
Branch: 1 branch
BranchTrueFalseTotal
if defined $client_id 0 0 0
295 0 return $self->{_client_id};
296 }
297
298 sub getClientId {
299 0 ▶ my( $self ) = @_;
Subroutine getClientId: not called CC=1 SCAR=6.9
300 0 return $self->{_client_id};
301 }
302
303
304 sub setClientSecret {
305 0 ▶ my ( $self, $client_secret ) = @_;
Subroutine setClientSecret: not called CC=2 SCAR=17.9
306 0 ▶ $self->{_client_secret} = $client_secret if defined($client_secret);
Branch: 1 branch
BranchTrueFalseTotal
if defined $client_secret 0 0 0
307 0 return $self->{_client_secret};
308 }
309
310 sub getClientSecret {
311 0 ▶ my( $self ) = @_;
Subroutine getClientSecret: not called CC=1 SCAR=6.9
312 0 return $self->{_client_secret};
313 }
314
315
316 sub setClaimsRedirectUri {
317 0 ▶ my ( $self, $claims_redirect_uri ) = @_;
Subroutine setClaimsRedirectUri: not called CC=2 SCAR=17.9
318 0 ▶ $self->{_claims_redirect_uri} = $claims_redirect_uri if defined($claims_redirect_uri);
Branch: 1 branch
BranchTrueFalseTotal
if defined $claims_redirect_uri 0 0 0
319 0 return $self->{_claims_redirect_uri};
320 }
321
322 sub getClaimsRedirectUri {
323 0 ▶ my( $self ) = @_;
Subroutine getClaimsRedirectUri: not called CC=1 SCAR=6.9
324 0 return $self->{_claims_redirect_uri};
325 }
326
327
328 sub setResourceEndPoint {
329 0 ▶ my ( $self, $resource_end_point ) = @_;
Subroutine setResourceEndPoint: not called CC=2 SCAR=17.9
330 0 ▶ $self->{_resource_end_point} = $resource_end_point if defined($resource_end_point);
Branch: 1 branch
BranchTrueFalseTotal
if defined $resource_end_point 0 0 0
331 0 return $self->{_resource_end_point};
332 }
333
334 sub getResourceEndPoint {
335 0 ▶ my( $self ) = @_;
Subroutine getResourceEndPoint: not called CC=1 SCAR=6.9
336 0 return $self->{_resource_end_point};
337 }
338
339 sub json_read{
340
341 0 ▶ my ($self) = @_;
Subroutine json_read: not called CC=9 SCAR=45.0
342 0 my $filename = 'oxd-settings.json';
343 #my $baseUrl = $self->{_base_url};
344 #print $baseUrl;
345 0 my $configOBJECT;
346 0 ▶ if (open (my $configJSON, $filename)){
Branch: 1 branch
BranchTrueFalseTotal
if (open my $configJSON, $filename) 0 0 0
347 0 local $/ = undef;
348 0 my $json = JSON::PP->new;
349 0 $configOBJECT = $json->decode(<$configJSON>);
350
351 0 ▶ if(!$configOBJECT->{authorization_redirect_uri}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($configOBJECT->{"authorization_redirect_uri"}) 0 0 0
352 0 my $defaultOxdSettingsJson = 'oxd-rp-settings-test.json';
353 0 ▶ if(open (my $configJSON, $defaultOxdSettingsJson)){
Branch: 1 branch
BranchTrueFalseTotal
if (open my $configJSON, $defaultOxdSettingsJson) 0 0 0
354 0 ▶ if(!my $configJSON){
Branch: 1 branch
BranchTrueFalseTotal
unless (my $configJSON) 0 0 0
355 #$error = error_get_last();
356 0 OxdClientSocket::log("oxd-configuration-test: ", 'Error problem with json data.');
357 0 OxdClientSocket::error_message("HTTP request failed. Error was: Testing");
358 }
359 0 $configOBJECT = $json->decode(<$configJSON>);
360 }
361 }
362
363 #$self->define_variables($configOBJECT);
364
365 0 my $OXD_HOST_PORT = $configOBJECT->{oxd_host_port};
366
367
368 0 ▶ if($OXD_HOST_PORT>=0 && $OXD_HOST_PORT<=65535){
Branch: 1 branch
BranchTrueFalseTotal
if ($OXD_HOST_PORT >= 0 and $OXD_HOST_PORT <= 65535) { } 0 0 0
Condition0%0/3
$OXD_HOST_PORT >= 0 and $OXD_HOST_PORT <= 65535
!ll&&!rl&&r
000
MC/DC0%0/2
$OXD_HOST_PORT >= 0 and $OXD_HOST_PORT <= 65535
$OXD_HOST_PORT >= 0 $OXD_HOST_PORT <= 65535
Truth table0%0/3
A and B
A= $OXD_HOST_PORT >= 0B= $OXD_HOST_PORT <= 65535
ABresult
0X0
100
111
369
370 }else{
371 0 OxdClientSocket::error_message($OXD_HOST_PORT." is not a valid port for socket. Port must be integer and between from 0 to 65535.");
372 }
373 #print $data->{authorization_redirect_uri};
374 0 close($configJSON);
375 }
376 0 my $op_host = $configOBJECT->{op_host};
377 0 my $oxd_host_port = $configOBJECT->{oxd_host_port};
378 0 my $authorization_redirect_uri = $configOBJECT->{authorization_redirect_uri};
379 0 my $post_logout_redirect_uri = $configOBJECT->{post_logout_redirect_uri};
380 0 my $client_frontchannel_logout_uris = $configOBJECT->{client_frontchannel_logout_uris};
381 0 my $scope = $configOBJECT->{scope};
382 0 my $application_type = $configOBJECT->{application_type};
383 0 my $response_types = $configOBJECT->{response_types};
384 0 my $grant_types = $configOBJECT->{grant_types};
385 0 my $acr_values = $configOBJECT->{acr_values};
386 0 my $rest_service_url = $configOBJECT->{rest_service_url};
387 0 my $connection_type = $configOBJECT->{connection_type};
388 0 my $oxd_id = $configOBJECT->{oxd_id};
389 0 my $clientName = $configOBJECT->{client_name};
390 0 my $claims_redirect_uri = $configOBJECT->{claims_redirect_uri};
391 0 my $resource_end_point = $configOBJECT->{resource_end_point};
392
393 #$self->new( $op_host, $oxd_host_port );
394 0 $self->setOpHost( $op_host );
395 0 $self->setOxdHostPort( $oxd_host_port );
396 0 $self->setAuthorizationRedirectUrl( $authorization_redirect_uri );
397 0 $self->setPostLogoutRedirectUrl( $post_logout_redirect_uri );
398 0 $self->setClientFrontChannelLogoutUris( $client_frontchannel_logout_uris );
399 0 $self->setScope( $scope );
400 0 $self->setApplicationType( $application_type );
401 0 $self->setResponseType( $response_types );
402 0 $self->setGrantTypes( $grant_types );
403 0 $self->setAcrValues( $acr_values );
404 0 $self->setRestServiceUrl( $rest_service_url );
405 0 $self->setConnectionType( $connection_type );
406 0 $self->setOxdId( $oxd_id );
407 0 $self->setClientName( $clientName );
408 0 $self->setClaimsRedirectUri( $claims_redirect_uri );
409 0 $self->setResourceEndPoint( $resource_end_point );
410
411 0 ▶ if($configOBJECT->{client_id}){
Branch: 1 branch
BranchTrueFalseTotal
if ($configOBJECT->{"client_id"}) 0 0 0
412 0 my $client_id = $configOBJECT->{client_id};
413 0 $self->setClientId( $client_id );
414 }
415 0 ▶ if($configOBJECT->{client_secret}){
Branch: 1 branch
BranchTrueFalseTotal
if ($configOBJECT->{"client_secret"}) 0 0 0
416 0 my $client_secret = $configOBJECT->{client_secret};
417 0 $self->setClientSecret( $client_secret );
418 }
419
420
421
422
423
424 =pod use constant OXD_HOST_PORT => $configOBJECT->{oxd_host_port};
425 use constant AUTHORIZATION_REDIRECT_URL => $configOBJECT->{authorization_redirect_uri};
426 use constant POST_LOGOUT_REDIRECT_URL => $configOBJECT->{post_logout_redirect_uri};
427 use constant SCOPE => $configOBJECT->{scope};
428 use constant APPLICATION_TYPE => $configOBJECT->{application_type};
429 use constant RESPONSE_TYPES => $configOBJECT->{response_types};
430 use constant GRANT_TYPES => $configOBJECT->{grant_types};
431 use constant ACR_VALUES => $configOBJECT->{acr_values};
432 =cut
433 #return $configOBJECT;
434 }
435
436 1 1; # this 1; is neccessary for our class to workk
↑ Summary blib/lib/OxdPackages/UpdateRegistration.pm »