blib/lib/OxdPackages/UmaRsCheckAccess.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 108 CC 6 SCAR 12.6
CC
6
Cov
0%
setRequestOxdId
6.0
setRequestRpt
6.0
setRequestPath
6.0
CRAP 3.5
1 #!/usr/bin/perl
2
3 ##
4 # Gluu-oxd-library
5 #
6 # An open source application library for Perl
7 #
8 # This content is released under the MIT License (MIT)
9 #
10 # Copyright (c) 2018, Gluu inc, USA, Austin
11 #
12 # Permission is hereby granted, free of charge, to any person obtaining a copy
13 # of this software and associated documentation files (the "Software"), to deal
14 # in the Software without restriction, including without limitation the rights
15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 # copies of the Software, and to permit persons to whom the Software is
17 # furnished to do so, subject to the following conditions:
18 #
19 # The above copyright notice and this permission notice shall be included in
20 # all copies or substantial portions of the Software.
21 #
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 # THE SOFTWARE.
29 #
30 # @package Gluu-oxd-library
31 # @version 3.1.2
32 # @author Inderpal Singh, Sobhan Panda
33 # @author_email inderpal@ourdesignz.com, sobhan@centroxy.com
34 # @copyright Copyright (c) 2018, Gluu inc federation (https://gluu.org/)
35 # @license http://opensource.org/licenses/MIT MIT License
36 # @link https://gluu.org/
37 # @since Version 3.1.2
38 # @filesource
39 #/
40
41 ##
42 # UMA RP - Check Access class
43 #
44 # Class is connecting to oxd-server via socket, and getting GAT from gluu-server.
45 #
46 # @package Gluu-oxd-library
47 # @subpackage Libraries
48 # @category Relying Party (RP) and User Managed Access (UMA)
49 # @author Inderpal Singh, Sobhan Panda
50 # @author inderpal@ourdesignz.com, sobhan@centroxy.com
51 # @see OxdClientSocket
52 # @see OxdClient
53 # @see OxdConfig
54 #
55
56 package UmaRsCheckAccess;
57 use vars qw($VERSION);
58 $VERSION = '0.01';
59 use OxdPackages::OxdClient;
60 use base qw(OxdClient Class::Accessor);
61 use strict;
62 our @ISA = qw(OxdClient); # inherits from OxdClient
63 use Data::Dumper;
64
65 sub new {
66 my $class = shift;
67 my $self = {
68
69 # @var string $request_oxd_id This parameter you must get after registration site in gluu-server
70 _request_oxd_id => shift,
71
72 # @var string $request_rpt This parameter you must get after using uma_rp_get_rpt protocol
73 _request_rpt => shift,
74
75 # @var string $request_path Path of resource (e.g. http://rs.com/phones), /phones should be passed
76 _request_path => shift,
77
78 # @var string $request_http_method Http method of RP request (GET, POST, PUT, DELETE)
79 _request_http_method => shift,
80 _request_protection_access_token => shift,
81
82 # Response parameter from oxd-server
83 # Access grant response (granted or denied)
84 # @var string $response_access
85 _response_access => shift,
86
87 # Response parameter from oxd-server
88 # Ticket number
89 # @var string $response_ticket
90 _response_ticket => shift,
91 };
92 # Print all the values just for clarification.
93 # print "First Name is $self->{_request_oxd_id}\n";
94
95 # print "<br>";
96 bless $self, $class;
97 return $self;
98 }
99
100
101 # @return string
102 sub getRequestOxdId
103 {
104 my( $self ) = @_;
105 return $self->{_request_oxd_id}
106 }
107
108
109 # @return string
110 sub getResponseTicket
111 {
112 my( $self ) = @_;
113 $self->{_response_ticket} = $self->getResponseData()->{ticket};
114 return $self->{_response_ticket}
115 }
116
117
118 # @param string $request_oxd_id
119 # @return void
120 sub setRequestOxdId
121 {
122 my ( $self, $request_oxd_id ) = @_;
123 $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id);
124 return $self->{_request_oxd_id};
125 }
126
127 # @return string
128 sub getRequestRpt
129 {
130 my( $self ) = @_;
131 return $self->{_request_rpt}
132 }
133
134 # @param string $request_rpt
135 # @return void
136 sub setRequestRpt
137 {
138 my ( $self, $request_rpt ) = @_;
139 $self->{_request_rpt} = $request_rpt if defined($request_rpt);
140 return $self->{_request_rpt};
141 }
142
143 # @return string
144 sub getRequestPath
145 {
146 my( $self ) = @_;
147 return $self->{_request_path}
148 }
149
150 # @param null $request_path
151 # @return void
152 sub setRequestPath
153 {
154 my ( $self, $request_path ) = @_;
155 $self->{_request_path} = $request_path if defined($request_path);
156 return $self->{_request_path};
157 }
158
159 # @return string
160 sub getRequestHttpMethod
161 {
162 my( $self ) = @_;
163 return $self->{_request_http_method}
164 }
165
166
167 # @param string $request_http_method
168 # @return void
169 sub setRequestHttpMethod
170 {
171 my ( $self, $request_http_method ) = @_;
172 $self->{_request_http_method} = $request_http_method if defined($request_http_method);
173 return $self->{_request_http_method};
174 }
175
176
177 # @return string
178 sub getRequestProtectionAccessToken
179 {
180 my( $self ) = @_;
181 return $self->{_request_protection_access_token}
182 }
183
184 ##
185 # @param string $request_protection_access_token
186 # @return void
187 #
188 sub setRequestProtectionAccessToken
189 {
190 my ( $self, $request_protection_access_token ) = @_;
191 $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token);
192 return $self->{_request_protection_access_token};
193 }
194
195 # @return string
196 sub getResponseAccess
197 {
198 my( $self ) = @_;
199 $self->{_response_access} = $self->getResponseData()->access;
200 return $self->{_response_access}
201 }
202
203
204 # Protocol command to oxd server
205 # @return void
206 sub setCommand
207 {
208 my ( $self ) = @_;
209 $self->{_command} = 'uma_rs_check_access';
210 }
211
212 # Protocol command to oxd to http server
213 # @return void
214 sub sethttpCommand
215 {
216 my ( $self ) = @_;
217 $self->{_httpcommand} = 'uma-rs-check-access';
218 }
219
220
221 # Method: setParams
222 # This method sets the parameters for uma_rs_check_access command.
223 # This module uses `request` method of OxdClient module for sending request to oxd-server
224 #
225 # Parameters:
226 #
227 # string $oxd_id - (Required) oxd Id from Client registration
228 #
229 # string $rpt - (Required) RPT Token. Can have blank value if absent (not send by RP)
230 #
231 # string $path - (Required) Path of resource (e.g. http://rs.com/phones), /phones should be passed
232 #
233 # string $http_method - (Required) Http method of RP request (GET, POST, PUT, DELETE)
234 #
235 # string $protection_access_token - Protection Acccess Token. OPTIONAL for `oxd-server` but REQUIRED for `oxd-https-extension`
236 #
237 # Returns:
238 # void
239 #
240 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
241 #
242 # *Access Granted Response from getResponseObject:*
243 # --- Code
244 # { "status":"ok", "data":{ "access":"granted" } }
245 # ---
246 #
247 # *Access Denied with Ticket Response from getResponseObject:*
248 # --- Code
249 # { "status": "ok", "data": { "access": "denied", "www-authenticate_header": "UMA realm=\"rs",as_uri="https://as.example.com",error="insufficient_scope",ticket="d26c30fd-eb94-40da-9f61-0c424acedf0e"", "ticket": "d26c30fd-eb94-40da-9f61-0c424acedf0e", "error": null, "error_description": null } }
250 # ---
251 #
252 # *Access Denied without Ticket Response from getResponseObject:*
253 # --- Code
254 # { "status": "ok", "data": { "access": "denied", } }
255 # ---
256 #
257 # *Resource is not Protected from getResponseObject:*
258 # --- Code
259 # { "status":"error", "data":{ "error":"invalid_request", "error_description":"Resource is not protected. Please protect your resource first with uma_rs_protect command." } }
260 # ---
261 #
262 sub setParams
263 {
264 my ( $self, $params ) = @_;
265 my $paramsArray = {
266 "oxd_id" => $self->getRequestOxdId(),
267 "rpt" => $self->getRequestRpt(),
268 "path" => $self->getRequestPath(),
269 "http_method" => $self->getRequestHttpMethod(),
270 "protection_access_token" => $self->getRequestProtectionAccessToken()
271 };
272 $self->{_params} = $paramsArray;
273 return $self->{_params};
274
275 }
276
277 1; # this 1; is neccessary for our class to work