rack-saml 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 814e3162772ca1b7deea5751c77af1fa07b969c4
4
- data.tar.gz: 7ead1385a2a3b93c4e74b269d2f764bca77c8bce
3
+ metadata.gz: 351da5cbd3ac2dee0229017a33144a4263d1ed2d
4
+ data.tar.gz: 71724a4318c0f7765f32346bcfa0e61ad7b017fc
5
5
  SHA512:
6
- metadata.gz: 06a068a3c5ae379525c365abf7096dec77013be2d722e66baf62019135d93297258b25af3a805b283139d01e125dfb834c5dfe1f47f6d23c7f3f169c15889abb
7
- data.tar.gz: 71382a6922efbeb60ce3284720c114a1e2e1764ab03115857cb0fed51f2059488413628199c116f09e3bd49aeac4156fa1027fa3026a1cbaf0ca12319fc5b234
6
+ metadata.gz: 9a70cc5feb6435a22310849406420d3ad3fc8faab1e0f1218c38656d428ae89b0141d96c1f8125787d588ffb8b2b617c43ce7274c8b183ce862c2a4a55a5beff
7
+ data.tar.gz: 062c93f2dc4060cbe67dcd86dfd5947efaade19dff67689372307cf1d178b79e84dbc5a967c374e368a804324459757fc7cc46716fe7a5d2eb18c4cb31099fba
@@ -1,6 +1,5 @@
1
- require 'rack'
2
1
  module Rack
3
2
  module Saml
4
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
5
4
  end
6
5
  end
data/lib/rack/saml.rb CHANGED
@@ -18,15 +18,15 @@ module Rack
18
18
  # 'rack_saml' => {
19
19
  # 'ds.session' => {
20
20
  # 'sid' => temporally_generated_hash,
21
- # 'expires_at' => xxxxx # timestamp
21
+ # 'expires' => xxxxx # timestamp (string)
22
22
  # }
23
23
  # 'saml_authreq.session' => {
24
24
  # 'sid' => temporally_generated_hash,
25
- # 'expires_at' => xxxxx # timestamp
25
+ # 'expires' => xxxxx # timestamp (string)
26
26
  # }
27
27
  # 'saml_res.session' => {
28
28
  # 'sid' => temporally_generated_hash,
29
- # 'expires_at' => xxxxx # timestamp,
29
+ # 'expires' => xxxxx, # timestamp (string)
30
30
  # 'env' => {}
31
31
  # }
32
32
  # }
@@ -39,41 +39,35 @@ module Rack
39
39
  class ValidationError < StandardError
40
40
  end
41
41
 
42
+ FILE_TYPE = [:config, :metadata, :attribute_map]
43
+ FILE_NAME = {
44
+ :config => 'rack-saml.yml',
45
+ :metadata => 'metadata.yml',
46
+ :attribute_map => 'attribute-map.yml'
47
+ }
48
+
42
49
  def default_config_path(config_file)
43
50
  ::File.expand_path("../../../config/#{config_file}", __FILE__)
44
51
  end
45
52
 
46
- def default_config
47
- default_config_path('rack-saml.yml')
48
- end
49
-
50
- def default_metadata
51
- default_config_path('metadata.yml')
52
- end
53
-
54
- def default_attribute_map
55
- default_config_path('attribute-map.yml')
53
+ def load_file(type)
54
+ if @opts[type].nil? || !::File.exists?(@opts[type])
55
+ @opts[type] = default_config_path(FILE_NAME[type])
56
+ end
57
+ eval "@#{type} = YAML.load_file(@opts[:#{type}])"
56
58
  end
57
59
 
58
60
  def initialize app, opts = {}
59
61
  @app = app
60
62
  @opts = opts
61
63
 
62
- if @opts[:config].nil? || !::File.exists?(@opts[:config])
63
- @opts[:config] = default_config
64
+ FILE_TYPE.each do |type|
65
+ load_file(type)
64
66
  end
65
- @config = YAML.load_file(@opts[:config])
67
+
66
68
  if @config['assertion_handler'].nil?
67
69
  raise ArgumentError, "'assertion_handler' parameter should be specified in the :config file"
68
70
  end
69
- if @opts[:metadata].nil? || !::File.exists?(@opts[:metadata])
70
- @opts[:metadata] = default_metadata
71
- end
72
- @metadata = YAML.load_file(@opts[:metadata])
73
- if @opts[:attribute_map].nil? || !::File.exists?(@opts[:attribute_map])
74
- @opts[:attribute_map] = default_attribute_map
75
- end
76
- @attribute_map = YAML.load_file(@opts[:attribute_map])
77
71
  end
78
72
 
79
73
  class Session
@@ -102,7 +96,7 @@ module Rack
102
96
  def start(type, timeout = 300)
103
97
  sid = nil
104
98
  if timeout.nil?
105
- period = nil
99
+ period = Time.now + 300
106
100
  else
107
101
  period = Time.now + timeout
108
102
  end
@@ -115,7 +109,7 @@ module Rack
115
109
  sid = generate_sid
116
110
  end
117
111
  @session["#{type}.session"]['sid'] = sid
118
- @session["#{type}.session"]['expires_at'] = period
112
+ @session["#{type}.session"]['expires'] = period.to_s
119
113
  @session["#{type}.session"]
120
114
  end
121
115
 
@@ -130,11 +124,11 @@ module Rack
130
124
  def is_valid?(type, sid = nil)
131
125
  session = @session["#{type}.session"]
132
126
  return false if session['sid'].nil? # no valid session
133
- if session['expires_at'].nil? # no expiration
127
+ if session['expires'].nil? # no expiration
134
128
  return true if sid.nil? # no sid check
135
129
  return true if session['sid'] == sid # sid check
136
130
  else
137
- if Time.now < Time.parse(session['expires_at'].to_s) # before expiration
131
+ if Time.now < Time.parse(session['expires']) # before expiration
138
132
  return true if sid.nil? # no sid check
139
133
  return true if session['sid'] == sid # sid check
140
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-saml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyokazu Akiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack