File Coverage

blib/lib/OxdPackages/OxdConfig.pm
Criterion Covered Total %
statement 12 151 7.9
branch 0 46 0.0
condition 0 3 0.0
subroutine 4 38 10.5
pod n/a
total 16 238 6.7


line stmt bran cond sub pod time code
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) 2017, 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.0
33             # @author Ourdesignz, Sobhan Panda
34             # @author gaurav.chhabra6785@gmail.com, sobhan@centroxy.com
35             # @copyright Copyright (c) 2017, 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.0
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     1   9 use vars qw($VERSION);
  1         4  
  1         65  
55             $VERSION = '0.01';
56 1     1   8 use strict;
  1         2  
  1         28  
57 1     1   7 use warnings;
  1         2  
  1         64  
58 1     1   606 use JSON::PP;
  1         20041  
  1         2349  
59            
60             sub new{
61 0     0     my $class = shift;
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             };
117            
118             # Print all the values just for clarification.
119             #print "OP HOST is :". $self->{_op_host};
120             #print "
";
121             #print "OXD HOST PORT is :".$self->{_oxd_host_port};
122 0           our $oxdHostPort;
123 0           $oxdHostPort = 'package';
124            
125 0           bless $self, $class;
126 0           $self->json_read;
127 0           return $self;
128             }
129            
130             sub setOpHost {
131             #my ( $self, $op_host,$oxd_host_port,$authorization_redirect_uri,$post_logout_redirect_uri,$scope,$application_type,$response_types,$grant_types,$acr_values ) = @_;
132 0     0     my ( $self, $op_host ) = @_;
133 0 0         $self->{_op_host} = $op_host if defined($op_host);
134 0           return $self->{_op_host};
135             }
136            
137             sub getOpHost {
138 0     0     my( $self ) = @_;
139 0           return $self->{_op_host};
140             }
141            
142             sub setOxdHostPort {
143 0     0     my ( $self, $oxd_host_port ) = @_;
144 0 0         $self->{_oxd_host_port} = $oxd_host_port if defined($oxd_host_port);
145 0           return $self->{_oxd_host_port};
146             }
147            
148             sub getOxdHostPort {
149 0     0     my( $self ) = @_;
150 0           return $self->{_oxd_host_port};
151             }
152            
153             sub setAuthorizationRedirectUrl {
154 0     0     my ( $self, $authorization_redirect_uri ) = @_;
155 0 0         $self->{_authorization_redirect_uri} = $authorization_redirect_uri if defined($authorization_redirect_uri);
156 0           return $self->{_authorization_redirect_uri};
157             }
158            
159             sub getAuthorizationRedirectUrl {
160 0     0     my( $self ) = @_;
161 0           return $self->{_authorization_redirect_uri};
162             }
163            
164             sub setPostLogoutRedirectUrl {
165 0     0     my ( $self, $post_logout_redirect_uri ) = @_;
166 0 0         $self->{_post_logout_redirect_uri} = $post_logout_redirect_uri if defined($post_logout_redirect_uri);
167 0           return $self->{_post_logout_redirect_uri};
168             }
169            
170             sub getPostLogoutRedirectUrl {
171 0     0     my( $self ) = @_;
172 0           return $self->{_post_logout_redirect_uri};
173             }
174            
175            
176             sub setClientFrontChannelLogoutUris {
177 0     0     my ( $self, $client_frontchannel_logout_uris ) = @_;
178 0 0         $self->{_client_frontchannel_logout_uris} = $client_frontchannel_logout_uris if defined($client_frontchannel_logout_uris);
179 0           return $self->{_client_frontchannel_logout_uris};
180             }
181            
182             sub getClientFrontChannelLogoutUris {
183 0     0     my( $self ) = @_;
184 0           return $self->{_client_frontchannel_logout_uris};
185             }
186            
187            
188             sub setScope {
189 0     0     my ( $self, $scope ) = @_;
190 0 0         $self->{_scope} = $scope if defined($scope);
191 0           return $self->{_scope};
192             }
193            
194             sub getScope {
195 0     0     my( $self ) = @_;
196 0           return $self->{_scope};
197             }
198            
199             sub setApplicationType {
200 0     0     my ( $self, $application_type ) = @_;
201 0 0         $self->{_application_type} = $application_type if defined($application_type);
202 0           return $self->{_application_type};
203             }
204            
205             sub getApplicationType {
206 0     0     my( $self ) = @_;
207 0           return $self->{_application_type};
208             }
209            
210             sub setResponseType {
211 0     0     my ( $self, $response_types ) = @_;
212 0 0         $self->{_response_types} = $response_types if defined($response_types);
213 0           return $self->{_response_types};
214             }
215            
216             sub getResponseType {
217 0     0     my( $self ) = @_;
218 0           return $self->{_response_types};
219             }
220            
221             sub setGrantTypes {
222 0     0     my ( $self, $grant_types ) = @_;
223 0 0         $self->{_grant_types} = $grant_types if defined($grant_types);
224 0           return $self->{_grant_types};
225             }
226            
227             sub getGrantTypes {
228 0     0     my( $self ) = @_;
229 0           return $self->{_grant_types};
230             }
231            
232             sub setAcrValues {
233 0     0     my ( $self, $acr_values ) = @_;
234 0 0         $self->{_acr_values} = $acr_values if defined($acr_values);
235 0           return $self->{_acr_values};
236             }
237            
238             sub getAcrValues {
239 0     0     my( $self ) = @_;
240 0           return $self->{_acr_values};
241             }
242            
243             sub setRestServiceUrl {
244 0     0     my ( $self, $rest_service_url ) = @_;
245 0 0         $self->{_rest_service_url} = $rest_service_url if defined($rest_service_url);
246 0           return $self->{_rest_service_url};
247             }
248            
249             sub getRestServiceUrl {
250 0     0     my( $self ) = @_;
251 0           return $self->{_rest_service_url};
252             }
253            
254             sub setConnectionType {
255 0     0     my ( $self, $connection_type ) = @_;
256 0 0         $self->{_connection_type} = $connection_type if defined($connection_type);
257 0           return $self->{_connection_type};
258             }
259            
260             sub getConnectionType {
261 0     0     my( $self ) = @_;
262 0           return $self->{_connection_type};
263             }
264            
265            
266             sub setOxdId {
267 0     0     my ( $self, $oxd_id ) = @_;
268 0 0         $self->{_oxd_id} = $oxd_id if defined($oxd_id);
269 0           return $self->{_oxd_id};
270             }
271            
272             sub getOxdId {
273 0     0     my( $self ) = @_;
274 0           return $self->{_oxd_id};
275             }
276            
277            
278             sub setClientName {
279 0     0     my ( $self, $clientName ) = @_;
280 0 0         $self->{_client_name} = $clientName if defined($clientName);
281 0           return $self->{_client_name};
282             }
283            
284             sub getClientName {
285 0     0     my( $self ) = @_;
286 0           return $self->{_client_name};
287             }
288            
289            
290             sub setClientId {
291 0     0     my ( $self, $client_id ) = @_;
292 0 0         $self->{_client_id} = $client_id if defined($client_id);
293 0           return $self->{_client_id};
294             }
295            
296             sub getClientId {
297 0     0     my( $self ) = @_;
298 0           return $self->{_client_id};
299             }
300            
301            
302             sub setClientSecret {
303 0     0     my ( $self, $client_secret ) = @_;
304 0 0         $self->{_client_secret} = $client_secret if defined($client_secret);
305 0           return $self->{_client_secret};
306             }
307            
308             sub getClientSecret {
309 0     0     my( $self ) = @_;
310 0           return $self->{_client_secret};
311             }
312            
313            
314            
315             sub json_read{
316            
317 0     0     my ($self) = @_;
318 0           my $filename = 'oxd-settings.json';
319             #my $baseUrl = $self->{_base_url};
320             #print $baseUrl;
321 0           my $configOBJECT;
322 0 0         if (open (my $configJSON, $filename)){
323 0           local $/ = undef;
324 0           my $json = JSON::PP->new;
325 0           $configOBJECT = $json->decode(<$configJSON>);
326            
327 0 0         if(!$configOBJECT->{authorization_redirect_uri}){
328 0           my $defaultOxdSettingsJson = 'oxd-rp-settings-test.json';
329 0 0         if(open (my $configJSON, $defaultOxdSettingsJson)){
330 0 0         if(!my $configJSON){
331             #$error = error_get_last();
332 0           OxdClientSocket::log("oxd-configuration-test: ", 'Error problem with json data.');
333 0           OxdClientSocket::error_message("HTTP request failed. Error was: Testing");
334             }
335 0           $configOBJECT = $json->decode(<$configJSON>);
336             }
337             }
338            
339             #$self->define_variables($configOBJECT);
340            
341 0           my $OXD_HOST_PORT = $configOBJECT->{oxd_host_port};
342            
343            
344 0 0 0       if($OXD_HOST_PORT>=0 && $OXD_HOST_PORT<=65535){
345            
346             }else{
347 0           OxdClientSocket::error_message($OXD_HOST_PORT." is not a valid port for socket. Port must be integer and between from 0 to 65535.");
348             }
349             #print $data->{authorization_redirect_uri};
350 0           close($configJSON);
351             }
352 0           my $op_host = $configOBJECT->{op_host};
353 0           my $oxd_host_port = $configOBJECT->{oxd_host_port};
354 0           my $authorization_redirect_uri = $configOBJECT->{authorization_redirect_uri};
355 0           my $post_logout_redirect_uri = $configOBJECT->{post_logout_redirect_uri};
356 0           my $client_frontchannel_logout_uris = $configOBJECT->{client_frontchannel_logout_uris};
357 0           my $scope = $configOBJECT->{scope};
358 0           my $application_type = $configOBJECT->{application_type};
359 0           my $response_types = $configOBJECT->{response_types};
360 0           my $grant_types = $configOBJECT->{grant_types};
361 0           my $acr_values = $configOBJECT->{acr_values};
362 0           my $rest_service_url = $configOBJECT->{rest_service_url};
363 0           my $connection_type = $configOBJECT->{connection_type};
364 0           my $oxd_id = $configOBJECT->{oxd_id};
365 0           my $clientName = $configOBJECT->{client_name};
366            
367             #$self->new( $op_host, $oxd_host_port );
368 0           $self->setOpHost( $op_host );
369 0           $self->setOxdHostPort( $oxd_host_port );
370 0           $self->setAuthorizationRedirectUrl( $authorization_redirect_uri );
371 0           $self->setPostLogoutRedirectUrl( $post_logout_redirect_uri );
372 0           $self->setClientFrontChannelLogoutUris( $client_frontchannel_logout_uris );
373 0           $self->setScope( $scope );
374 0           $self->setApplicationType( $application_type );
375 0           $self->setResponseType( $response_types );
376 0           $self->setGrantTypes( $grant_types );
377 0           $self->setAcrValues( $acr_values );
378 0           $self->setRestServiceUrl( $rest_service_url );
379 0           $self->setConnectionType( $connection_type );
380 0           $self->setOxdId( $oxd_id );
381 0           $self->setClientName( $clientName );
382            
383 0 0         if($configOBJECT->{client_id}){
384 0           my $client_id = $configOBJECT->{client_id};
385 0           $self->setClientId( $client_id );
386             }
387 0 0         if($configOBJECT->{client_secret}){
388 0           my $client_secret = $configOBJECT->{client_secret};
389 0           $self->setClientSecret( $client_secret );
390             }
391            
392            
393            
394            
395            
396             =pod use constant OXD_HOST_PORT => $configOBJECT->{oxd_host_port};
397             use constant AUTHORIZATION_REDIRECT_URL => $configOBJECT->{authorization_redirect_uri};
398             use constant POST_LOGOUT_REDIRECT_URL => $configOBJECT->{post_logout_redirect_uri};
399             use constant SCOPE => $configOBJECT->{scope};
400             use constant APPLICATION_TYPE => $configOBJECT->{application_type};
401             use constant RESPONSE_TYPES => $configOBJECT->{response_types};
402             use constant GRANT_TYPES => $configOBJECT->{grant_types};
403             use constant ACR_VALUES => $configOBJECT->{acr_values};
404             =cut
405             #return $configOBJECT;
406             }
407            
408             1; # this 1; is neccessary for our class to workk