OxdPackages/OxdConfig.pm

filter: Statementstmt 11.1% 11 / 99 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 13.0% 3 / 23 Podpod n/a totaltotal 9.0% 14 / 155 CC 16 SCAR 26.2
CC
16
Cov
8%
json_read
56.0
setOpHost
6.0
setOxdHostPort
6.0
CRAP 13.8
« OxdPackages/OxdClientSocket.pm ↑ Summary 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 PHP
8 #
9 # This content is released under the MIT License (MIT)
10 #
11 # Copyright (c) 2015, 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 2.4.4
33 # @author Ourdesignz
34 # @author gaurav.chhabra6785@gmail.com
35 # @copyright Copyright (c) 2015, Gluu inc federation (https://gluu.org/)
36 # @license http://opensource.org/licenses/MIT MIT License
37 # @link https://gluu.org/
38 # @since Version 2.4.4
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  
59 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
60 0 my $class = shift;
61
62 0 my $self = {
63
64 # @static
65 # @var string $op_host Gluu server url, which need to connect
66 _op_host => shift,
67
68 # @static
69 # @var int $oxd_host_port Socket connection port
70 _oxd_host_port => shift,
71
72 # @static
73 # @var string $authorization_redirect_uri Site authorization redirect uri
74 _authorization_redirect_uri => shift,
75
76 # @static
77 # @var string $post_logout_redirect_uri Site logout redirect uri
78 _post_logout_redirect_uri => shift,
79
80 # @static
81 # @var array $scope For getting needed scopes from gluu-server
82 _scope => shift,
83
84 # @static
85 # @var string $application_type web or mobile
86 _application_type => shift,
87
88 # @static
89 # @var array $response_types OpenID Authentication response types
90 _response_types => shift,
91
92 # @static
93 # @var array $grant_types OpenID Token Request type
94 _grant_types => shift,
95
96 # @static
97 # @var array $acr_values Gluu login acr type, can be basic, duo, u2f, gplus and etc.
98 _acr_values => shift,
99 };
100
101 # Print all the values just for clarification.
102 #print "OP HOST is :". $self->{_op_host};
103 #print "<br>";
104 #print "OXD HOST PORT is :".$self->{_oxd_host_port};
105 0 our $oxdHostPort;
106 0 $oxdHostPort = 'package';
107
108 0 bless $self, $class;
109 0 $self->json_read;
110 0 return $self;
111 }
112  
113 0 ▶sub setOpHost {
Subroutine setOpHost: not called CC=2 SCAR=17.9
114 #my ( $self, $op_host,$oxd_host_port,$authorization_redirect_uri,$post_logout_redirect_uri,$scope,$application_type,$response_types,$grant_types,$acr_values ) = @_;
115 0 my ( $self, $op_host ) = @_;
116 0 ▶ $self->{_op_host} = $op_host if defined($op_host);
Branch: 1 branch
BranchTrueFalseTotal
if defined $op_host 0 0 0
117 0 return $self->{_op_host};
118 }
119  
120 0 ▶sub getOpHost {
Subroutine getOpHost: not called CC=1 SCAR=6.9
121 0 my( $self ) = @_;
122 0 return $self->{_op_host};
123 }
124  
125 0 ▶sub setOxdHostPort {
Subroutine setOxdHostPort: not called CC=2 SCAR=17.9
126 0 my ( $self, $oxd_host_port ) = @_;
127 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
128 0 return $self->{_oxd_host_port};
129 }
130  
131 0 ▶sub getOxdHostPort {
Subroutine getOxdHostPort: not called CC=1 SCAR=6.9
132 0 my( $self ) = @_;
133 0 return $self->{_oxd_host_port};
134 }
135  
136 0 ▶sub setAuthorizationRedirectUrl {
Subroutine setAuthorizationRedirectUrl: not called CC=2 SCAR=17.9
137 0 my ( $self, $authorization_redirect_uri ) = @_;
138 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
139 0 return $self->{_authorization_redirect_uri};
140 }
141  
142 0 ▶sub getAuthorizationRedirectUrl {
Subroutine getAuthorizationRedirectUrl: not called CC=1 SCAR=6.9
143 0 my( $self ) = @_;
144 0 return $self->{_authorization_redirect_uri};
145 }
146  
147 0 ▶sub setPostLogoutRedirectUrl {
Subroutine setPostLogoutRedirectUrl: not called CC=2 SCAR=17.9
148 0 my ( $self, $post_logout_redirect_uri ) = @_;
149 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
150 0 return $self->{_post_logout_redirect_uri};
151 }
152  
153 0 ▶sub getPostLogoutRedirectUrl {
Subroutine getPostLogoutRedirectUrl: not called CC=1 SCAR=6.9
154 0 my( $self ) = @_;
155 0 return $self->{_post_logout_redirect_uri};
156 }
157  
158  
159 0 ▶sub setScope {
Subroutine setScope: not called CC=2 SCAR=17.9
160 0 my ( $self, $scope ) = @_;
161 0 ▶ $self->{_scope} = $scope if defined($scope);
Branch: 1 branch
BranchTrueFalseTotal
if defined $scope 0 0 0
162 0 return $self->{_scope};
163 }
164  
165 0 ▶sub getScope {
Subroutine getScope: not called CC=1 SCAR=6.9
166 0 my( $self ) = @_;
167 0 return $self->{_scope};
168 }
169  
170 0 ▶sub setApplicationType {
Subroutine setApplicationType: not called CC=2 SCAR=17.9
171 0 my ( $self, $application_type ) = @_;
172 0 ▶ $self->{_application_type} = $application_type if defined($application_type);
Branch: 1 branch
BranchTrueFalseTotal
if defined $application_type 0 0 0
173 0 return $self->{_application_type};
174 }
175  
176 0 ▶sub getApplicationType {
Subroutine getApplicationType: not called CC=1 SCAR=6.9
177 0 my( $self ) = @_;
178 0 return $self->{_application_type};
179 }
180  
181 0 ▶sub setResponseType {
Subroutine setResponseType: not called CC=2 SCAR=17.9
182 0 my ( $self, $response_types ) = @_;
183 0 ▶ $self->{_response_types} = $response_types if defined($response_types);
Branch: 1 branch
BranchTrueFalseTotal
if defined $response_types 0 0 0
184 0 return $self->{_response_types};
185 }
186  
187 0 ▶sub getResponseType {
Subroutine getResponseType: not called CC=1 SCAR=6.9
188 0 my( $self ) = @_;
189 0 return $self->{_response_types};
190 }
191  
192 0 ▶sub setGrantTypes {
Subroutine setGrantTypes: not called CC=2 SCAR=17.9
193 0 my ( $self, $grant_types ) = @_;
194 0 ▶ $self->{_grant_types} = $grant_types if defined($grant_types);
Branch: 1 branch
BranchTrueFalseTotal
if defined $grant_types 0 0 0
195 0 return $self->{_grant_types};
196 }
197  
198 0 ▶sub getGrantTypes {
Subroutine getGrantTypes: not called CC=1 SCAR=6.9
199 0 my( $self ) = @_;
200 0 return $self->{_grant_types};
201 }
202  
203 0 ▶sub setAcrValues {
Subroutine setAcrValues: not called CC=2 SCAR=17.9
204 0 my ( $self, $acr_values ) = @_;
205 0 ▶ $self->{_acr_values} = $acr_values if defined($acr_values);
Branch: 1 branch
BranchTrueFalseTotal
if defined $acr_values 0 0 0
206 0 return $self->{_acr_values};
207 }
208  
209 0 ▶sub getAcrValues {
Subroutine getAcrValues: not called CC=1 SCAR=6.9
210 0 my( $self ) = @_;
211 0 return $self->{_acr_values};
212 }
213 0 ▶sub json_read{
Subroutine json_read: not called CC=7 SCAR=40.3
214
215 0 my ($self) = @_;
216 0 my $filename = 'oxd-settings.json';
217 #my $baseUrl = $self->{_base_url};
218 #print $baseUrl;
219 0 my $configOBJECT;
220 0 ▶ if (open (my $configJSON, $filename)){
Branch: 1 branch
BranchTrueFalseTotal
if (open my $configJSON, $filename) 0 0 0
221 0 local $/ = undef;
222 0 my $json = JSON::PP->new;
223 0 $configOBJECT = $json->decode(<$configJSON>);
224
225 0 ▶ if(!$configOBJECT->{authorization_redirect_uri}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($configOBJECT->{"authorization_redirect_uri"}) 0 0 0
226 0 my $defaultOxdSettingsJson = 'oxd-rp-settings-test.json';
227 0 ▶ if(open (my $configJSON, $defaultOxdSettingsJson)){
Branch: 1 branch
BranchTrueFalseTotal
if (open my $configJSON, $defaultOxdSettingsJson) 0 0 0
228 0 ▶ if(!my $configJSON){
Branch: 1 branch
BranchTrueFalseTotal
unless (my $configJSON) 0 0 0
229 #$error = error_get_last();
230 0 OxdClientSocket::log("oxd-configuration-test: ", 'Error problem with json data.');
231 0 OxdClientSocket::error_message("HTTP request failed. Error was: Testing");
232 }
233 0 $configOBJECT = $json->decode(<$configJSON>);
234 }
235 }
236
237 #$self->define_variables($configOBJECT);
238
239 0 my $OXD_HOST_PORT = $configOBJECT->{oxd_host_port};
240
241
242 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
243  
244 }else{
245 0 OxdClientSocket::error_message($OXD_HOST_PORT." is not a valid port for socket. Port must be integer and between from 0 to 65535.");
246 }
247 #print $data->{authorization_redirect_uri};
248 0 close($configJSON);
249 }
250 0 my $op_host = $configOBJECT->{op_host};
251 0 my $oxd_host_port = $configOBJECT->{oxd_host_port};
252 0 my $authorization_redirect_uri = $configOBJECT->{authorization_redirect_uri};
253 0 my $post_logout_redirect_uri = $configOBJECT->{post_logout_redirect_uri};
254 0 my $scope = $configOBJECT->{scope};
255 0 my $application_type = $configOBJECT->{application_type};
256 0 my $response_types = $configOBJECT->{response_types};
257 0 my $grant_types = $configOBJECT->{grant_types};
258 0 my $acr_values = $configOBJECT->{acr_values};
259
260 #$self->new( $op_host, $oxd_host_port );
261 0 $self->setOpHost( $op_host );
262 0 $self->setOxdHostPort( $oxd_host_port );
263 0 $self->setAuthorizationRedirectUrl( $authorization_redirect_uri );
264 0 $self->setPostLogoutRedirectUrl( $post_logout_redirect_uri );
265 0 $self->setScope( $scope );
266 0 $self->setApplicationType( $application_type );
267 0 $self->setResponseType( $response_types );
268 0 $self->setGrantTypes( $grant_types );
269 0 $self->setAcrValues( $acr_values );
270
271
272
273
274  
275
276
277 =pod use constant OXD_HOST_PORT => $configOBJECT->{oxd_host_port};
278 use constant AUTHORIZATION_REDIRECT_URL => $configOBJECT->{authorization_redirect_uri};
279 use constant POST_LOGOUT_REDIRECT_URL => $configOBJECT->{post_logout_redirect_uri};
280 use constant SCOPE => $configOBJECT->{scope};
281 use constant APPLICATION_TYPE => $configOBJECT->{application_type};
282 use constant RESPONSE_TYPES => $configOBJECT->{response_types};
283 use constant GRANT_TYPES => $configOBJECT->{grant_types};
284 use constant ACR_VALUES => $configOBJECT->{acr_values};
285 =cut
286 #return $configOBJECT;
287 }
288  
289 1 1; # this 1; is neccessary for our class to workk
« OxdPackages/OxdClientSocket.pm ↑ Summary OxdPackages/UpdateRegistration.pm »