oxd-ruby 0.1.9 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +16 -0
  4. data/README.md +3 -241
  5. data/lib/generators/oxd/templates/oxd_config.rb +5 -5
  6. data/lib/oxd-ruby.rb +3 -1
  7. data/lib/oxd/client_oxd_commands.rb +96 -109
  8. data/lib/oxd/config.rb +17 -15
  9. data/lib/oxd/errors.rb +33 -0
  10. data/lib/oxd/oxd_connector.rb +51 -49
  11. data/lib/oxd/uma_commands.rb +72 -35
  12. data/lib/oxd/version.rb +2 -1
  13. data/oxd-ruby.gemspec +2 -2
  14. metadata +8 -72
  15. data/demosite/.gitignore +0 -17
  16. data/demosite/Gemfile +0 -50
  17. data/demosite/Gemfile.lock +0 -197
  18. data/demosite/README.md +0 -172
  19. data/demosite/Rakefile +0 -6
  20. data/demosite/app/assets/images/.keep +0 -0
  21. data/demosite/app/assets/javascripts/application.js +0 -17
  22. data/demosite/app/assets/javascripts/bootstrap.js.coffee +0 -3
  23. data/demosite/app/assets/stylesheets/application.css +0 -16
  24. data/demosite/app/assets/stylesheets/bootstrap_and_overrides.css +0 -7
  25. data/demosite/app/controllers/application_controller.rb +0 -46
  26. data/demosite/app/controllers/concerns/.keep +0 -0
  27. data/demosite/app/controllers/home_controller.rb +0 -79
  28. data/demosite/app/controllers/uma_controller.rb +0 -40
  29. data/demosite/app/helpers/application_helper.rb +0 -2
  30. data/demosite/app/mailers/.keep +0 -0
  31. data/demosite/app/models/.keep +0 -0
  32. data/demosite/app/models/concerns/.keep +0 -0
  33. data/demosite/app/views/home/index.html.erb +0 -210
  34. data/demosite/app/views/layouts/application.html.erb +0 -14
  35. data/demosite/app/views/uma/index.html.erb +0 -123
  36. data/demosite/bin/bundle +0 -3
  37. data/demosite/bin/rails +0 -9
  38. data/demosite/bin/rake +0 -9
  39. data/demosite/bin/setup +0 -29
  40. data/demosite/bin/spring +0 -15
  41. data/demosite/config.ru +0 -4
  42. data/demosite/config/application.rb +0 -26
  43. data/demosite/config/boot.rb +0 -3
  44. data/demosite/config/database.yml +0 -25
  45. data/demosite/config/environment.rb +0 -5
  46. data/demosite/config/environments/development.rb +0 -41
  47. data/demosite/config/environments/production.rb +0 -79
  48. data/demosite/config/environments/test.rb +0 -42
  49. data/demosite/config/initializers/assets.rb +0 -11
  50. data/demosite/config/initializers/backtrace_silencers.rb +0 -7
  51. data/demosite/config/initializers/cookies_serializer.rb +0 -3
  52. data/demosite/config/initializers/filter_parameter_logging.rb +0 -4
  53. data/demosite/config/initializers/inflections.rb +0 -16
  54. data/demosite/config/initializers/mime_types.rb +0 -4
  55. data/demosite/config/initializers/oxd_config.rb +0 -25
  56. data/demosite/config/initializers/session_store.rb +0 -3
  57. data/demosite/config/initializers/wrap_parameters.rb +0 -14
  58. data/demosite/config/locales/en.bootstrap.yml +0 -23
  59. data/demosite/config/locales/en.yml +0 -23
  60. data/demosite/config/routes.rb +0 -76
  61. data/demosite/config/secrets.yml +0 -22
  62. data/demosite/db/seeds.rb +0 -7
  63. data/demosite/lib/assets/.keep +0 -0
  64. data/demosite/lib/tasks/.keep +0 -0
  65. data/demosite/log/.keep +0 -0
  66. data/demosite/public/404.html +0 -67
  67. data/demosite/public/422.html +0 -67
  68. data/demosite/public/500.html +0 -66
  69. data/demosite/public/favicon.ico +0 -0
  70. data/demosite/public/robots.txt +0 -5
  71. data/demosite/test/controllers/.keep +0 -0
  72. data/demosite/test/fixtures/.keep +0 -0
  73. data/demosite/test/helpers/.keep +0 -0
  74. data/demosite/test/integration/.keep +0 -0
  75. data/demosite/test/mailers/.keep +0 -0
  76. data/demosite/test/models/.keep +0 -0
  77. data/demosite/test/test_helper.rb +0 -10
  78. data/demosite/vendor/assets/javascripts/.keep +0 -0
  79. data/demosite/vendor/assets/stylesheets/.keep +0 -0
@@ -1,10 +1,10 @@
1
1
  require 'active_support/configurable'
2
2
 
3
3
  # @author Inderpal Singh
4
- # @note supports oxd-version 3.1.1
4
+ # @note supports oxd-version 3.1.2
5
5
  module Oxd
6
6
 
7
- # Configures global settings for Oxd
7
+ # Configures global settings for oxd
8
8
  # @yield config
9
9
  # @example
10
10
  # Oxd.configure do |config|
@@ -17,7 +17,7 @@ module Oxd
17
17
  end
18
18
  end
19
19
 
20
- # Global settings for Oxd
20
+ # Global settings for oxd
21
21
  def self.config
22
22
  @config
23
23
  end
@@ -32,7 +32,6 @@ module Oxd
32
32
  config_accessor :client_secret
33
33
  config_accessor :client_name
34
34
  config_accessor :authorization_redirect_uri
35
- config_accessor :logout_redirect_uri
36
35
  config_accessor :post_logout_redirect_uri
37
36
  config_accessor :scope
38
37
  config_accessor :grant_types
@@ -43,9 +42,8 @@ module Oxd
43
42
  config_accessor :client_token_endpoint_auth_method
44
43
  config_accessor :client_request_uris
45
44
  config_accessor :contacts
46
- config_accessor :client_logout_uris
45
+ config_accessor :client_frontchannel_logout_uris
47
46
  config_accessor :connection_type
48
- config_accessor :oxd_host
49
47
  config_accessor :dynamic_registration
50
48
  config_accessor :prompt
51
49
  config_accessor :id_token
@@ -56,6 +54,8 @@ module Oxd
56
54
  config_accessor :client_sector_identifier_uri
57
55
  config_accessor :ui_locales
58
56
  config_accessor :claims_locales
57
+ config_accessor :claims_redirect_uri
58
+ config_accessor :op_discovery_path
59
59
  config_accessor :protection_access_token
60
60
 
61
61
  # define param_name writer
@@ -68,17 +68,19 @@ module Oxd
68
68
  class_eval writer, __FILE__, line
69
69
  end
70
70
 
71
- #[oxd]
71
+ # ****** config to hold the information about the oxd module that has been deployed (host, port, etc.) ******
72
72
  # oxd_host_ip : the host is generally localhost as all communication are carried out between oxd-ruby and oxd server using sockets.
73
73
  # oxd_host_port: the port is the one which is configured during the oxd deployment
74
74
 
75
- #[client]
75
+ # ****** config to hold the information which are specific to website like the redirect uris ******
76
+ # op_host: Host URL of the OpenID Provider
76
77
  # application_type: the app_type is generally 'web' although 'native' can be used for native app
77
- # authorization_redirect_uri: [REQUIRED] this is the primary redirect URL of the website or app
78
- # => the first one is always your primary uri set in authorization_redirect_uri
78
+ # prompt: 'login' is required if you want to force alter current user session
79
+ # authorization_redirect_uri: [REQUIRED] Redirect uri to which user will be redirected after authorization
79
80
  # post_logout_redirect_uri: [OPTIONAL] website's public uri to call upon logout
80
- # client_logout_uris: [REQUIRED, LIST] logout uris of the client
81
- # grant_types: [OPTIONAL, LIST] grant types to "authorization_code" or "refresh_token"
81
+ # client_frontchannel_logout_uris: [REQUIRED, LIST] logout uris of the client which will be called by the OpenID provider when logout happens. This is a good place to clear session/cookies.
82
+ # grant_types: [OPTIONAL, LIST] grant types supported by the openid server, ["authorization_code", "client_credentials"]
83
+ # => 'client_credentials' is required for the UMA
82
84
  # acr_values: [OPTIONAL, LIST] the values are "basic" and "duo"
83
85
  # client_jwks_uri: [OPTIONAL]
84
86
  # client_token_endpoint_auth_method: [OPTIONAL]
@@ -94,8 +96,7 @@ module Oxd
94
96
  config.prompt = "login"
95
97
  config.authorization_redirect_uri = "https://gluu.example.com/callback"
96
98
  config.post_logout_redirect_uri = "https://gluu.example.com/logout"
97
- config.client_logout_uris = ["https://gluu.example.com/callback"]
98
- config.logout_redirect_uri = 'https://gluu.example.com/logout'
99
+ config.client_frontchannel_logout_uris = ["https://gluu.example.com/callback"]
99
100
  config.grant_types = []
100
101
  config.acr_values = ["basic"]
101
102
  config.client_jwks_uri = ""
@@ -110,8 +111,9 @@ module Oxd
110
111
  config.client_sector_identifier_uri = ""
111
112
  config.ui_locales = []
112
113
  config.claims_locales = []
114
+ config.claims_redirect_uri = []
115
+ config.op_discovery_path = ""
113
116
  config.protection_access_token = ""
114
- config.oxd_host = ""
115
117
  config.dynamic_registration = true
116
118
  config.connection_type = 'local'
117
119
  end
@@ -0,0 +1,33 @@
1
+ module Oxd
2
+ # Error raised by oxd-ruby whenever an oxd Server Error is reported
3
+ class ServerError < StandardError
4
+ def initialize(errorObj)
5
+ error_msg = "oxd Server Error: #{errorObj['error']}\n #{errorObj['error_description']}"
6
+ super(error_msg)
7
+ end
8
+ end
9
+
10
+ # Error raised when oxd-server returns "invalid_ticket" error for the `uma_rp_get_rpt` command.
11
+ class InvalidTicketError < StandardError
12
+ def initialize(errorObj)
13
+ error_msg = "Invalid Ticket Error: #{errorObj['error_description']}"
14
+ super(error_msg)
15
+ end
16
+ end
17
+
18
+ # Error raised when oxd-server returns a "need_info" error for the `uma_rp_get_rpt` command.
19
+ class NeedInfoError < StandardError
20
+ def initialize(errorObj)
21
+ error_msg = "#{errorObj}"
22
+ super(error_msg)
23
+ end
24
+ end
25
+
26
+ # Error raised when UMA RP does an `uma_rp_check_access` on unprotected resource and the oxd server returns 'invalid_request' response.
27
+ class InvalidRequestError < StandardError
28
+ def initialize(errorObj)
29
+ error_msg = "Invalid Request Error: #{errorObj['error_description']}"
30
+ super(error_msg)
31
+ end
32
+ end
33
+ end
@@ -5,10 +5,10 @@ require 'json'
5
5
  require 'uri'
6
6
 
7
7
  # @author Inderpal Singh
8
- # @note supports oxd-version 3.1.1
8
+ # @note supports oxd-version 3.1.2
9
9
  module Oxd
10
10
 
11
- # A class which takes care of the socket communication with oxD Server.
11
+ # A class which takes care of the socket communication with oxd Server.
12
12
  class OxdConnector
13
13
 
14
14
  # class constructor
@@ -21,52 +21,50 @@ module Oxd
21
21
  @response_data = Hash.new
22
22
  @configuration = Oxd.config
23
23
 
24
- logger(:log_msg => "Problem with json data : authorization_redirect_uri can't be blank") if @configuration.authorization_redirect_uri.empty?
25
- logger(:log_msg => "#{@configuration.oxd_host_ip} is not a valid IP address") if (IPAddr.new(@configuration.oxd_host_ip) rescue nil).nil?
26
- logger(:log_msg => "#{@configuration.oxd_host_port} is not a valid port for socket. Port must be integer and between from 0 to 65535") if (!@configuration.oxd_host_port.is_a?(Integer) || (@configuration.oxd_host_port < 0 && @configuration.oxd_host_port > 65535))
24
+ trigger_error("Problem with json data : authorization_redirect_uri can't be blank") if @configuration.authorization_redirect_uri.empty?
25
+ trigger_error("#{@configuration.oxd_host_ip} is not a valid IP address") if (IPAddr.new(@configuration.oxd_host_ip) rescue nil).nil?
26
+ trigger_error("#{@configuration.oxd_host_port} is not a valid port for socket. Port must be integer and between from 0 to 65535") if (!@configuration.oxd_host_port.is_a?(Integer) || (@configuration.oxd_host_port < 0 && @configuration.oxd_host_port > 65535))
27
27
  end
28
28
 
29
29
  # Checks the validity of command that is to be passed to oxd-server
30
30
  def validate_command
31
- command_types = ['setup_client', 'get_client_token', 'get_authorization_url','update_site_registration','get_tokens_by_code','get_access_token_by_refresh_token', 'get_user_info', 'register_site', 'get_logout_uri','get_authorization_code','uma_rs_protect','uma_rs_check_access','uma_rp_get_rpt','uma_rp_get_claims_gathering_url']
31
+ command_types = ['setup_client', 'get_client_token', 'introspect_access_token', 'get_authorization_url','update_site','remove_site','get_tokens_by_code','get_access_token_by_refresh_token', 'get_user_info', 'register_site', 'get_logout_uri','get_authorization_code','uma_rs_protect','uma_rs_check_access','uma_rp_get_rpt','uma_rp_get_claims_gathering_url','introspect_rpt']
32
32
  if (!command_types.include?(@command))
33
- logger(:log_msg => "Command: #{@command} does not exist! Exiting process.")
33
+ trigger_error("Command: #{@command} does not exist! Exiting process.")
34
34
  end
35
35
  end
36
36
 
37
- # method to communicate with the oxD server
37
+ # method to communicate with the oxd server
38
38
  # @param request [JSON] representation of the JSON command string
39
39
  # @param char_count [Integer] number of characters to read from response
40
- # @return response from the oxD Server
40
+ # @return response from the oxd Server
41
41
  def oxd_socket_request(request, char_count = 8192)
42
42
  host = @configuration.oxd_host_ip # The web server
43
43
  port = @configuration.oxd_host_port # Default HTTP port
44
44
 
45
- if(!socket = TCPSocket.new(host, port) ) # Connect to Oxd server
46
- logger(:log_msg => "Socket Error : Couldn't connect to socket ")
45
+ if(!socket = TCPSocket.new(host, port) ) # Connect to oxd server
46
+ trigger_error("Socket Error : Couldn't connect to socket")
47
47
  else
48
- logger(:log_msg => "Client: socket::socket_connect connected : #{request}", :error => "")
48
+ logger("Client: socket::socket_connect connected : #{request}")
49
49
  end
50
50
 
51
51
  socket.print(request) # Send request
52
52
  response = socket.recv(char_count) # Read response
53
53
  if(response)
54
- logger(:log_msg => "Client: oxd_socket_response: #{response}", :error => "")
54
+ logger("Client: oxd_socket_response: #{response}")
55
55
  else
56
- logger(:log_msg => "Client: oxd_socket_response : Error socket reading process.")
56
+ trigger_error("Client: oxd_socket_response : Error socket reading process.")
57
57
  end
58
58
  # close connection
59
59
  if(socket.close)
60
- logger(:log_msg => "Client: oxd_socket_connection : disconnected.", :error => "")
60
+ logger("Client: oxd_socket_connection : disconnected.")
61
61
  end
62
- #logger(:log_msg => response)
63
- #abort
64
62
  return response
65
63
  end
66
64
 
67
- # method to communicate with the oxD-to-http server
65
+ # method to communicate with the oxd-to-https server
68
66
  # @param request_params [JSON] representation of the JSON command string
69
- # @return response from the oxD-to-http server
67
+ # @return response from the oxd-to-https server
70
68
  def oxd_http_request(request_params, command = "")
71
69
  uri = URI.parse("https://127.0.0.1/"+command)
72
70
  http = Net::HTTP.new("127.0.0.1", 8443)
@@ -80,63 +78,67 @@ module Oxd
80
78
  request.add_field('Authorization','Bearer '+@configuration.protection_access_token)
81
79
  end
82
80
  request.body = request_params
83
- logger(:log_msg => "Sending oxd_http_request command #{command} with data #{request_params.inspect}", :error => "")
84
- response = http.request(request)
85
- response2 = response.body
86
- logger(:log_msg => "oxd_http_request response #{response2}", :error => "")
87
- return response2
81
+ logger("Sending oxd_http_request command #{command} with data #{request_params.inspect}")
82
+ http_response = http.request(request)
83
+ response = http_response.body
84
+ logger("oxd_http_request response #{response}")
85
+ return response
88
86
  end
89
87
 
90
88
  # @param comm [String] command string for oxd-to-http
91
- # method to send commands to the oxD server and oxd-to-http and to recieve the response via {#oxd_socket_request}
92
- # @return [JSON] @response_object : response from the oxd server in JSON form
89
+ # method to send commands to the oxd server and oxd-to-http and to recieve the response via {#oxd_socket_request}
90
+ # @return [JSON] response from the oxd server in JSON form
93
91
  def request(comm = "")
94
92
 
95
93
  uri = URI.parse(@configuration.authorization_redirect_uri)
96
- logger(:log_msg => "Please enable SSL on your website or check URIs in Oxd configuration.") if (uri.scheme != 'https')
94
+ trigger_error("Please enable SSL on your website or check URIs in oxd configuration.") if (uri.scheme != 'https')
97
95
  validate_command
98
96
 
99
97
  if(@configuration.connection_type == 'local')
100
98
  jsondata = getData.to_json
101
99
  if(!is_json? (jsondata))
102
- logger(:log_msg => "Sending parameters must be JSON. Exiting process.")
103
- end
100
+ trigger_error("Sending parameters must be JSON. Exiting process.")
101
+ end
104
102
  length = jsondata.length
105
103
  if( length <= 0 )
106
- logger(:log_msg => "JSON data length must be more than zero. Exiting process.")
104
+ trigger_error("JSON data length must be more than zero. Exiting process.")
107
105
  else
108
106
  length = length <= 999 ? sprintf('0%d', length) : length
109
107
  end
110
108
  @response_json = oxd_socket_request((length.to_s + jsondata).encode("UTF-8"))
111
109
  @response_json.sub!(@response_json[0..3], "")
112
110
  else
113
- jsondata = getData2.to_json
111
+ jsondata = @params.to_json
114
112
  @response_json = oxd_http_request(jsondata, comm)
115
113
  end
116
114
 
117
115
 
118
116
  if (@response_json)
119
117
  response = JSON.parse(@response_json)
120
- if (response['status'] == 'error')
121
- logger(:log_msg => "OxD Server Error : #{response['data']['error_description']}")
122
- elsif (response['status'] == 'ok')
123
-
118
+ if (response['status'] == 'error')
119
+ raise ServerError, response['data'] if response['data']['error'] == 'internal_error'
120
+ raise NeedInfoError, response['data'] if response['data']['error'] == 'need_info'
121
+ raise InvalidTicketError, response['data'] if response['data']['error'] == 'invalid_ticket'
122
+ raise InvalidRequestError, response['data'] if response['data']['error'] == 'invalid_request'
123
+
124
+ trigger_error("oxd Server Error : #{response['data']['error_description']}")
125
+ elsif (response['status'] == 'ok')
124
126
  @response_object = JSON.parse(@response_json)
125
127
  end
126
128
  else
127
- logger(:log_msg => "Response is empty. Exiting process.")
129
+ trigger_error("Response is empty. Exiting process.")
128
130
  end
129
131
 
130
132
  return @response_object
131
133
  end
132
134
 
133
- # @return [Mixed] @response_object set by request method
135
+ # @return [Mixed] response object set by request method
134
136
  def getResponseObject
135
137
  return @response_object
136
138
  end
137
139
 
138
- # extracts 'data' parameter from @response_object
139
- # @return [Mixed] @response_data
140
+ # extracts 'data' parameter from response object
141
+ # @return [Mixed] response data
140
142
  def getResponseData
141
143
  if (!@response_object)
142
144
  @response_data = 'Data is empty';
@@ -153,11 +155,6 @@ module Oxd
153
155
  return @data
154
156
  end
155
157
 
156
- def getData2
157
- @data = @params
158
- return @data
159
- end
160
-
161
158
  # checks whether the passed string is in JSON format or not
162
159
  # @param string_to_validate [String]
163
160
  # @return [Boolean]
@@ -170,15 +167,20 @@ module Oxd
170
167
  end
171
168
 
172
169
  # Logs server response and errors to log file
173
- # @param args [Hash] {:log_msg, :error} response to print in log file and raise error
170
+ # @param log_msg [String], response to print in log file and raise error
174
171
  # @raise RuntimeError
175
- def logger(args={})
172
+ def logger(log_msg)
176
173
  # Initialize Log file
177
174
  # Location : app_root/log/oxd-ruby.log
178
175
  @logger ||= Logger.new("log/oxd-ruby.log")
179
- @logger.info(args[:log_msg])
176
+ @logger.info(log_msg)
177
+ end
180
178
 
181
- raise (args[:error] || args[:log_msg]) if args[:error] != ""
182
- end
179
+ # Logs generated errors to log file
180
+ # @raise RuntimeError
181
+ def trigger_error(msg)
182
+ logger(msg)
183
+ raise msg
184
+ end
183
185
  end
184
186
  end
@@ -1,5 +1,5 @@
1
1
  # @author Inderpal Singh
2
- # @note supports oxd-version 3.1.1
2
+ # @note supports oxd-version 3.1.2
3
3
  module Oxd
4
4
 
5
5
  require 'json'
@@ -13,13 +13,52 @@ module Oxd
13
13
  super
14
14
  end
15
15
 
16
+ # default params to send with every request
17
+ def default_params
18
+ defaults = {
19
+ "oxd_id" => @configuration.oxd_id,
20
+ "protection_access_token" => @configuration.protection_access_token
21
+ }
22
+ end
23
+
16
24
  # @param path [STRING] REQUIRED
17
25
  # @param conditions [HASH] REQUIRED (variable number of conditions can be passed)
18
26
  # @return [ARRAY] resources
19
- # @example
20
- # condition1 = {:httpMethods => ["GET"], :scopes => ["http://photoz.example.com/dev/actions/view"]}
21
- # condition2 = {:httpMethods => ["PUT", "POST"], :scopes => ["http://photoz.example.com/dev/actions/all","http://photoz.example.com/dev/actions/add"],:ticketScopes => ["http://photoz.example.com/dev/actions/add"]}
27
+ # @example : 1
28
+ # condition1 = {
29
+ # :httpMethods => ["GET"],
30
+ # :scopes => ["http://photoz.example.com/dev/actions/view"]
31
+ # }
32
+ # condition2 = {
33
+ # :httpMethods => ["PUT", "POST"],
34
+ # :scopes => [
35
+ # "http://photoz.example.com/dev/actions/all",
36
+ # "http://photoz.example.com/dev/actions/add"
37
+ # ],
38
+ # :ticketScopes => ["http://photoz.example.com/dev/actions/add"]
39
+ # }
22
40
  # uma_add_resource("/photo", condition1, condition2)
41
+ #
42
+ # @example : 2 (with scope expressions)
43
+ # condition = {
44
+ # :httpMethods => ["GET"],
45
+ # :scope_expression => {
46
+ # :rule => {
47
+ # :and => [
48
+ # {
49
+ # :or => [{:var => 0}, {:var => 1}]
50
+ # },
51
+ # {:var => 2}
52
+ # ]
53
+ # },
54
+ # :data => [
55
+ # "http://photoz.example.com/dev/actions/all",
56
+ # "http://photoz.example.com/dev/actions/add",
57
+ # "http://photoz.example.com/dev/actions/internalClient"
58
+ # ]
59
+ # }
60
+ # }
61
+ # uma_add_resource("/photo", condition)
23
62
  # combines multiple resources into @resources array to pass to uma_rs_protect method
24
63
  def uma_add_resource(path, *conditions)
25
64
  @resources.push({:path => path, :conditions => conditions})
@@ -29,14 +68,10 @@ module Oxd
29
68
  # @raise RuntimeError if @resources is nil
30
69
  # method to protect resources with UMA resource server
31
70
  def uma_rs_protect
32
- logger(:log_msg => "Please set resources with uma_add_resource(path, *conditions) method first.") if(@resources.nil?)
33
- logger(:log_msg => "UMA configuration #{@configuration}", :error => '')
71
+ trigger_error("Please set resources with uma_add_resource(path, *conditions) method first.") if(@resources.nil?)
72
+ logger("UMA configuration #{@configuration}")
34
73
  @command = 'uma_rs_protect'
35
- @params = {
36
- "oxd_id" => @configuration.oxd_id,
37
- "resources" => @resources,
38
- "protection_access_token" => @configuration.protection_access_token
39
- }
74
+ @params = default_params.merge({ "resources" => @resources })
40
75
  request('uma-rs-protect')
41
76
  getResponseData['oxd_id']
42
77
  end
@@ -49,25 +84,24 @@ module Oxd
49
84
  # @param state [STRING] OPTIONAL, state that is returned from uma_rp_get_claims_gathering_url command
50
85
  # @return [Hash] response data (access_token, token_type, pct, upgraded)
51
86
  # method for obtaining RPT to gain access to protected resources at the UMA resource server
52
- def uma_rp_get_rpt( claim_token = nil, claim_token_format = nil, pct = nil, rpt = nil, scope = nil, state = nil )
87
+ def uma_rp_get_rpt( claim_token: nil, claim_token_format: nil, pct: nil, rpt: nil, scope: nil, state: nil )
53
88
  @command = 'uma_rp_get_rpt'
54
- @params = {
55
- "oxd_id" => @configuration.oxd_id,
89
+ @params = default_params.merge({
56
90
  "ticket" => @configuration.ticket,
57
91
  "claim_token" => claim_token,
58
92
  "claim_token_format" => claim_token_format,
59
93
  "pct" => pct,
60
94
  "rpt" => (!rpt.nil?)? rpt : @configuration.rpt,
61
95
  "scope" => scope,
62
- "state" => state,
63
- "protection_access_token" => @configuration.protection_access_token
64
- }
96
+ "state" => state
97
+ })
65
98
  request('uma-rp-get-rpt')
66
99
 
67
100
  if getResponseData['error'] == 'need_info' && !getResponseData['details']['ticket'].empty?
68
- @configuration.ticket = getResponseData['details']['ticket']
101
+ @configuration.ticket = getResponseData['details']['ticket']
102
+ else
103
+ @configuration.rpt = getResponseData['access_token']
69
104
  end
70
-
71
105
  getResponseData
72
106
  end
73
107
 
@@ -77,21 +111,17 @@ module Oxd
77
111
  # method to check if we have permission to access particular resource or not
78
112
  def uma_rs_check_access(path, http_method)
79
113
  if (path.empty? || http_method.empty? || (!['GET', 'POST', 'PUT', 'DELETE'].include? http_method))
80
- logger(:log_msg => "Empty/Wrong value in place of path or http_method.")
114
+ trigger_error("Empty/Wrong value in place of path or http_method.")
81
115
  end
82
116
  @command = 'uma_rs_check_access'
83
- @params = {
84
- "oxd_id" => @configuration.oxd_id,
117
+ @params = default_params.merge({
85
118
  "rpt" => @configuration.rpt,
86
119
  "path" => path,
87
- "http_method" => http_method,
88
- "protection_access_token" => @configuration.protection_access_token
89
- }
120
+ "http_method" => http_method
121
+ })
90
122
  request('uma-rs-check-access')
91
123
  if getResponseData['access'] == 'denied' && !getResponseData['ticket'].empty?
92
- @configuration.ticket = getResponseData['ticket']
93
- elsif getResponseData['access'] == 'granted'
94
- @configuration.ticket = ""
124
+ @configuration.ticket = getResponseData['ticket']
95
125
  end
96
126
  getResponseData
97
127
  end
@@ -101,17 +131,24 @@ module Oxd
101
131
  # method to check if we have permission to access particular resource or not
102
132
  def uma_rp_get_claims_gathering_url( claims_redirect_uri )
103
133
  if (claims_redirect_uri.empty?)
104
- logger(:log_msg => "Empty/Wrong value in place of claims_redirect_uri.")
134
+ trigger_error("Empty/Wrong value in place of claims_redirect_uri.")
105
135
  end
106
136
  @command = 'uma_rp_get_claims_gathering_url'
107
- @params = {
108
- "oxd_id" => @configuration.oxd_id,
137
+ @params = default_params.merge({
109
138
  "ticket" => @configuration.ticket,
110
- "claims_redirect_uri" => claims_redirect_uri,
111
- "protection_access_token" => @configuration.protection_access_token
112
- }
139
+ "claims_redirect_uri" => claims_redirect_uri
140
+ })
113
141
  request('uma-rp-get-claims-gathering-url')
142
+ getResponseData["url"]
143
+ end
144
+
145
+ # @return [OBJECT] @response_data
146
+ # method to gain information about obtained RPT
147
+ def introspect_rpt
148
+ @command = 'introspect_rpt'
149
+ @params = default_params.merge({ "rpt" => @configuration.rpt })
150
+ request('introspect-rpt')
114
151
  getResponseData
115
- end
152
+ end
116
153
  end
117
154
  end