OxdPackages/UmaRsProtect.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 104 CC 4 SCAR 11.1
CC
4
Cov
0%
setRequestOxdId
6.0
setOverwrite
6.0
setRequestProtectionAccessToken
6.0
CRAP 3.0
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.3
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.3
38 # @filesource
39 #/
40
41 ##
42 # UMA RS Protect resources package
43 #
44 # Package is connecting to oxd-server via socket, and adding resources in 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 UmaRsProtect;
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 # @var string $request_oxd_id This parameter you must get after registration site in gluu-server
69 _request_oxd_id => shift,
70
71 _request_overwrite => shift,
72
73 _request_protection_access_token => shift,
74
75 # @var array $request_resources This parameter your resources parameter
76 _request_resources => [],
77 _request_resource => [],
78 _request_condition => [],
79 };
80 # Print all the values just for clarification.
81 #print "First Name is $self->{_request_oxd_id}\n";
82
83 #print "<br>";
84 bless $self, $class;
85 return $self;
86 }
87
88 # @return string
89 sub getRequestOxdId{
90 my( $self ) = @_;
91 return $self->{_request_oxd_id};
92 }
93
94 # @param string $request_oxd_id
95 # @return void
96 sub setRequestOxdId{
97 my ( $self, $request_oxd_id ) = @_;
98 $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id);
99 return $self->{_request_oxd_id};
100 }
101
102 # @return string
103 sub getOverwrite {
104 my( $self ) = @_;
105 return $self->{_request_overwrite};
106 }
107
108 # @param string $request_overwrite
109 # @return void
110 sub setOverwrite {
111 my ( $self, $request_overwrite ) = @_;
112 $self->{_request_overwrite} = $request_overwrite if defined($request_overwrite);
113 return $self->{_request_overwrite};
114 }
115
116 # @return array
117 sub getRequestProtectionAccessToken
118 {
119 my( $self ) = @_;
120 return $self->{_request_protection_access_token};
121 }
122
123
124 # @param array $request_request_protection_access_token
125 # @return void
126 sub setRequestProtectionAccessToken
127 {
128 my ( $self, $request_protection_access_token ) = @_;
129 $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token);
130 return $self->{_request_protection_access_token};
131 }
132
133 # @return array
134 sub getRequestResources{
135 my( $self ) = @_;
136 return $self->{_request_resources};
137 }
138
139 sub addResource{
140 my ( $self, $path ) = @_;
141
142 my @request_resources = {
143 'path'=>$path,
144 'conditions' => $self->{_request_condition}
145 };
146
147 push $self->{_request_resources}, @request_resources;
148 $self->{_request_condition} = "";
149 }
150
151 # Method: addConditionForPath
152 #
153 # Parameters:
154 #
155 # array $httpMethods - List of HTTP Methods supported in a condition
156 #
157 # array $scopes - List of Scopes in a condition
158 #
159 # array $ticketScopes - List of Scopes protected with ticket in a condition
160 #
161 # dict $scope_expression - Scope expression for logical operations
162 #
163 # Returns:
164 # dict Condition
165 sub addConditionForPath{
166 my ( $self, $httpMethods, $scopes, $ticketScopes, $scope_expression ) = @_;
167
168 my @request_condition = {
169 "httpMethods" => $httpMethods,
170 "scopes" => $scopes,
171 "ticketScopes" => $ticketScopes,
172 "scope_expression" => $scope_expression
173 };
174
175 push $self->{_request_condition}, @request_condition;
176 return $self->{_request_condition};
177 }
178 sub getCondition{
179 my( $self ) = @_;
180 return $self->{_request_condition};
181 }
182
183 # Method: getScopeExpression
184 #
185 # Parameters:
186 #
187 # dict $rule - Rule
188 #
189 # array $data - Data
190 #
191 # Returns:
192 # dict ScopeExpression
193 sub getScopeExpression {
194 my ( $self, $request_rule, $request_data ) = @_;
195
196 my $request_scope_expression = {
197 "rule" => $request_rule,
198 "data" => $request_data,
199 };
200
201 #push $self->{_request_scope_expression}, @request_scope_expression;
202 return $request_scope_expression;
203
204 }
205
206 # Protocol command to oxd server
207 # @return void
208 sub setCommand{
209 my ( $self ) = @_;
210 $self->{_command} = 'uma_rs_protect';
211 }
212
213 # Protocol command to oxd to http server
214 # @return void
215 sub sethttpCommand {
216 my ( $self ) = @_;
217 $self->{_httpcommand} = 'uma-rs-protect';
218 }
219
220 # Method: setParams
221 # This method sets the parameters for uma_rs_protect command.
222 # This module uses `request` method of OxdClient module for sending request to oxd-server
223 #
224 # Parameters:
225 #
226 # string $oxd_id - (Required) oxd Id from Client registration
227 #
228 # bool $overwrite - (Optional) If true, Allows existing resource to overwrite
229 #
230 # dict $resources - (Required) Resources to be protected
231 #
232 # string $protection_access_token - Protection Acccess Token. OPTIONAL for `oxd-server` but REQUIRED for `oxd-https-extension`
233 #
234 # Returns:
235 # void
236 #
237 # This module uses `getResponseObject` method of OxdClient module for getting response from oxd.
238 #
239 # *Example response from getResponseObject:*
240 # --- Code
241 # { "status":"ok", "data": { "oxd_id": "bcad760f-91ba-46e1-a020-05e4281d91b6" } }
242 # ---
243 #
244 sub setParams{
245 my ( $self, $params ) = @_;
246 my $paramsArray = {
247 "oxd_id" => $self->getRequestOxdId(),
248 "overwrite" => $self->getOverwrite(),
249 "resources" => $self->getRequestResources(),
250 "protection_access_token" => $self->getRequestProtectionAccessToken()
251
252 };
253 # print Dumper $paramsArray;
254 $self->{_params} = $paramsArray;
255
256 #exit 1;
257 return $self->{_params};
258 }
259
260 1; # this 1; is neccessary for our class to work