| 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 Sobhan Panda | ||
| 33 | # @author 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 | package UmaRpGetClaimsGatheringUrl; | ||
| 43 | use vars qw($VERSION); | ||
| 44 | $VERSION = '0.01'; | ||
| 45 | use OxdPackages::OxdClient; | ||
| 46 | use base qw(OxdClient Class::Accessor); | ||
| 47 | use strict; | ||
| 48 | our @ISA = qw(OxdClient); # inherits from OxdClient | ||
| 49 | use Data::Dumper; | ||
| 50 | |||
| 51 | sub new { | ||
| 52 | my $class = shift; | ||
| 53 | my $self = { | ||
| 54 | |||
| 55 | # @var string $request_oxd_id This parameter you must get after registration site in gluu-server | ||
| 56 | _request_oxd_id => shift, | ||
| 57 | |||
| 58 | # @var bool $request_force_new Indicates whether return new RPT, in general should be false, so oxd server can cache/reuse same RPT | ||
| 59 | _request_force_new => shift, | ||
| 60 | |||
| 61 | _request_ticket => shift, | ||
| 62 | |||
| 63 | _request_claims_redirect_uri => shift, | ||
| 64 | |||
| 65 | _request_protection_access_token => shift, | ||
| 66 | |||
| 67 | |||
| 68 | # Response parameter from oxd-server | ||
| 69 | # Gluu RP Token | ||
| 70 | # @var string $response_rpt | ||
| 71 | |||
| 72 | _response_rpt => shift, | ||
| 73 | |||
| 74 | _response_url => shift | ||
| 75 | }; | ||
| 76 | # Print all the values just for clarification. | ||
| 77 | # print "First Name is $self->{_request_oxd_id}\n"; | ||
| 78 | |||
| 79 | # print "<br>"; | ||
| 80 | bless $self, $class; | ||
| 81 | return $self; | ||
| 82 | } | ||
| 83 | |||
| 84 | # @return string | ||
| 85 | sub getRequestOxdId | ||
| 86 | { | ||
| 87 | my( $self ) = @_; | ||
| 88 | return $self->{_request_oxd_id} | ||
| 89 | } | ||
| 90 | |||
| 91 | ## | ||
| 92 | # @param string $request_oxd_id | ||
| 93 | # @return void | ||
| 94 | # | ||
| 95 | sub setRequestOxdId | ||
| 96 | { | ||
| 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 | ## | ||
| 103 | # @return bool | ||
| 104 | # | ||
| 105 | sub getRequestForceNew | ||
| 106 | { | ||
| 107 | my( $self ) = @_; | ||
| 108 | return $self->{_request_force_new}; | ||
| 109 | } | ||
| 110 | |||
| 111 | ## | ||
| 112 | # @param bool $request_force_new | ||
| 113 | # @return void | ||
| 114 | # | ||
| 115 | sub setRequestForceNew | ||
| 116 | { | ||
| 117 | my ( $self, $request_force_new ) = @_; | ||
| 118 | $self->{_request_force_new} = $request_force_new if defined($request_force_new); | ||
| 119 | return $self->{_request_force_new}; | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 123 | # @return string | ||
| 124 | sub getRequestTicket | ||
| 125 | { | ||
| 126 | my( $self ) = @_; | ||
| 127 | return $self->{_request_ticket} | ||
| 128 | } | ||
| 129 | |||
| 130 | ## | ||
| 131 | # @param string $request_ticket | ||
| 132 | # @return void | ||
| 133 | # | ||
| 134 | sub setRequestTicket | ||
| 135 | { | ||
| 136 | my ( $self, $request_ticket ) = @_; | ||
| 137 | $self->{_request_ticket} = $request_ticket if defined($request_ticket); | ||
| 138 | return $self->{_request_ticket}; | ||
| 139 | } | ||
| 140 | |||
| 141 | |||
| 142 | # @return string | ||
| 143 | sub getRequestClaimsRedirectUri | ||
| 144 | { | ||
| 145 | my( $self ) = @_; | ||
| 146 | return $self->{_request_claims_redirect_uri} | ||
| 147 | } | ||
| 148 | |||
| 149 | ## | ||
| 150 | # @param string $request_claim_token | ||
| 151 | # @return void | ||
| 152 | # | ||
| 153 | sub setRequestClaimsRedirectUri | ||
| 154 | { | ||
| 155 | my ( $self, $request_claims_redirect_uri ) = @_; | ||
| 156 | $self->{_request_claims_redirect_uri} = $request_claims_redirect_uri if defined($request_claims_redirect_uri); | ||
| 157 | return $self->{_request_claims_redirect_uri}; | ||
| 158 | } | ||
| 159 | |||
| 160 | |||
| 161 | # @return string | ||
| 162 | sub getRequestProtectionAccessToken | ||
| 163 | { | ||
| 164 | my( $self ) = @_; | ||
| 165 | return $self->{_request_protection_access_token} | ||
| 166 | } | ||
| 167 | |||
| 168 | ## | ||
| 169 | # @param string $request_protection_access_token | ||
| 170 | # @return void | ||
| 171 | # | ||
| 172 | sub setRequestProtectionAccessToken | ||
| 173 | { | ||
| 174 | my ( $self, $request_protection_access_token ) = @_; | ||
| 175 | $self->{_request_protection_access_token} = $request_protection_access_token if defined($request_protection_access_token); | ||
| 176 | return $self->{_request_protection_access_token}; | ||
| 177 | } | ||
| 178 | |||
| 179 | |||
| 180 | ## | ||
| 181 | # @return string | ||
| 182 | # | ||
| 183 | sub getResponseRpt | ||
| 184 | { | ||
| 185 | my( $self ) = @_; | ||
| 186 | $self->{_response_rpt} = $self->getResponseData()->{rpt}; | ||
| 187 | return $self->{_response_rpt}; | ||
| 188 | } | ||
| 189 | |||
| 190 | ## | ||
| 191 | # @return string | ||
| 192 | # | ||
| 193 | sub getResponseUrl | ||
| 194 | { | ||
| 195 | my( $self ) = @_; | ||
| 196 | $self->{_response_url} = $self->getResponseData()->{url}; | ||
| 197 | return $self->{_response_url}; | ||
| 198 | } | ||
| 199 | |||
| 200 | ## | ||
| 201 | # Protocol command to oxd server | ||
| 202 | # @return void | ||
| 203 | # | ||
| 204 | sub setCommand | ||
| 205 | { | ||
| 206 | my ( $self ) = @_; | ||
| 207 | $self->{_command} = 'uma_rp_get_claims_gathering_url'; | ||
| 208 | } | ||
| 209 | |||
| 210 | ## | ||
| 211 | # Protocol command to oxd to http server | ||
| 212 | # @return void | ||
| 213 | # | ||
| 214 | sub sethttpCommand | ||
| 215 | { | ||
| 216 | my ( $self ) = @_; | ||
| 217 | $self->{_httpcommand} = 'uma-rp-get-claims-gathering-url'; | ||
| 218 | } | ||
| 219 | |||
| 220 | # Method: setParams | ||
| 221 | # This method sets the parameters for uma_rp_get_claims_gathering_url 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 | # string $ticket - (Required) Ticket | ||
| 229 | # | ||
| 230 | # string $claims_redirect_uri - (Required) Claims Redirect Uri | ||
| 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": { "url": "https://idp-hostname/oxauth/restv1/uma/gather_claims?client_id=@!4116.DF7C.62D4.D0CF!0001!D420.A5E5!0008!6156.5BD4.5F9B.D172&ticket=d26c30fd-eb94-40da-9f61-0c424acedf0e&claims_redirect_uri=https://client.example.com&state=fk0vl0lvmn8imecjf67m57r772", "state": "fk0vl0lvmn8imecjf67m57r772", "error": null, "error_description": null } } | ||
| 242 | # --- | ||
| 243 | # | ||
| 244 | sub setParams | ||
| 245 | { | ||
| 246 | my ( $self, $params ) = @_; | ||
| 247 | my $paramsArray = { | ||
| 248 | "oxd_id" => $self->getRequestOxdId(), | ||
| 249 | "ticket" => $self->getRequestTicket(), | ||
| 250 | "claims_redirect_uri" => $self->getRequestClaimsRedirectUri(), | ||
| 251 | "protection_access_token" => $self->getRequestProtectionAccessToken() | ||
| 252 | }; | ||
| 253 | $self->{_params} = $paramsArray; | ||
| 254 | return $self->{_params}; | ||
| 255 | } | ||
| 256 | |||
| 257 | 1; # this 1; is neccessary for our class to work |