saml_camel 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4ad1d62b323fe26e46a9a3a792d8135f1527cdb0baca5be3b0d3dee9269d9dc
4
- data.tar.gz: 3e541102a3ad4019bc2324ad5f0381ce139e8119c294ba9f8e9220748b342f57
3
+ metadata.gz: a85dd9e46209cb477da0b7519ef800d88796e6084a7c5679af77507f7209faba
4
+ data.tar.gz: 539f735329de875c9679f39862f20a6a608e4362ad0b06fcae941d7f17fbbd9e
5
5
  SHA512:
6
- metadata.gz: bdf5758464765a73a0ece1c6f6ed4046bbe345a574b4ea990dab8f821e89fe6c01db4be13dd0f5690c3c667269f8b48704d1dac8b9b257791d06f9ae5e3e19cc
7
- data.tar.gz: 6dd10093b2ffb277485400ca236cd4ab017c67cc0b626110c21bc43b654997f8671c03ca5e0144a53e97cf194312cca3bb8ecabbcb6095a669b1f5414ddb27a9
6
+ metadata.gz: 52102243981e4784384594b1799c6f9de96b9f7840ab8315fea0d7b004cdfd2c87629673af860f3240b53aa4b55cf4cb9b9d96d620a8c92939cfba90a826e71b
7
+ data.tar.gz: 208ad0581678d2a9f600786cd9acb25d3b0218fde684b03b1d7f5d98398caa419b6ad94f25c7d596ff0ca463c0a8c8cd5987ae3ccd10364c24da9813ebd333a7
data/README.md CHANGED
@@ -37,7 +37,7 @@ $ bundle
37
37
  config.cache_store = :memory_store
38
38
  ```
39
39
 
40
- **NOTE:** use the cache_store most appropriate for your situation. **It may make more sense to use a file store, or a redis server. If you are running an app accross multiple instances do not use memory_store**. For example it may not make sense to cache in memory in production. You can read more about rails caching behavior here http://guides.rubyonrails.org/caching_with_rails.html
40
+ **NOTE:** use the cache_store most appropriate for your situation. **It may make more sense to use a file store, or a redis server. If you are running an app across multiple instances do not use memory_store**. For example it may not make sense to cache in memory in production. You can read more about rails caching behavior here http://guides.rubyonrails.org/caching_with_rails.html
41
41
 
42
42
  2. run `rake saml_camel:generate_saml` to generate metadata files for the development, test, and production environment. You can also specify a custom environment like this `rake saml_camel:generate_saml environment=acceptance`
43
43
 
@@ -72,6 +72,22 @@ Identity Provider(idp) to recognize your app. Typically it should take the form
72
72
  end
73
73
  ```
74
74
 
75
+ 6. you can also pass in an optional `RelayState:` keyword argument to provide the RelayState parameter.
76
+ The relay state parameter will be played back to you in the response parameters from the idp. This can be useful if you want to redirect users to different endpoints after the response goes to the ACS.
77
+ ```ruby
78
+ class DashboardController < ApplicationController
79
+ before_action except: [:home] do
80
+ saml_protect(relay_state: "some-value-I-want-in-the-response")
81
+ end
82
+
83
+ def home
84
+ end
85
+
86
+ def index
87
+ end
88
+ end
89
+ ```
90
+
75
91
  7. to logout simply make a post to `localhost:3000/saml/logout`. This will kill the local saml session, and the session with the identity provider.
76
92
 
77
93
  7. response attributes found in `session[:saml_attributes]`
@@ -82,6 +98,9 @@ Identity Provider(idp) to recognize your app. Typically it should take the form
82
98
 
83
99
  9. Logging is turned on by default. Logging is configured in `config/saml/development/settings.json`. To utilize logging saml_logging should be set to true (default), and primary_id must have a value. primary_id is the saml attribute you consider to be a primary identifier for a user
84
100
 
101
+ 11. Clock drift can be adjusted by setting the `clock_drift` in `config/saml/development/settings.json`
102
+ The value should be an integer(which translates to seconds). For example a value of 60 will allow clock drift of 1 minute. It is recommended that if you set this value, it should be set as low as possible for security purposes.
103
+
85
104
 
86
105
  10. Convenience Endpoints (assuming enginte is mounted to `saml` path):
87
106
  - `/saml/attributes` view attributes being passed through
@@ -101,6 +120,7 @@ Identity Provider(idp) to recognize your app. Typically it should take the form
101
120
  "primary_id": "eduPersonPrincipalName",
102
121
  "sp_session_timeout": 1,
103
122
  "sp_session_lifetime": 8,
123
+ "clock_drift": false,
104
124
  "test_auth_path": true,
105
125
  "saml_logging": true,
106
126
  "debug": false,
@@ -17,7 +17,8 @@ module SamlCamel::SamlService # rubocop:disable Style/ClassAndModuleChildren
17
17
  end
18
18
 
19
19
  # TODO: refactor
20
- def saml_protect # rubocop:disable Metrics/MethodLength, Metrics/AbcSize:
20
+ def saml_protect(relay_state: nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize:
21
+ relay_state = relay_state ? "&RelayState=#{CGI.escape(relay_state)}" : ""
21
22
  #TODO move this
22
23
  begin
23
24
  settings = JSON.parse(File.read("config/saml/#{Rails.env}/settings.json"))
@@ -27,6 +28,8 @@ module SamlCamel::SamlService # rubocop:disable Style/ClassAndModuleChildren
27
28
  end
28
29
 
29
30
  user_cache = cache_available?(Rails.cache.fetch(session[:saml_session_id])) if session[:saml_session_id]
31
+
32
+ #user has an active saml_session_id and cache was found using that session id
30
33
  if session[:saml_session_id] && user_cache
31
34
  SamlCamel::Logging.debug('Saml Session and User Cache Found.') if sp_debug
32
35
  SamlCamel::Logging.debug("SAML session id: #{session[:saml_session_id]} | Cache: #{user_cache}") if sp_debug
@@ -35,14 +38,22 @@ module SamlCamel::SamlService # rubocop:disable Style/ClassAndModuleChildren
35
38
  saml_attributes: session[:saml_attributes]
36
39
  )
37
40
  session[:sp_session] = sp.validate_sp_session(session[:sp_session], request.remote_ip)
41
+
42
+ # run this if a user does not have an sp session, or if the response was a failure
38
43
  unless session[:saml_response_success] || session[:sp_session]
39
44
  SamlCamel::Logging.debug('SAML response not successful or no sp session not valid. Generating new request.') if sp_debug
40
45
  SamlCamel::Logging.debug("SAML response: #{session[:saml_response_success]}") if sp_debug
41
46
  SamlCamel::Logging.debug("SP session #{session[:sp_session]}") if sp_debug
47
+
48
+ session[:saml_session_id] = SamlCamel::ServiceProvider.generate_permit_key
49
+ saml_request_url = SamlCamel::ServiceProvider.new(
50
+ cache_permit_key: session[:saml_session_id].to_sym
51
+ ).generate_saml_request(request)
42
52
 
43
- saml_request_url = sp.generate_saml_request(request)
44
- redirect_to(saml_request_url)
53
+ redirect_to(saml_request_url + relay_state)
45
54
  end
55
+
56
+ # user did not have a saml_session_id and an active cache
46
57
  else
47
58
  SamlCamel::Logging.debug('User Cache or saml session id not found. Generating new request.') if sp_debug
48
59
  SamlCamel::Logging.debug("SAML session id: #{session[:saml_session_id]} | Cache: #{user_cache}") if sp_debug
@@ -51,7 +62,7 @@ module SamlCamel::SamlService # rubocop:disable Style/ClassAndModuleChildren
51
62
  saml_request_url = SamlCamel::ServiceProvider.new(
52
63
  cache_permit_key: session[:saml_session_id].to_sym
53
64
  ).generate_saml_request(request)
54
- redirect_to(saml_request_url)
65
+ redirect_to(saml_request_url + relay_state)
55
66
  end
56
67
  session[:saml_response_success] = nil # keeps us from looping
57
68
  end
@@ -25,13 +25,31 @@ module SamlCamel
25
25
 
26
26
  # ol OneLogin
27
27
  def self.ol_response(idp_response, raw_response: false)
28
+ clock_drift = set_clock_drift
28
29
  settings = SamlCamel::Transaction.saml_settings(raw_response: raw_response)
29
- response = OneLogin::RubySaml::Response.new(idp_response, settings: settings)
30
+ if clock_drift
31
+ response = OneLogin::RubySaml::Response.new(idp_response, settings: settings, allowed_clock_drift: clock_drift.second)
32
+ else
33
+ response = OneLogin::RubySaml::Response.new(idp_response, settings: settings)
34
+ end
30
35
  response.settings = settings
31
-
32
36
  response
33
37
  end
34
38
 
39
+ #if user configured clock drift, check configuration
40
+ # ruby saml default I "think" is 180 sec based of the java saml pull request https://github.com/onelogin/java-saml/issues/89
41
+ # however when I pulled the ruby-saml gem and searched the repo it looks like there is no clock drift by default
42
+ def self.set_clock_drift
43
+ clock_drift = SP_SETTINGS.dig('settings','clock_drift')
44
+ # clock drift must either be an integer of falsey
45
+ unless (clock_drift.class == Integer || clock_drift.class == Fixnum) || !clock_drift
46
+ SamlCamel::Logging.clock_drift(clock_drift)
47
+ raise "Clock Drift Incorrectly Configured."
48
+ end
49
+ clock_drift
50
+ end
51
+
52
+
35
53
  # TODO: method too complex
36
54
  def check_expired_session(sp_session) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/LineLength
37
55
  sp_timeout = SP_SETTINGS['settings']['sp_session_timeout']
@@ -117,6 +135,7 @@ module SamlCamel
117
135
  end
118
136
 
119
137
 
138
+
120
139
  # set saml_session lifetime, called if none set
121
140
  # TODO: this may need to be renamed, it's not really setting the lifetime
122
141
  # it's refreshing the last time a user authenticated
@@ -4,7 +4,11 @@ module SamlCamel
4
4
  # handle shib attributes
5
5
  class Shib
6
6
  if SP_SETTINGS.dig('settings','shib_module')
7
- ATTRIBUTE_MAP = JSON.parse(File.read('config/saml/shibboleth.json'))
7
+ if File.file?('config/saml/shibboleth.json') #keep backwards compatiblity
8
+ ATTRIBUTE_MAP = JSON.parse(File.read('config/saml/shibboleth.json'))
9
+ else
10
+ ATTRIBUTE_MAP = JSON.parse(File.read("config/saml/#{Rails.env}/settings.json"))["attribute_map"]
11
+ end
8
12
  end
9
13
 
10
14
  def self.attributes(request)
@@ -1,2 +1,4 @@
1
- <h1>Failure in SAML Response</h1>
2
- <h3><%= @error %></h3>
1
+ <div id="samlcamel-error-container">
2
+ <h1 id='samlcamel-error-head'>Failure in SAML Response</h1>
3
+ <h3 id='samlcamel-error-msg'><%= @error %></h3>
4
+ </div>
data/lib/saml_camel.rb CHANGED
@@ -87,6 +87,12 @@ module SamlCamel
87
87
  LOGGER.debug('Unknown Error During relay state logging. IP check') if SHOULD_LOG
88
88
  end
89
89
 
90
+ def self.clock_drift(clock_drift)
91
+ LOGGER.debug("Clock drift has not been configured. Must either be false, or an integer. Currently configured as #{clock_drift}(#{clock_drift.class})") if SHOULD_LOG
92
+ rescue StandardError
93
+ LOGGER.debug('Unknown Error During Debug') if SHOULD_LOG
94
+ end
95
+
90
96
  def self.debug(message)
91
97
  LOGGER.debug(message) if SHOULD_LOG
92
98
  rescue StandardError
@@ -108,6 +114,7 @@ module SamlCamel
108
114
  end
109
115
  end
110
116
 
117
+ #no occurances of this being used, may be able to remove? 10/17/2018
111
118
  def self.saml_state(data)
112
119
  if SHOULD_LOG
113
120
  LOGGER.info("Stored Relay: #{data[:stored_relay]} |
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SamlCamel
4
- VERSION = '1.0.6'
4
+ VERSION = '1.0.7'
5
5
  end
@@ -71,6 +71,7 @@ tA6SX0infqNRyPRNJK+bnQd1yOP4++tjD/lAPE+5tiD/waI3fArt43ZE/qp7pYMS
71
71
  primary_id: 'eduPersonPrincipalName',
72
72
  sp_session_timeout: 1,
73
73
  sp_session_lifetime: 8,
74
+ clock_drift: false,
74
75
  test_auth_path: true,
75
76
  saml_logging: true,
76
77
  debug: false,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saml_camel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'Danai Adkisson '
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-02 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails