OxdPackages/UmaRsProtect.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 87 CC 3 SCAR 10.4
CC
3
Cov
0%
setRequestOxdId
6.0
setRequestProtectionAccessToken
6.0
new
2.0
CRAP 2.8
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) 2017, 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.0
32 # @author Inderpal Singh, Sobhan Panda
33 # @author_email inderpal@ourdesignz.com, sobhan@centroxy.com
34 # @copyright Copyright (c) 2017, 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.0
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_protection_access_token => shift,
72
73 # @var array $request_resources This parameter your resources parameter
74 _request_resources => [],
75 _request_resource => [],
76 _request_condition => [],
77 };
78 # Print all the values just for clarification.
79 #print "First Name is $self->{_request_oxd_id}\n";
80
81 #print "<br>";
82 bless $self, $class;
83 return $self;
84 }
85
86 # @return string
87 sub getRequestOxdId{
88 my( $self ) = @_;
89 return $self->{_request_oxd_id};
90 }
91
92 # @param string $request_oxd_id
93 # @return void
94 sub setRequestOxdId{
95 my ( $self, $request_oxd_id ) = @_;
96 $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id);
97 return $self->{_request_oxd_id};
98 }
99
100 # @return array
101 sub getRequestProtectionAccessToken
102 {
103 my( $self ) = @_;
104 return $self->{_request_protection_access_token};
105 }
106
107
108 # @param array $request_request_protection_access_token
109 # @return void
110 sub setRequestProtectionAccessToken
111 {
112 my ( $self, $request_protection_access_token ) = @_;
113 $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token);
114 return $self->{_request_protection_access_token};
115 }
116
117 # @return array
118 sub getRequestResources{
119 my( $self ) = @_;
120 return $self->{_request_resources};
121 }
122
123 sub addResource{
124 my ( $self, $path ) = @_;
125
126 my @request_resources = {
127 'path'=>$path,
128 'conditions' => $self->{_request_condition}
129 };
130
131 push $self->{_request_resources}, @request_resources;
132 $self->{_request_condition} = "";
133 }
134
135 sub addConditionForPath{
136 my ( $self, $httpMethods, $scopes, $ticketScopes ) = @_;
137
138 my @request_condition = {
139 "httpMethods" => $httpMethods,
140 "scopes" => $scopes,
141 "ticketScopes" => $ticketScopes
142 };
143
144 push $self->{_request_condition}, @request_condition;
145 return $self->{_request_condition};
146 }
147 sub getCondition{
148 my( $self ) = @_;
149 return $self->{_request_condition};
150 }
151
152 # Protocol command to oxd server
153 # @return void
154 sub setCommand{
155 my ( $self ) = @_;
156 $self->{_command} = 'uma_rs_protect';
157 }
158
159 # Protocol command to oxd to http server
160 # @return void
161 sub sethttpCommand {
162 my ( $self ) = @_;
163 $self->{_httpcommand} = 'uma-rs-protect';
164 }
165
166 # Protocol parameter to oxd server
167 # @return void
168 sub setParams{
169 my ( $self, $params ) = @_;
170 my $paramsArray = {
171 "oxd_id" => $self->getRequestOxdId(),
172 "resources" => $self->getRequestResources(),
173 "protection_access_token" => $self->getRequestProtectionAccessToken()
174
175 };
176 # print Dumper $paramsArray;
177 $self->{_params} = $paramsArray;
178
179 #exit 1;
180 return $self->{_params};
181 }
182
183 1; # this 1; is neccessary for our class to work