| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | ## | ||
| 4 | # Gluu-oxd-library | ||
| 5 | # | ||
| 6 | # An open source application library for PHP | ||
| 7 | # | ||
| 8 | # This content is released under the MIT License (MIT) | ||
| 9 | # | ||
| 10 | # Copyright (c) 2016, 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 2.4.4 | ||
| 32 | # @author Inderpal Singh | ||
| 33 | # @author inderpal@ourdesignz.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 2.4.4 | ||
| 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 | ||
| 50 | # @author inderpal@ourdesignz.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 | |||
| 81 | # Response parameter from oxd-server | ||
| 82 | # Access grant response (granted or denied) | ||
| 83 | # @var string $response_access | ||
| 84 | _response_access => shift, | ||
| 85 | |||
| 86 | # Response parameter from oxd-server | ||
| 87 | # Ticket number | ||
| 88 | # @var string $response_ticket | ||
| 89 | _response_ticket => shift, | ||
| 90 | }; | ||
| 91 | # Print all the values just for clarification. | ||
| 92 | # print "First Name is $self->{_request_oxd_id}\n"; | ||
| 93 | |||
| 94 | # print "<br>"; | ||
| 95 | bless $self, $class; | ||
| 96 | return $self; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | # @return string | ||
| 101 | sub getRequestOxdId | ||
| 102 | { | ||
| 103 | my( $self ) = @_; | ||
| 104 | return $self->{_request_oxd_id} | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | # @return string | ||
| 109 | sub getResponseTicket | ||
| 110 | { | ||
| 111 | my( $self ) = @_; | ||
| 112 | $self->{_response_ticket} = $self->getResponseData()->{ticket}; | ||
| 113 | return $self->{_response_ticket} | ||
| 114 | } | ||
| 115 | |||
| 116 | |||
| 117 | # @param string $request_oxd_id | ||
| 118 | # @return void | ||
| 119 | sub setRequestOxdId | ||
| 120 | { | ||
| 121 | my ( $self, $request_oxd_id ) = @_; | ||
| 122 | $self->{_request_oxd_id} = $request_oxd_id if defined($request_oxd_id); | ||
| 123 | return $self->{_request_oxd_id}; | ||
| 124 | } | ||
| 125 | |||
| 126 | # @return string | ||
| 127 | sub getRequestRpt | ||
| 128 | { | ||
| 129 | my( $self ) = @_; | ||
| 130 | return $self->{_request_rpt} | ||
| 131 | } | ||
| 132 | |||
| 133 | # @param string $request_rpt | ||
| 134 | # @return void | ||
| 135 | sub setRequestRpt | ||
| 136 | { | ||
| 137 | my ( $self, $request_rpt ) = @_; | ||
| 138 | $self->{_request_rpt} = $request_rpt if defined($request_rpt); | ||
| 139 | return $self->{_request_rpt}; | ||
| 140 | } | ||
| 141 | |||
| 142 | # @return string | ||
| 143 | sub getRequestPath | ||
| 144 | { | ||
| 145 | my( $self ) = @_; | ||
| 146 | return $self->{_request_path} | ||
| 147 | } | ||
| 148 | |||
| 149 | # @param null $request_path | ||
| 150 | # @return void | ||
| 151 | sub setRequestPath | ||
| 152 | { | ||
| 153 | my ( $self, $request_path ) = @_; | ||
| 154 | $self->{_request_path} = $request_path if defined($request_path); | ||
| 155 | return $self->{_request_path}; | ||
| 156 | } | ||
| 157 | |||
| 158 | # @return string | ||
| 159 | sub getRequestHttpMethod | ||
| 160 | { | ||
| 161 | my( $self ) = @_; | ||
| 162 | return $self->{_request_http_method} | ||
| 163 | } | ||
| 164 | |||
| 165 | |||
| 166 | # @param string $request_http_method | ||
| 167 | # @return void | ||
| 168 | sub setRequestHttpMethod | ||
| 169 | { | ||
| 170 | my ( $self, $request_http_method ) = @_; | ||
| 171 | $self->{_request_http_method} = $request_http_method if defined($request_http_method); | ||
| 172 | return $self->{_request_http_method}; | ||
| 173 | } | ||
| 174 | |||
| 175 | |||
| 176 | # @return string | ||
| 177 | sub getResponseAccess | ||
| 178 | { | ||
| 179 | my( $self ) = @_; | ||
| 180 | $self->{_response_access} = $self->getResponseData()->access; | ||
| 181 | return $self->{_response_access} | ||
| 182 | } | ||
| 183 | |||
| 184 | |||
| 185 | # Protocol command to oxd server | ||
| 186 | # @return void | ||
| 187 | sub setCommand | ||
| 188 | { | ||
| 189 | my ( $self ) = @_; | ||
| 190 | $self->{_command} = 'uma_rs_check_access'; | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | # Protocol parameter to oxd server | ||
| 195 | # @return void | ||
| 196 | sub setParams | ||
| 197 | { | ||
| 198 | my ( $self, $params ) = @_; | ||
| 199 | my $paramsArray = { | ||
| 200 | "oxd_id" => $self->getRequestOxdId(), | ||
| 201 | "rpt" => $self->getRequestRpt(), | ||
| 202 | "path" => $self->getRequestPath(), | ||
| 203 | "http_method" => $self->getRequestHttpMethod() | ||
| 204 | |||
| 205 | }; | ||
| 206 | $self->{_params} = $paramsArray; | ||
| 207 | return $self->{_params}; | ||
| 208 | |||
| 209 | } | ||
| 210 | |||
| 211 | 1; # this 1; is neccessary for our class to work |