| 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) 2016, 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 RP - Get Rpt 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 UmaRpGetRpt; | ||
| 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 bool $request_force_new Indicates whether return new RPT, in general should be false, so oxd server can cache/reuse same RPT | ||
| 73 | _request_force_new => shift, | ||
| 74 | |||
| 75 | _request_ticket => shift, | ||
| 76 | |||
| 77 | _request_claim_token => shift, | ||
| 78 | |||
| 79 | _request_claim_token_format => shift, | ||
| 80 | |||
| 81 | _request_pct => shift, | ||
| 82 | |||
| 83 | _request_rpt => shift, | ||
| 84 | |||
| 85 | _request_scope => shift, | ||
| 86 | |||
| 87 | _request_state => shift, | ||
| 88 | |||
| 89 | _request_protection_access_token => shift, | ||
| 90 | |||
| 91 | |||
| 92 | # Response parameter from oxd-server | ||
| 93 | # Gluu RP Token | ||
| 94 | # @var string $response_rpt | ||
| 95 | |||
| 96 | _response_rpt => shift | ||
| 97 | }; | ||
| 98 | # Print all the values just for clarification. | ||
| 99 | # print "First Name is $self->{_request_oxd_id}\n"; | ||
| 100 | |||
| 101 | # print "<br>"; | ||
| 102 | bless $self, $class; | ||
| 103 | return $self; | ||
| 104 | } | ||
| 105 | |||
| 106 | # @return string | ||
| 107 | sub getRequestOxdId | ||
| 108 | { | ||
| 109 | my( $self ) = @_; | ||
| 110 | return $self->{_request_oxd_id} | ||
| 111 | } | ||
| 112 | |||
| 113 | ## | ||
| 114 | # @param string $request_oxd_id | ||
| 115 | # @return void | ||
| 116 | # | ||
| 117 | sub setRequestOxdId | ||
| 118 | { | ||
| 119 | my ( $self, $request_oxd_id ) = @_; | ||
| 120 | $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id); | ||
| 121 | return $self->{_request_oxd_id}; | ||
| 122 | } | ||
| 123 | |||
| 124 | ## | ||
| 125 | # @return bool | ||
| 126 | # | ||
| 127 | sub getRequestForceNew | ||
| 128 | { | ||
| 129 | my( $self ) = @_; | ||
| 130 | return $self->{_request_force_new}; | ||
| 131 | } | ||
| 132 | |||
| 133 | ## | ||
| 134 | # @param bool $request_force_new | ||
| 135 | # @return void | ||
| 136 | # | ||
| 137 | sub setRequestForceNew | ||
| 138 | { | ||
| 139 | my ( $self, $request_force_new ) = @_; | ||
| 140 | $self->{_request_force_new} = $request_force_new if defined($request_force_new); | ||
| 141 | return $self->{_request_force_new}; | ||
| 142 | } | ||
| 143 | |||
| 144 | |||
| 145 | # @return string | ||
| 146 | sub getRequestTicket | ||
| 147 | { | ||
| 148 | my( $self ) = @_; | ||
| 149 | return $self->{_request_ticket} | ||
| 150 | } | ||
| 151 | |||
| 152 | ## | ||
| 153 | # @param string $request_ticket | ||
| 154 | # @return void | ||
| 155 | # | ||
| 156 | sub setRequestTicket | ||
| 157 | { | ||
| 158 | my ( $self, $request_ticket ) = @_; | ||
| 159 | $self->{_request_ticket} = $request_ticket if defined($request_ticket); | ||
| 160 | return $self->{_request_ticket}; | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | # @return string | ||
| 165 | sub getRequestClaimToken | ||
| 166 | { | ||
| 167 | my( $self ) = @_; | ||
| 168 | return $self->{_request_claim_token} | ||
| 169 | } | ||
| 170 | |||
| 171 | ## | ||
| 172 | # @param string $request_claim_token | ||
| 173 | # @return void | ||
| 174 | # | ||
| 175 | sub setRequestClaimToken | ||
| 176 | { | ||
| 177 | my ( $self, $request_claim_token ) = @_; | ||
| 178 | $self->{_request_claim_token} = $request_claim_token if defined($request_claim_token); | ||
| 179 | return $self->{_request_claim_token}; | ||
| 180 | } | ||
| 181 | |||
| 182 | |||
| 183 | # @return string | ||
| 184 | sub getRequestClaimTokenFormat | ||
| 185 | { | ||
| 186 | my( $self ) = @_; | ||
| 187 | return $self->{_request_claim_token_format} | ||
| 188 | } | ||
| 189 | |||
| 190 | ## | ||
| 191 | # @param string $request_claim_token_format | ||
| 192 | # @return void | ||
| 193 | # | ||
| 194 | sub setRequestClaimTokenFormat | ||
| 195 | { | ||
| 196 | my ( $self, $request_claim_token_format ) = @_; | ||
| 197 | $self->{_request_claim_token_format} = $request_claim_token_format if defined($request_claim_token_format); | ||
| 198 | return $self->{_request_claim_token_format}; | ||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 202 | # @return string | ||
| 203 | sub getRequestPCT | ||
| 204 | { | ||
| 205 | my( $self ) = @_; | ||
| 206 | return $self->{_request_pct} | ||
| 207 | } | ||
| 208 | |||
| 209 | ## | ||
| 210 | # @param string $request_pct | ||
| 211 | # @return void | ||
| 212 | # | ||
| 213 | sub setRequestPCT | ||
| 214 | { | ||
| 215 | my ( $self, $request_pct ) = @_; | ||
| 216 | $self->{_request_pct} = $request_pct if defined($request_pct); | ||
| 217 | return $self->{_request_pct}; | ||
| 218 | } | ||
| 219 | |||
| 220 | |||
| 221 | # @return string | ||
| 222 | sub getRequestRPT | ||
| 223 | { | ||
| 224 | my( $self ) = @_; | ||
| 225 | return $self->{_request_rpt} | ||
| 226 | } | ||
| 227 | |||
| 228 | ## | ||
| 229 | # @param string $request_rpt | ||
| 230 | # @return void | ||
| 231 | # | ||
| 232 | sub setRequestRPT | ||
| 233 | { | ||
| 234 | my ( $self, $request_rpt ) = @_; | ||
| 235 | $self->{_request_rpt} = $request_rpt if defined($request_rpt); | ||
| 236 | return $self->{_request_rpt}; | ||
| 237 | } | ||
| 238 | |||
| 239 | |||
| 240 | # @return string | ||
| 241 | sub getRequestScope | ||
| 242 | { | ||
| 243 | my( $self ) = @_; | ||
| 244 | return $self->{_request_scope} | ||
| 245 | } | ||
| 246 | |||
| 247 | ## | ||
| 248 | # @param string $request_scope | ||
| 249 | # @return void | ||
| 250 | # | ||
| 251 | sub setRequestScope | ||
| 252 | { | ||
| 253 | my ( $self, $request_scope ) = @_; | ||
| 254 | $self->{_request_scope} = $request_scope if defined($request_scope); | ||
| 255 | return $self->{_request_scope}; | ||
| 256 | } | ||
| 257 | |||
| 258 | |||
| 259 | # @return string | ||
| 260 | sub getRequestState | ||
| 261 | { | ||
| 262 | my( $self ) = @_; | ||
| 263 | return $self->{_request_state} | ||
| 264 | } | ||
| 265 | |||
| 266 | ## | ||
| 267 | # @param string $request_state | ||
| 268 | # @return void | ||
| 269 | # | ||
| 270 | sub setRequestState | ||
| 271 | { | ||
| 272 | my ( $self, $request_state ) = @_; | ||
| 273 | $self->{_request_state} = $request_state if defined($request_state); | ||
| 274 | return $self->{_request_state}; | ||
| 275 | } | ||
| 276 | |||
| 277 | |||
| 278 | # @return string | ||
| 279 | sub getRequestProtectionAccessToken | ||
| 280 | { | ||
| 281 | my( $self ) = @_; | ||
| 282 | return $self->{_request_protection_access_token} | ||
| 283 | } | ||
| 284 | |||
| 285 | ## | ||
| 286 | # @param string $request_protection_access_token | ||
| 287 | # @return void | ||
| 288 | # | ||
| 289 | sub setRequestProtectionAccessToken | ||
| 290 | { | ||
| 291 | my ( $self, $request_protection_access_token ) = @_; | ||
| 292 | $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token); | ||
| 293 | return $self->{_request_protection_access_token}; | ||
| 294 | } | ||
| 295 | |||
| 296 | |||
| 297 | ## | ||
| 298 | # @return string | ||
| 299 | # | ||
| 300 | sub getResponseRpt | ||
| 301 | { | ||
| 302 | my( $self ) = @_; | ||
| 303 | $self->{_response_rpt} = $self->getResponseData()->{rpt}; | ||
| 304 | return $self->{_response_rpt}; | ||
| 305 | } | ||
| 306 | |||
| 307 | ## | ||
| 308 | # Protocol command to oxd server | ||
| 309 | # @return void | ||
| 310 | # | ||
| 311 | sub setCommand | ||
| 312 | { | ||
| 313 | my ( $self ) = @_; | ||
| 314 | $self->{_command} = 'uma_rp_get_rpt'; | ||
| 315 | } | ||
| 316 | |||
| 317 | ## | ||
| 318 | # Protocol command to oxd to http server | ||
| 319 | # @return void | ||
| 320 | # | ||
| 321 | sub sethttpCommand | ||
| 322 | { | ||
| 323 | my ( $self ) = @_; | ||
| 324 | $self->{_httpcommand} = 'uma-rp-get-rpt'; | ||
| 325 | } | ||
| 326 | |||
| 327 | ## | ||
| 328 | # Protocol parameter to oxd server | ||
| 329 | # @return void | ||
| 330 | # | ||
| 331 | sub setParams | ||
| 332 | { | ||
| 333 | my ( $self, $params ) = @_; | ||
| 334 | my $paramsArray = { | ||
| 335 | "oxd_id" => $self->getRequestOxdId(), | ||
| 336 | "ticket" => $self->getRequestTicket(), | ||
| 337 | "claim_token" => $self->getRequestClaimToken(), | ||
| 338 | "claim_token_format" => $self->getRequestClaimTokenFormat(), | ||
| 339 | "pct" => $self->getRequestPCT(), | ||
| 340 | "rpt" => $self->getRequestRPT(), | ||
| 341 | "scope" => $self->getRequestScope(), | ||
| 342 | "state" => $self->getRequestState(), | ||
| 343 | "protection_access_token" => $self->getRequestProtectionAccessToken() | ||
| 344 | }; | ||
| 345 | $self->{_params} = $paramsArray; | ||
| 346 | return $self->{_params}; | ||
| 347 | } | ||
| 348 | |||
| 349 | 1; # this 1; is neccessary for our class to work |