relevance-rubycas-server 0.6.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.loadpath +5 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.txt +1 -0
  4. data/History.txt +223 -0
  5. data/LICENSE.txt +504 -0
  6. data/Manifest.txt +61 -0
  7. data/README.txt +25 -0
  8. data/Rakefile +60 -0
  9. data/bin/rubycas-server +26 -0
  10. data/bin/rubycas-server-ctl +22 -0
  11. data/config.example.yml +363 -0
  12. data/custom_views.example.rb +11 -0
  13. data/lib/casserver.rb +110 -0
  14. data/lib/casserver/authenticators/active_directory_ldap.rb +11 -0
  15. data/lib/casserver/authenticators/base.rb +47 -0
  16. data/lib/casserver/authenticators/ldap.rb +108 -0
  17. data/lib/casserver/authenticators/ntlm.rb +88 -0
  18. data/lib/casserver/authenticators/sql.rb +102 -0
  19. data/lib/casserver/authenticators/sql_encrypted.rb +75 -0
  20. data/lib/casserver/authenticators/test.rb +15 -0
  21. data/lib/casserver/cas.rb +307 -0
  22. data/lib/casserver/conf.rb +112 -0
  23. data/lib/casserver/controllers.rb +436 -0
  24. data/lib/casserver/environment.rb +23 -0
  25. data/lib/casserver/models.rb +218 -0
  26. data/lib/casserver/postambles.rb +174 -0
  27. data/lib/casserver/utils.rb +30 -0
  28. data/lib/casserver/version.rb +9 -0
  29. data/lib/casserver/views.rb +235 -0
  30. data/lib/rubycas-server.rb +1 -0
  31. data/lib/rubycas-server/version.rb +1 -0
  32. data/lib/themes/cas.css +121 -0
  33. data/lib/themes/notice.png +0 -0
  34. data/lib/themes/ok.png +0 -0
  35. data/lib/themes/simple/bg.png +0 -0
  36. data/lib/themes/simple/login_box_bg.png +0 -0
  37. data/lib/themes/simple/logo.png +0 -0
  38. data/lib/themes/simple/theme.css +28 -0
  39. data/lib/themes/urbacon/bg.png +0 -0
  40. data/lib/themes/urbacon/login_box_bg.png +0 -0
  41. data/lib/themes/urbacon/logo.png +0 -0
  42. data/lib/themes/urbacon/theme.css +33 -0
  43. data/lib/themes/warning.png +0 -0
  44. data/misc/basic_cas_single_signon_mechanism_diagram.png +0 -0
  45. data/misc/basic_cas_single_signon_mechanism_diagram.svg +652 -0
  46. data/resources/init.d.sh +58 -0
  47. data/setup.rb +1585 -0
  48. data/test/test_cas.rb +33 -0
  49. data/test/test_casserver.rb +125 -0
  50. data/vendor/isaac_0.9.1/LICENSE +26 -0
  51. data/vendor/isaac_0.9.1/README +78 -0
  52. data/vendor/isaac_0.9.1/TODO +3 -0
  53. data/vendor/isaac_0.9.1/VERSIONS +3 -0
  54. data/vendor/isaac_0.9.1/crypt/ISAAC.rb +171 -0
  55. data/vendor/isaac_0.9.1/isaac.gemspec +39 -0
  56. data/vendor/isaac_0.9.1/setup.rb +596 -0
  57. data/vendor/isaac_0.9.1/test/TC_ISAAC.rb +76 -0
  58. metadata +158 -0
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'mosquito'
3
+
4
+ $CONF = {:authenticator => {:class => "CASServer::Authenticators::Test"},
5
+ :log => {:file => "/tmp/test.log", :level => "INFO"}}
6
+
7
+ require File.dirname(__FILE__) + "/../lib/casserver"
8
+
9
+ CASServer.create
10
+
11
+ class TestCASServer < Camping::UnitTest
12
+
13
+ include CASServer::CAS
14
+
15
+ def test_generate_proxy_granting_ticket
16
+ pgt_url = "https://portal.urbacon.net:6543/cas_proxy_callback/receive_pgt"
17
+ st = generate_service_ticket("http://test.foo", "tester")
18
+
19
+ pgt = nil
20
+
21
+ assert_difference(ProxyGrantingTicket, :count, 1) do
22
+ pgt = generate_proxy_granting_ticket(pgt_url, st)
23
+ end
24
+
25
+ puts pgt.inspect
26
+ end
27
+
28
+ protected
29
+ def env
30
+ return {'REMOTE_ADDR' => "TEST"}
31
+ end
32
+
33
+ end
@@ -0,0 +1,125 @@
1
+ require 'rubygems'
2
+ require 'mosquito'
3
+
4
+ $CONF = {:authenticator => {:class => "CASServer::Authenticators::Test"}}
5
+
6
+ require File.dirname(__FILE__) + "/../lib/casserver"
7
+
8
+ include CASServer::Models
9
+ CASServer.create
10
+
11
+ class TestCASServer < Camping::FunctionalTest
12
+
13
+ def test_test_atuhenticator
14
+ require File.dirname(__FILE__) + "/../lib/casserver/authenticators/test"
15
+
16
+ valid_credentials = {:username => "testuser", :password => "testpassword"}
17
+ invalid_credentials = {:username => "asdfsdf", :password => "asdfsdf"}
18
+
19
+ assert_equal CASServer::Authenticators::Test, $AUTH.class
20
+ assert $AUTH.validate(valid_credentials)
21
+ assert !$AUTH.validate(invalid_credentials)
22
+ end
23
+
24
+ def test_valid_login
25
+ lt = start_login
26
+
27
+ post '/login',
28
+ :lt => lt.ticket,
29
+ :username => "testuser",
30
+ :password => "testpassword"
31
+
32
+ assert_match_body("You have successfully logged in")
33
+
34
+ lt = LoginTicket.find_by_ticket(lt.ticket)
35
+
36
+ assert_not_nil @cookies[:tgt]
37
+ assert_not_nil TicketGrantingTicket.find_by_ticket(@cookies[:tgt])
38
+
39
+ assert lt.consumed?
40
+ end
41
+
42
+ def test_valid_login_with_service
43
+ lt = start_login
44
+
45
+ fake_service = "http://www.google.com/"
46
+
47
+ post '/login',
48
+ :lt => lt.ticket,
49
+ :username => "testuser",
50
+ :password => "testpassword",
51
+ :service => fake_service
52
+
53
+ @response.headers['Location'].to_s =~ /(.*?)\?ticket=(.*)/
54
+ redirected_to = $~[1]
55
+ service_ticket = $~[2]
56
+
57
+ assert_equal fake_service, redirected_to
58
+
59
+ assert_not_nil service_ticket
60
+ st = ServiceTicket.find_by_ticket(service_ticket)
61
+ assert_equal fake_service, st.service
62
+ assert_equal "testuser", st.username
63
+ assert !st.consumed?
64
+
65
+ assert_not_nil @cookies[:tgt]
66
+ assert_not_nil TicketGrantingTicket.find_by_ticket(@cookies[:tgt])
67
+
68
+ assert LoginTicket.find_by_ticket(lt.ticket).consumed?
69
+ end
70
+
71
+ def test_invalid_login
72
+ lt = start_login
73
+
74
+ post '/login',
75
+ :lt => lt.ticket,
76
+ :username => "testuser",
77
+ :password => "badpassword"
78
+
79
+ assert_match_body("Incorrect username or password")
80
+
81
+ # reusing the same login ticket should fail
82
+ post '/login',
83
+ :lt => lt.ticket,
84
+ :username => "testuser",
85
+ :password => "testpassword"
86
+
87
+ assert_match_body("The login ticket you provided has already been used up")
88
+
89
+ # missing username/password
90
+ lt = start_login
91
+ post '/login',
92
+ :lt => lt.ticket
93
+
94
+ assert_match_body("Incorrect username or password")
95
+
96
+ # missing login ticket
97
+ post '/login',
98
+ :username => "testuser",
99
+ :password => "testpassword"
100
+
101
+ assert_match_body("Your login request did not include a login ticket")
102
+ end
103
+
104
+ private
105
+ def start_login
106
+ assert_difference(LoginTicket, :count, 1) do
107
+ get '/login'
108
+ end
109
+
110
+ assert_response :success
111
+ assert_match_body("Login")
112
+
113
+ @response.body =~ /LT-[a-zA-Z0-9]*/
114
+ lt = $~[0]
115
+ assert_not_nil lt
116
+
117
+ lt = LoginTicket.find_by_ticket(lt)
118
+ assert_not_nil lt
119
+
120
+ assert !lt.consumed?
121
+
122
+ lt
123
+ end
124
+
125
+ end
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2004 - 2005 Kirk Haines (khaines@enigo.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ For details about the ISAAC algorithm itself, see:
15
+
16
+ http://burtleburtle.net/bob/rand/isaac.html
17
+
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
@@ -0,0 +1,78 @@
1
+ Crypt::ISAAC README
2
+ ============
3
+
4
+ ISAAC is a cryptographically secure PRNG for generating high quality random
5
+ numbers. Detailed information about the algorithm can be found at:
6
+
7
+ http://burtleburtle.net/bob/rand/isaac.html
8
+
9
+ This is a pure Ruby implementation of the algorithm. It is reasonably fast for
10
+ a pure Ruby implementation. On an 800Mhz PIII computer running Ruby 1.8.2,
11
+ and while the machine is also serving as general desktop, the library seems to
12
+ consistently generate between 15000 and 16000 random numbers per second.
13
+
14
+ Ruby uses the Mersenne Twister as its PRNG, and while this the Twister is
15
+ a fast PRNG that produces highly random numbers, it is not strong for
16
+ cryptographic purposes, nor is it suitable when one needs multiple
17
+ independent streams of random numbers. Crypt::ISAAC is suitable for either
18
+ purpose.
19
+
20
+
21
+ Requirements
22
+ ------------
23
+
24
+ * Ruby 1.8 (should also run on 1.6.x)
25
+
26
+
27
+ Install
28
+ -------
29
+
30
+ If you have never installed Crypt::ISAAC, you may run the testsuite
31
+ to confirm that it works with:
32
+
33
+ # ruby setup.rb test
34
+
35
+ If you already have a version of Crypt::ISAAC installed, but want to
36
+ confirm this one before installing, run the test suite manually as
37
+ follows:
38
+
39
+ # ruby test/TC_ISAAC.rb local
40
+
41
+ When you are ready to install Crypt::ISAAC, type:
42
+
43
+ # ruby setup.rb install
44
+
45
+ This one step will install Crypt::ISAAC in your Ruby SITELIB. To test
46
+ the library after installation:
47
+
48
+ # ruby setup.rb test
49
+
50
+ Usage
51
+ -----
52
+
53
+ require 'crypt/ISAAC'
54
+
55
+ rng = Crypt::ISAAC.new
56
+
57
+ r1 = rng.rand() # returns a floating point between 0 and 1
58
+ r2 = rnd.rand(1000) # returns an integer between 0 and 999
59
+
60
+ rand() should work identically to the Kernel.rand().
61
+
62
+ Enjoy it. Let me know if you find anything that can be improved or that
63
+ needs to be fixed.
64
+
65
+
66
+ License
67
+ -------
68
+
69
+ The Crypt::ISAAC library is licensed with an MIT style licence.
70
+ See the LICENSE file for details. As for the ISAAC algorithm itself,
71
+ see:
72
+
73
+ http://burtleburtle.net/bob/rand/isaac.html
74
+
75
+
76
+
77
+ Kirk Haines
78
+ khaines@enigo.com
@@ -0,0 +1,3 @@
1
+ * Add a C version of the ISAAC algorithm and make it possible to install
2
+ the pure Ruby version and/or a version using a C extension for better
3
+ performance.
@@ -0,0 +1,3 @@
1
+ * 0.9 Initial public release. Pure Ruby.
2
+ * 0.9.1 Update to tweak a couple things and reorganize project struct.
3
+ Now uses a Package based installer, or can be installed as a gem.
@@ -0,0 +1,171 @@
1
+ module Crypt
2
+
3
+ # ISAAC is a fast, strong random number generator. Details on the
4
+ # algorithm can be found here: http://burtleburtle.net/bob/rand/isaac.html
5
+ # This provides a consistent and capable algorithm for producing
6
+ # independent streams of quality random numbers.
7
+
8
+ class ISAAC
9
+
10
+ attr_accessor :randrsl, :randcnt
11
+ attr_accessor :mm, :aa, :bb, :cc
12
+
13
+ # When a Crypt::ISAAC object is created, it needs to be seeded for
14
+ # random number generation. If the system has a /dev/urandom file,
15
+ # that will be used to do the seeding by default. If false is explictly
16
+ # passed when creating the object, it will instead use /dev/random to
17
+ # generate its seeds. Be warned that this may make for SLOW
18
+ # initialization.
19
+ # If the requested source (/dev/urandom or /dev/random) do not exist,
20
+ # the system will fall back to a simplistic initialization mechanism
21
+ # using the builtin Mersenne Twister PRNG.
22
+
23
+ def initialize(noblock = true)
24
+ @mm = []
25
+ @randrsl = []
26
+ # Best initialization of the generator would be by pulling
27
+ # numbers from /dev/random.
28
+ rnd_source = noblock ? '/dev/urandom' : '/dev/random'
29
+ if (FileTest.exist? rnd_source)
30
+ File.open(rnd_source,'r') do |r|
31
+ 256.times do |t|
32
+ z = r.read(4)
33
+ x = z.unpack('V')[0]
34
+ @randrsl[t] = x
35
+ end
36
+ end
37
+ else
38
+ # If urandom isn't available, the standard Ruby PRNG makes an
39
+ # adequate fallback.
40
+ 256.times do |t|
41
+ @randrsl[t] = Kernel.rand(4294967295)
42
+ end
43
+ end
44
+ randinit(true)
45
+ nil
46
+ end
47
+
48
+ # Works just like the standard rand() function. If called with an
49
+ # integer argument, rand() will return positive random number in
50
+ # the range of 0 to (argument - 1). If called without an integer
51
+ # argument, rand() returns a positive floating point number less than 1.
52
+
53
+ def rand(*num)
54
+ if (@randcnt == 1)
55
+ isaac
56
+ @randcnt = 256
57
+ end
58
+ @randcnt -= 1
59
+ if num[0].to_i > 0
60
+ @randrsl[@randcnt].modulo(num[0])
61
+ else
62
+ ".#{@randrsl[@randcnt]}".to_f
63
+ end
64
+ end
65
+
66
+ def isaac
67
+ i = 0
68
+ x = 0
69
+ y = 0
70
+
71
+ @cc += 1
72
+ @bb += @cc
73
+ @bb & 0xffffffff
74
+
75
+ while (i < 256) do
76
+ x = @mm[i]
77
+ @aa = (@mm[(i + 128) & 255] + (@aa^(@aa << 13)) ) & 0xffffffff
78
+ @mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
79
+ @randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
80
+ i += 1
81
+
82
+ x = @mm[i]
83
+ @aa = (@mm[(i+128)&255] + (@aa^(0x03ffffff & (@aa >> 6))) ) & 0xffffffff
84
+ @mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
85
+ @randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
86
+ i += 1
87
+
88
+ x = @mm[i]
89
+ @aa = (@mm[(i + 128)&255] + (@aa^(@aa << 2)) ) & 0xffffffff
90
+ @mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
91
+ @randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
92
+ i += 1
93
+
94
+ x = @mm[i]
95
+ @aa = (@mm[(i+128)&255] + (@aa^(0x0000ffff & (@aa >> 16))) ) & 0xffffffff
96
+ @mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
97
+ @randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
98
+ i += 1
99
+ end
100
+ end
101
+
102
+ def randinit(flag)
103
+ i = 0
104
+ a = 0
105
+ b = 0
106
+ c = 0
107
+ d = 0
108
+ e = 0
109
+ f = 0
110
+ g = 0
111
+ @aa = @bb = @cc = 0
112
+ a = b = c = d = e = f = g = h = 0x9e3779b9
113
+
114
+ while (i < 4) do
115
+ a ^= b<<1; d += a; b += c
116
+ b ^= 0x3fffffff & (c>>2); e += b; c += d
117
+ c ^= d << 8; f += c; d += e
118
+ d ^= 0x0000ffff & (e >> 16); g += d; e += f
119
+ e ^= f << 10; h += e; f += g
120
+ f ^= 0x0fffffff & (g >> 4); a += f; g += h
121
+ g ^= h << 8; b += g; h += a
122
+ h ^= 0x007fffff & (a >> 9); c += h; a += b
123
+ i += 1
124
+ end
125
+
126
+ i = 0
127
+ while (i < 256) do
128
+ if (flag)
129
+ a+=@randrsl[i ].to_i; b+=@randrsl[i+1].to_i;
130
+ c+=@randrsl[i+2]; d+=@randrsl[i+3];
131
+ e+=@randrsl[i+4]; f+=@randrsl[i+5];
132
+ g+=@randrsl[i+6]; h+=@randrsl[i+7];
133
+ end
134
+
135
+ a^=b<<11; d+=a; b+=c;
136
+ b^=0x3fffffff & (c>>2); e+=b; c+=d;
137
+ c^=d<<8; f+=c; d+=e;
138
+ d^=0x0000ffff & (e>>16); g+=d; e+=f;
139
+ e^=f<<10; h+=e; f+=g;
140
+ f^=0x0fffffff & (g>>4); a+=f; g+=h;
141
+ g^=h<<8; b+=g; h+=a;
142
+ h^=0x007fffff & (a>>9); c+=h; a+=b;
143
+ @mm[i]=a;@mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
144
+ @mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
145
+ i += 8
146
+ end
147
+
148
+ if flag
149
+ i = 0
150
+ while (i < 256)
151
+ a+=@mm[i ]; b+=@mm[i+1]; c+=@mm[i+2]; d+=@mm[i+3];
152
+ e+=@mm[i+4]; f+=@mm[i+5]; g+=@mm[i+6]; h+=@mm[i+7];
153
+ a^=b<<11; d+=a; b+=c;
154
+ b^=0x3fffffff & (c>>2); e+=b; c+=d;
155
+ c^=d<<8; f+=c; d+=e;
156
+ d^=0x0000ffff & (e>>16); g+=d; e+=f;
157
+ e^=f<<10; h+=e; f+=g;
158
+ f^=0x0fffffff & (g>>4); a+=f; g+=h;
159
+ g^=h<<8; b+=g; h+=a;
160
+ h^=0x007fffff & (a>>9); c+=h; a+=b;
161
+ @mm[i ]=a; @mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
162
+ @mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
163
+ i += 8
164
+ end
165
+ end
166
+
167
+ isaac()
168
+ @randcnt=256; # /* prepare to use the first set of results */
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,39 @@
1
+ #####
2
+ # Crypt::ISAAC
3
+ # http://rubyforge.org/projects/crypt-isaac/
4
+ # Copyright 2004-2005 Kirk Haines
5
+ #
6
+ # Licensed under the Ruby License. See the README for details.
7
+ #
8
+ #####
9
+
10
+ spec = Gem::Specification.new do |s|
11
+ s.name = 'Crypt::ISAAC'
12
+ s.version = '0.9.1'
13
+ s.summary = %q(Ruby implementation of the ISAAC PRNG)
14
+ s.platform = Gem::Platform::RUBY
15
+
16
+ s.has_rdoc = true
17
+ s.rdoc_options = %w(--title Crypt::ISAAC --main README --line-numbers)
18
+ s.extra_rdoc_files = %w(README)
19
+
20
+ s.files = %w(README LICENSE TODO VERSIONS setup.rb isaac.gemspec test/TC_ISAAC.rb crypt/ISAAC.rb)
21
+
22
+ s.test_files = ['test/TC_ISAAC.rb']
23
+
24
+ s.require_paths = %w(crypt)
25
+
26
+ s.author = %q(Kirk Haines)
27
+ s.email = %q(khaines@enigo.com)
28
+ s.rubyforge_project = %q(crypt-isaac)
29
+ s.homepage = %q(http://rubyforge.org/projects/crypt-isaac)
30
+ description = []
31
+ File.open("README") do |file|
32
+ file.each do |line|
33
+ line.chomp!
34
+ break if line.empty?
35
+ description << "#{line.gsub(/\[\d\]/, '')}"
36
+ end
37
+ end
38
+ s.description = description[1..-1].join(" ")
39
+ end