tuwien_logon 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -0,0 +1,38 @@
1
+ module TuwienLogon
2
+ module Authentication
3
+ def authenticated?(params)
4
+ raise 'You must provide at least a user_id, a host and an skey' unless params[:user_id] && params[:host] && params[:skey]
5
+
6
+ secret = params[:secret] || TuwienLogon.config.secret
7
+ tolerance = params[:time_tolerance] || TuwienLogon.config.time_tolerance
8
+ offset = params[:server_time_offset] || TuwienLogon.config.server_time_offset
9
+ time = params[:time] || Time.now
10
+
11
+ auth = Authentication.new params[:user_id], params[:host], secret, tolerance, time + offset
12
+ auth.valid? params[:skey]
13
+ end
14
+
15
+ class Authentication
16
+ attr_accessor :user_id, :client_host_name, :secret, :timestamp, :tolerance
17
+
18
+ def initialize(user_id, client_host_name, secret, tolerance=0, timestamp=Time.now)
19
+ @user_id = user_id.to_s
20
+ @client_host_name = client_host_name.downcase
21
+ @secret= secret.to_s
22
+ @timestamp = timestamp.to_i / 10
23
+ @tolerance = tolerance
24
+ end
25
+
26
+ def skey(time_offset = 0)
27
+ Digest::SHA1.hexdigest(user_id + (timestamp + time_offset).to_s + client_host_name + secret)
28
+ end
29
+
30
+ def valid?(skey_to_check)
31
+ (-tolerance..tolerance).each do |time_offset|
32
+ return true if skey(time_offset) == skey_to_check
33
+ end
34
+ false
35
+ end
36
+ end
37
+ end
38
+ end
@@ -4,10 +4,9 @@ module TuwienLogon
4
4
  class Configuration
5
5
  include Singleton
6
6
 
7
- attr_accessor :authentication_url, :user_info_url, :secret, :user_info_params, :time_tolerance, :server_time_offset
7
+ attr_accessor :user_info_url, :secret, :user_info_params, :time_tolerance, :server_time_offset
8
8
 
9
9
  def initialize
10
- @authentication_url = 'https://iu.zid.tuwien.ac.at/AuthServ.authenticate'
11
10
  @user_info_url = 'https://iu.zid.tuwien.ac.at/AuthServ.userInfo'
12
11
  @secret = '123456'
13
12
  @user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
data/lib/tuwien_logon.rb CHANGED
@@ -6,5 +6,9 @@ module TuwienLogon
6
6
  def config
7
7
  TuwienLogon::Configuration.instance
8
8
  end
9
+
10
+ def configuration
11
+ yield config
12
+ end
9
13
  end
10
14
  end
data/test/helper.rb CHANGED
@@ -8,7 +8,6 @@ require 'tuwien_logon'
8
8
 
9
9
  class Test::Unit::TestCase
10
10
  def setup
11
- TuwienLogon.config.authentication_url = 'http://localhost:4567/AuthServ.authenticate'
12
11
  TuwienLogon.config.user_info_url = 'http://localhost:4567/AuthServ.userInfo'
13
12
  TuwienLogon.config.secret = '123456'
14
13
  TuwienLogon.config.user_info_params = [:oid, :firstname, :lastname, :title, :matriculation_number, :institute_symbol]
@@ -1,21 +1,17 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestTuwienLogon < Test::Unit::TestCase
4
- should "set the authentication url correctly" do
5
- url = 'abc'
6
- TuwienLogon.config.authentication_url = url
7
- assert_equal url, TuwienLogon.config.authentication_url
8
- end
9
-
10
- should "set the user info url correctly" do
4
+ should "set the user info url url directly" do
11
5
  url = 'abc'
12
6
  TuwienLogon.config.user_info_url = url
13
7
  assert_equal url, TuwienLogon.config.user_info_url
14
8
  end
15
9
 
16
- should "set the secret correctly" do
10
+ should "set the user info url url by a block" do
17
11
  url = 'abc'
18
- TuwienLogon.config.secret = url
19
- assert_equal url, TuwienLogon.config.secret
12
+ TuwienLogon.configuration do |config|
13
+ config.user_info_url = url
14
+ end
15
+ assert_equal url, TuwienLogon.config.user_info_url
20
16
  end
21
17
  end
data/tuwien_logon.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tuwien_logon}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Clemens Helm"]
@@ -24,10 +24,12 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "lib/tuwien_logon.rb",
27
+ "lib/tuwien_logon/authentication.rb",
27
28
  "lib/tuwien_logon/configuration.rb",
28
29
  "lib/tuwien_logon/user_info.rb",
29
30
  "lib/tuwien_logon/user_info_request.rb",
30
31
  "test/helper.rb",
32
+ "test/test_authentication.rb",
31
33
  "test/test_tuwien_logon.rb",
32
34
  "test/test_user_info.rb",
33
35
  "test/test_user_info_request.rb",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Clemens Helm
@@ -46,10 +46,12 @@ files:
46
46
  - Rakefile
47
47
  - VERSION
48
48
  - lib/tuwien_logon.rb
49
+ - lib/tuwien_logon/authentication.rb
49
50
  - lib/tuwien_logon/configuration.rb
50
51
  - lib/tuwien_logon/user_info.rb
51
52
  - lib/tuwien_logon/user_info_request.rb
52
53
  - test/helper.rb
54
+ - test/test_authentication.rb
53
55
  - test/test_tuwien_logon.rb
54
56
  - test/test_user_info.rb
55
57
  - test/test_user_info_request.rb