line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
# OxdClient.pm, a number as an object |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Attribute::Abstract; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package OxdClient; # This is the "Class" |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
454
|
use OxdPackages::OxdClientSocket; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(OxdClientSocket); # inherits from OxdClient |
13
|
|
|
|
|
|
|
# makes all attributes available |
14
|
|
|
|
|
|
|
use lib './modules'; |
15
|
|
|
|
|
|
|
use Attribute::Handlers; |
16
|
|
|
|
|
|
|
use strict; |
17
|
|
|
|
|
|
|
use warnings; |
18
|
|
|
|
|
|
|
use JSON::PP; |
19
|
|
|
|
|
|
|
use OxdPackages::OxdConfig; |
20
|
|
|
|
|
|
|
use Data::Dumper qw(Dumper); |
21
|
|
|
|
|
|
|
use utf8; |
22
|
|
|
|
|
|
|
use Encode; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
|
|
|
|
|
|
my $class = shift; |
27
|
|
|
|
|
|
|
my $self = { |
28
|
|
|
|
|
|
|
# @var string $command Extend class protocol command name, for sending oxd-server |
29
|
|
|
|
|
|
|
_command=>shift, |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# @var string $params Extends class sending parameters to oxd-server |
32
|
|
|
|
|
|
|
_params => [], |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# @var string $data Response data from oxd-server |
35
|
|
|
|
|
|
|
_data => [], |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# @var string $response_json Response data from oxd-server in format json |
38
|
|
|
|
|
|
|
_response_json=>shift, |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# @var object $response_object Response data from oxd-server in format object |
41
|
|
|
|
|
|
|
_response_object=>shift, |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# @var string $response_status Response status from oxd-server |
44
|
|
|
|
|
|
|
_response_status=>shift, |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# @var array $response_data Response data from oxd-server in format array |
47
|
|
|
|
|
|
|
_response_data => [], |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
# Print all the values just for clarification. |
52
|
|
|
|
|
|
|
#print "First Name is $self->{_firstName}\n"; |
53
|
|
|
|
|
|
|
bless $self, $class; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# send function sends the command to the oxd server. |
59
|
|
|
|
|
|
|
# Args: |
60
|
|
|
|
|
|
|
# command (dict) - Dict representation of the JSON command string |
61
|
|
|
|
|
|
|
# @return void |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
sub request{ |
64
|
|
|
|
|
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# @var array $command_types Protocols commands name |
67
|
|
|
|
|
|
|
my @command_types = ("get_authorization_url", |
68
|
|
|
|
|
|
|
"update_site_registration", |
69
|
|
|
|
|
|
|
"get_tokens_by_code", |
70
|
|
|
|
|
|
|
"get_user_info", |
71
|
|
|
|
|
|
|
"register_site", |
72
|
|
|
|
|
|
|
"get_logout_uri", |
73
|
|
|
|
|
|
|
"get_authorization_code", |
74
|
|
|
|
|
|
|
"uma_rs_protect", |
75
|
|
|
|
|
|
|
"uma_rs_check_access", |
76
|
|
|
|
|
|
|
"uma_rp_get_rpt", |
77
|
|
|
|
|
|
|
"uma_rp_authorize_rpt", |
78
|
|
|
|
|
|
|
"uma_rp_get_gat"); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->setCommand(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $exist = 'false'; |
85
|
|
|
|
|
|
|
for (my $i=0; $i <= scalar @command_types; $i++) { |
86
|
|
|
|
|
|
|
if ($command_types[$i] eq $self->getCommand()) { |
87
|
|
|
|
|
|
|
my $exist = 'true'; |
88
|
|
|
|
|
|
|
last; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if (!$exist) { |
93
|
|
|
|
|
|
|
$self->log('Command: ' . $self->getCommand() . ' is not exist!','Exiting process.'); |
94
|
|
|
|
|
|
|
$self->error_message('Command: ' . $self->getCommand() . ' is not exist!'); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$self->setParams(); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $json_array = $self->getData(); |
101
|
|
|
|
|
|
|
my $json = JSON::PP->new; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $jsondata = $json->encode($json_array); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if(!$self->is_JSON($jsondata)){ |
107
|
|
|
|
|
|
|
$self->log("Sending parameters must be JSON.",'Exiting process.'); |
108
|
|
|
|
|
|
|
$self->error_message('Sending parameters must be JSON.'); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $lenght = length $jsondata; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if($lenght<=0){ |
114
|
|
|
|
|
|
|
$self->log("Length must be more than zero.",'Exiting process.'); |
115
|
|
|
|
|
|
|
$self->error_message("Length must be more than zero."); |
116
|
|
|
|
|
|
|
}else{ |
117
|
|
|
|
|
|
|
$lenght = $lenght <= 999 ? "0" . $lenght : $lenght; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $lenght_jsondata = encode('UTF-8', $lenght . $jsondata); |
121
|
|
|
|
|
|
|
my $response_json = $self->oxd_socket_request($lenght_jsondata); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $char_count = substr($response_json, 0, 4); |
124
|
|
|
|
|
|
|
$response_json =~ s/$char_count//g; |
125
|
|
|
|
|
|
|
$self->{_response_json} = $response_json if defined($response_json); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
if ( $response_json) { |
128
|
|
|
|
|
|
|
my $object = JSON::PP->new->utf8->decode($response_json); |
129
|
|
|
|
|
|
|
#print $object->{data}->{oxd_id}; |
130
|
|
|
|
|
|
|
if ($object->{status} eq 'error') { |
131
|
|
|
|
|
|
|
$self->error_message($object->{data}->{error} . ' : ' . $object->{data}->{error_description}); |
132
|
|
|
|
|
|
|
} elsif ($object->{status} eq 'ok') { |
133
|
|
|
|
|
|
|
$self->setResponseObject( $object ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} else { |
136
|
|
|
|
|
|
|
print "I am here"; |
137
|
|
|
|
|
|
|
$self->log("Response is empty...",'Exiting process.'); |
138
|
|
|
|
|
|
|
$self->error_message('Response is empty...'); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Response status |
144
|
|
|
|
|
|
|
# @return string, OK on success, error on failure |
145
|
|
|
|
|
|
|
sub getResponseStatus |
146
|
|
|
|
|
|
|
{ |
147
|
|
|
|
|
|
|
my ($self) = @_; |
148
|
|
|
|
|
|
|
return $self->{_response_status}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Setting response status |
153
|
|
|
|
|
|
|
# @return void |
154
|
|
|
|
|
|
|
sub setResponseStatus |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
my ( $self) = @_; |
157
|
|
|
|
|
|
|
$self->{_response_status} = $self->getResponseObject()->{status}; |
158
|
|
|
|
|
|
|
return $self->{_response_status}; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# If data is not empty it is returning response data from oxd-server in format array. |
163
|
|
|
|
|
|
|
# If data empty or error , you have problem with parameter or protocol. |
164
|
|
|
|
|
|
|
# @return array |
165
|
|
|
|
|
|
|
sub getResponseData{ |
166
|
|
|
|
|
|
|
my ($self) = @_; |
167
|
|
|
|
|
|
|
if (!$self->getResponseObject()) { |
168
|
|
|
|
|
|
|
$self->{_response_data} = 'Data is empty'; |
169
|
|
|
|
|
|
|
$self->error_message($self->{_response_data}); |
170
|
|
|
|
|
|
|
} else { |
171
|
|
|
|
|
|
|
$self->{_response_data} = $self->getResponseObject()->{data}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
return $self->{_response_data}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Data which need to send oxd server. |
177
|
|
|
|
|
|
|
# @return array |
178
|
|
|
|
|
|
|
sub getData{ |
179
|
|
|
|
|
|
|
my ($self) = @_; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $data = { |
182
|
|
|
|
|
|
|
"command" => $self->getCommand(), |
183
|
|
|
|
|
|
|
"params" => $self->getParams(), |
184
|
|
|
|
|
|
|
}; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#my @data = ('command' => $self->getCommand(), 'params' => $self->getParams()); |
187
|
|
|
|
|
|
|
return $data; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Protocol name for request. |
192
|
|
|
|
|
|
|
# @return string |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub getCommand{ |
195
|
|
|
|
|
|
|
my ($self) = @_; |
196
|
|
|
|
|
|
|
return $self->{_command}; |
197
|
|
|
|
|
|
|
#return 'register_site'; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# Setting protocol name for request. |
202
|
|
|
|
|
|
|
# @return void |
203
|
|
|
|
|
|
|
#sub setCommand : Abstract; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# If response data is not empty it is returning response data from oxd-server in format object. |
206
|
|
|
|
|
|
|
# If response data empty or error , you have problem with parameter or protocol. |
207
|
|
|
|
|
|
|
# |
208
|
|
|
|
|
|
|
# @return object |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub setResponseObject{ |
211
|
|
|
|
|
|
|
my ( $self, $response_object ) = @_; |
212
|
|
|
|
|
|
|
$self->{_response_object} = $response_object if defined($response_object); |
213
|
|
|
|
|
|
|
return $self->{_response_object}; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# If response data is not empty it is returning response data from oxd-server in format object. |
218
|
|
|
|
|
|
|
# If response data empty or error , you have problem with parameter or protocol. |
219
|
|
|
|
|
|
|
# |
220
|
|
|
|
|
|
|
# @return object |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub getResponseObject{ |
223
|
|
|
|
|
|
|
my ($self) = @_; |
224
|
|
|
|
|
|
|
return $self->{_response_object}; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# If response data is not empty it is returning response data from oxd-server in format json. |
229
|
|
|
|
|
|
|
# If response data empty or error , you have problem with parameter or protocol. |
230
|
|
|
|
|
|
|
# @return string |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub getResponseJSON{ |
233
|
|
|
|
|
|
|
my ($self) = @_; |
234
|
|
|
|
|
|
|
return $self->{_response_json}; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Setting parameters for request. |
239
|
|
|
|
|
|
|
# @return void |
240
|
|
|
|
|
|
|
#sub setParams : Abstract; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# Parameters for request. |
244
|
|
|
|
|
|
|
# @return array |
245
|
|
|
|
|
|
|
sub getParams{ |
246
|
|
|
|
|
|
|
my ($self) = @_; |
247
|
|
|
|
|
|
|
return $self->{_params}; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# Checking format string. |
252
|
|
|
|
|
|
|
# @param string $string |
253
|
|
|
|
|
|
|
# @return bool |
254
|
|
|
|
|
|
|
sub is_JSON{ |
255
|
|
|
|
|
|
|
# Get passed arguments |
256
|
|
|
|
|
|
|
my($self,$jsondata) = @_; |
257
|
|
|
|
|
|
|
my $json_out = eval { decode_json($jsondata) }; |
258
|
|
|
|
|
|
|
if ($@){ |
259
|
|
|
|
|
|
|
#print "Error: $@"; |
260
|
|
|
|
|
|
|
return 0; |
261
|
|
|
|
|
|
|
}else{ |
262
|
|
|
|
|
|
|
return 1; |
263
|
|
|
|
|
|
|
#print "OK!\n"; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; # this 1; is neccessary for our class to work |