rubycas-server 0.3.0 → 0.4.0
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.
- data/CHANGELOG.txt +10 -0
- data/Manifest.txt +2 -0
- data/Rakefile +1 -2
- data/bin/rubycas-server +21 -4
- data/bin/rubycas-server-ctl +163 -0
- data/config.example.yml +6 -6
- data/lib/casserver.rb +16 -5
- data/lib/casserver/authenticators/ldap.rb +1 -1
- data/lib/casserver/cas.rb +2 -0
- data/lib/casserver/conf.rb +9 -3
- data/lib/casserver/controllers.rb +24 -14
- data/lib/casserver/postambles.rb +75 -11
- data/lib/casserver/version.rb +1 -1
- data/resources/init.d.sh +58 -0
- metadata +6 -3
data/CHANGELOG.txt
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
=== 0.4.0 :: In progress...
|
|
2
|
+
|
|
3
|
+
* Added rubycas-server-ctl script for controlling daemonized server.
|
|
4
|
+
* Added system startup script to be used in /etc/init.d on Linux systems.
|
|
5
|
+
* Authenticator can now be loaded from an external file using the 'source'
|
|
6
|
+
configuration option.
|
|
7
|
+
* Better preemptive detection of startup problems with mongrel.
|
|
8
|
+
* User now sees an error message if the service URI is not a valid URI (i.e.
|
|
9
|
+
if it's not URI-encoded or otherwise malformed).
|
|
10
|
+
|
|
1
11
|
=== 0.3.0 :: 2007-03-29
|
|
2
12
|
|
|
3
13
|
* Fixed glaring security problem with LDAP/AD Authenticator where under some
|
data/Manifest.txt
CHANGED
|
@@ -4,6 +4,7 @@ Manifest.txt
|
|
|
4
4
|
README.txt
|
|
5
5
|
Rakefile
|
|
6
6
|
bin/rubycas-server
|
|
7
|
+
bin/rubycas-server-ctl
|
|
7
8
|
config.example.yml
|
|
8
9
|
lib/casserver.rb
|
|
9
10
|
lib/casserver/authenticators/active_directory_ldap.rb
|
|
@@ -31,5 +32,6 @@ lib/themes/urbacon/login_box_bg.png
|
|
|
31
32
|
lib/themes/urbacon/logo.png
|
|
32
33
|
lib/themes/urbacon/theme.css
|
|
33
34
|
lib/themes/warning.png
|
|
35
|
+
resources/init.d.sh
|
|
34
36
|
setup.rb
|
|
35
37
|
test/test_casserver.rb
|
data/Rakefile
CHANGED
|
@@ -20,7 +20,6 @@ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
|
20
20
|
|
|
21
21
|
DEPS = [
|
|
22
22
|
['camping', '>= 1.5'],
|
|
23
|
-
# ['sqlite3-ruby', '>= 1.2.0'],
|
|
24
23
|
['activesupport', '>= 1.4.0'],
|
|
25
24
|
['activerecord', '>=1.15.3']
|
|
26
25
|
]
|
|
@@ -56,5 +55,5 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
|
56
55
|
|
|
57
56
|
# == Optional
|
|
58
57
|
p.extra_deps = DEPS
|
|
59
|
-
p.spec_extras = {:executables => 'rubycas-server'}
|
|
58
|
+
p.spec_extras = {:executables => ['rubycas-server', 'rubycas-server-ctl']}
|
|
60
59
|
end
|
data/bin/rubycas-server
CHANGED
|
@@ -4,10 +4,14 @@ require 'optparse'
|
|
|
4
4
|
|
|
5
5
|
local_casserver = File.expand_path(File.dirname(File.expand_path(__FILE__))+'/../lib/casserver.rb')
|
|
6
6
|
if File.exists? local_casserver
|
|
7
|
+
# use local rubycas-server installation
|
|
7
8
|
$: << File.dirname(local_casserver)
|
|
9
|
+
path = File.dirname(local_casserver)+"/"
|
|
8
10
|
else
|
|
11
|
+
# use gem installation
|
|
12
|
+
path = ""
|
|
9
13
|
require 'rubygems'
|
|
10
|
-
|
|
14
|
+
gem 'rubycas-server'
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
OptionParser.new do |opts|
|
|
@@ -21,14 +25,27 @@ OptionParser.new do |opts|
|
|
|
21
25
|
opts.on("-d", "--daemonize", "Run as a daemon (only when using webrick or mongrel)") do |c|
|
|
22
26
|
$DAEMONIZE = true
|
|
23
27
|
end
|
|
24
|
-
|
|
28
|
+
|
|
29
|
+
opts.on("-P", "--pid_file FILE", "Use pid file (default is /etc/rubycas-server/rubycas-server.pid)") do |c|
|
|
30
|
+
if $DAEMONIZE && !File.exists?(c)
|
|
31
|
+
puts "Using pid file '#{c}'"
|
|
32
|
+
$PID_FILE = c
|
|
33
|
+
elsif File.exists?(c)
|
|
34
|
+
puts "The pid file already exists. Is rubycas-server running?\n" +
|
|
35
|
+
"You will have to first manually remove the pid file at '#{c}' to start the server as a daemon."
|
|
36
|
+
exit 1
|
|
37
|
+
else
|
|
38
|
+
puts "Not running as Daemon. Ignoring pid option"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
25
42
|
opts.on_tail("-h", "--help", "Show this message") do
|
|
26
43
|
puts opts
|
|
27
44
|
exit
|
|
28
45
|
end
|
|
29
46
|
|
|
30
47
|
opts.on_tail("-v", "--version", "Show version number") do
|
|
31
|
-
require
|
|
48
|
+
require "#{path}casserver/version"
|
|
32
49
|
puts "rubycas-server-#{CASServer::VERSION::STRING}"
|
|
33
50
|
exit
|
|
34
51
|
end
|
|
@@ -36,4 +53,4 @@ end.parse!
|
|
|
36
53
|
|
|
37
54
|
$RUN = true
|
|
38
55
|
|
|
39
|
-
load
|
|
56
|
+
load "#{path}casserver.rb"
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
@options = {}
|
|
6
|
+
@options[:pid_file] = "/etc/rubycas-server/rubycas-server.pid"
|
|
7
|
+
@options[:conf_file] = nil
|
|
8
|
+
@options[:verbose] = false
|
|
9
|
+
|
|
10
|
+
def start
|
|
11
|
+
# use local rubycas-server bin if it exists and is executable -- makes debugging easier
|
|
12
|
+
bin = File.dirname(File.expand_path(__FILE__)) + "/rubycas-server"
|
|
13
|
+
|
|
14
|
+
if File.exists?(bin)
|
|
15
|
+
exec = "ruby #{bin}"
|
|
16
|
+
else
|
|
17
|
+
exec = "rubycas-server"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
case get_state
|
|
21
|
+
when :ok
|
|
22
|
+
$stderr.puts "rubycas-server is already running"
|
|
23
|
+
exit 1
|
|
24
|
+
when :not_running
|
|
25
|
+
$stderr.puts "The pid file '#{@options[:pid_file]}' exists but rubycas-server is not running." +
|
|
26
|
+
"Please delete the pid file first."
|
|
27
|
+
exit 1
|
|
28
|
+
when :dead
|
|
29
|
+
$stderr.puts "The pid file '#{@options[:pid_file]}' exists but rubycas-server is not running." +
|
|
30
|
+
" Please delete the pid file first."
|
|
31
|
+
exit 1
|
|
32
|
+
when :missing_pid
|
|
33
|
+
# we should be good to go (unless the server is already running without a pid file)
|
|
34
|
+
else
|
|
35
|
+
$stderr.puts "rubycas-server could not be started. Try looking in the log file for more info."
|
|
36
|
+
exit 1
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
cmd = "#{exec} -d -P #{@options[:pid_file]}"
|
|
40
|
+
cmd += " -c #{@options[:conf_file]}" if !@options[:conf_file].nil?
|
|
41
|
+
|
|
42
|
+
puts ">>> #{cmd}" if @options[:verbose]
|
|
43
|
+
|
|
44
|
+
output = `#{cmd}`
|
|
45
|
+
|
|
46
|
+
puts "<<< #{output}" if @options[:verbose]
|
|
47
|
+
|
|
48
|
+
if s = get_state == :ok
|
|
49
|
+
exit 0
|
|
50
|
+
else
|
|
51
|
+
$stderr.puts "rubycas-server could not start properly!\nTry running with the --verbose option for details."
|
|
52
|
+
case s
|
|
53
|
+
when :missing_pid
|
|
54
|
+
exit 4
|
|
55
|
+
when :not_running
|
|
56
|
+
exit 3
|
|
57
|
+
when :dead
|
|
58
|
+
exit 1
|
|
59
|
+
else
|
|
60
|
+
exit 4
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def stop
|
|
66
|
+
if File.exists? @options[:pid_file]
|
|
67
|
+
pid = open(@options[:pid_file]).read.to_i
|
|
68
|
+
begin
|
|
69
|
+
Process.kill("TERM", pid)
|
|
70
|
+
exit 0
|
|
71
|
+
rescue Errno::ESRCH
|
|
72
|
+
$stderr.puts "rubycas-server process '#{pid}' does not exist."
|
|
73
|
+
exit 1
|
|
74
|
+
end
|
|
75
|
+
else
|
|
76
|
+
$stderr.puts "#{@options[:pid_file]} not found. Is rubycas-server running?"
|
|
77
|
+
exit 4
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def status
|
|
82
|
+
case get_state
|
|
83
|
+
when :ok
|
|
84
|
+
puts "rubycas-server appears to be up and running."
|
|
85
|
+
exit 0
|
|
86
|
+
when :missing_pid
|
|
87
|
+
$stderr.puts "rubycas-server does not appear to be running (pid file not found)."
|
|
88
|
+
exit 3
|
|
89
|
+
when :empty_pid
|
|
90
|
+
$stderr.puts "rubycas-server does not appear to be running (pid file exists but is empty)."
|
|
91
|
+
when :not_running
|
|
92
|
+
$stderr.puts "rubycas-server is not running."
|
|
93
|
+
exit 1
|
|
94
|
+
when :dead
|
|
95
|
+
$stderr.puts "rubycas-server is dead or unresponsive."
|
|
96
|
+
exit 102
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def get_state
|
|
101
|
+
if File.exists? @options[:pid_file]
|
|
102
|
+
pid = File.read(@options[:pid_file]).strip
|
|
103
|
+
|
|
104
|
+
return :empty_pid unless pid and !pid.empty? # pid file exists but is empty
|
|
105
|
+
|
|
106
|
+
state = `ps -p #{pid} -o state=`.strip
|
|
107
|
+
if state == ''
|
|
108
|
+
:not_running
|
|
109
|
+
elsif state == 'R' || state == 'S'
|
|
110
|
+
:ok
|
|
111
|
+
else
|
|
112
|
+
:dead
|
|
113
|
+
end
|
|
114
|
+
else
|
|
115
|
+
# TODO: scan through the process table to see if server is running without pid file
|
|
116
|
+
:missing_pid
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
OptionParser.new do |opts|
|
|
121
|
+
opts.banner = "Usage: #{$0} (start|stop|restart) [options]"
|
|
122
|
+
opts.banner += "\nruby-server-ctl is only usable when using webrick or mongrel"
|
|
123
|
+
|
|
124
|
+
opts.on("-c", "--config FILE", "Path to rubycas-server configuration file") { |value| @options[:conf_file] = value }
|
|
125
|
+
opts.on("-P", "--pid_file FILE", "Path to rubycas-server pid file") { |value| @options[:pid_file] = value }
|
|
126
|
+
opts.on('-v', '--verbose', "Print all called commands and output.") { |value| @options[:verbose] = value }
|
|
127
|
+
|
|
128
|
+
if ARGV.empty?
|
|
129
|
+
puts opts
|
|
130
|
+
exit
|
|
131
|
+
else
|
|
132
|
+
@cmd = opts.parse!(ARGV)
|
|
133
|
+
if @cmd.nil?
|
|
134
|
+
puts opts
|
|
135
|
+
exit
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
if !@options[:conf_file].nil? && !File.exists?(@options[:conf_file])
|
|
141
|
+
puts "Invalid path to rubycas-server configuration file: #{@options[:conf_file]}"
|
|
142
|
+
exit
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
case @cmd[0]
|
|
146
|
+
when "start":
|
|
147
|
+
puts "Starting rubycas-server..."
|
|
148
|
+
start
|
|
149
|
+
when "stop":
|
|
150
|
+
puts "Stopping rubycas-server..."
|
|
151
|
+
stop
|
|
152
|
+
when "restart":
|
|
153
|
+
puts "Restarting rubycas-server..."
|
|
154
|
+
stop
|
|
155
|
+
start
|
|
156
|
+
when "status":
|
|
157
|
+
puts "Checking status of rubycas-server..."
|
|
158
|
+
status
|
|
159
|
+
else
|
|
160
|
+
puts "Invalid command. Usage: rubycas-server-ctl [-cPv] start|stop|restart|status"
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
exit
|
data/config.example.yml
CHANGED
|
@@ -149,16 +149,16 @@ database:
|
|
|
149
149
|
# as a hash under :username and :password keys. In the future, this hash
|
|
150
150
|
# might also contain other data such as the domain that the user is logging in to.
|
|
151
151
|
#
|
|
152
|
-
# To use your custom authenticator, specify it's class name
|
|
153
|
-
# of the config.
|
|
154
|
-
#
|
|
155
|
-
#
|
|
156
|
-
# method as an @options hash.
|
|
152
|
+
# To use your custom authenticator, specify it's class name and path to the source file
|
|
153
|
+
# in the authenticator section of the config. Any other parameters you specify in the
|
|
154
|
+
# authenticator configuration will be passed on to the authenticator and made availabe in
|
|
155
|
+
# the validate() method as an @options hash.
|
|
157
156
|
#
|
|
158
157
|
# Example:
|
|
159
158
|
#
|
|
160
159
|
#authenticator:
|
|
161
160
|
# class: FooModule::MyCustomAuthenticator
|
|
161
|
+
# source: /path/to/source.rb
|
|
162
162
|
# option_a: foo
|
|
163
163
|
# another_option: yeeha
|
|
164
164
|
|
|
@@ -224,4 +224,4 @@ log:
|
|
|
224
224
|
# If you would prefer that ticket-granting ticket expiry be enforced (in effect limiting
|
|
225
225
|
# the maximum length of a session), you can set expire_sessions to true.
|
|
226
226
|
|
|
227
|
-
# expire_sessions: false
|
|
227
|
+
# expire_sessions: false
|
data/lib/casserver.rb
CHANGED
|
@@ -8,7 +8,7 @@ $CASSERVER_HOME = File.dirname(File.expand_path(__FILE__))
|
|
|
8
8
|
$: << $CASSERVER_HOME
|
|
9
9
|
|
|
10
10
|
require 'rubygems'
|
|
11
|
-
|
|
11
|
+
gem 'camping', '~> 1.5'
|
|
12
12
|
require 'camping'
|
|
13
13
|
|
|
14
14
|
require 'active_support'
|
|
@@ -31,9 +31,14 @@ module CASServer
|
|
|
31
31
|
module_function :init_logger
|
|
32
32
|
|
|
33
33
|
def init_db_logger
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
begin
|
|
35
|
+
if CASServer::Conf.db_log
|
|
36
|
+
log_file = CASServer::Conf.db_log[:file] || 'casserver_db.log'
|
|
37
|
+
CASServer::Models::Base.logger = Logger.new(log_file)
|
|
38
|
+
CASServer::Models::Base.logger.level = "CASServer::Utils::Logger::#{CASServer::Conf.db_log[:level] || 'DEBUG'}".constantize
|
|
39
|
+
end
|
|
40
|
+
rescue Errno::EACCES => e
|
|
41
|
+
$LOG.warn "Can't write to database log file at '#{log_file}': #{e}"
|
|
37
42
|
end
|
|
38
43
|
end
|
|
39
44
|
module_function :init_db_logger
|
|
@@ -72,11 +77,17 @@ if __FILE__ == $0 || $RUN
|
|
|
72
77
|
|
|
73
78
|
require 'casserver/postambles'
|
|
74
79
|
include CASServer::Postambles
|
|
75
|
-
|
|
80
|
+
|
|
81
|
+
if $PID_FILE && (CASServer::Conf.server.to_s != 'mongrel' || CASServer::Conf.server.to_s != 'webrick')
|
|
82
|
+
$LOG.warn("Unable to create a pid file. You must use mongrel or webrick for this feature.")
|
|
83
|
+
end
|
|
84
|
+
|
|
76
85
|
begin
|
|
77
86
|
raise NoMethodError if CASServer::Conf.server.nil?
|
|
78
87
|
send(CASServer::Conf.server)
|
|
79
88
|
rescue NoMethodError
|
|
89
|
+
# FIXME: this rescue can sometime report the incorrect error messages due to other underlying problems
|
|
90
|
+
# raising a NoMethodError
|
|
80
91
|
if CASServer::Conf.server
|
|
81
92
|
raise "The server setting '#{CASServer::Conf.server}' in your config.yml file is invalid."
|
|
82
93
|
else
|
data/lib/casserver/cas.rb
CHANGED
|
@@ -219,6 +219,8 @@ module CASServer::CAS
|
|
|
219
219
|
def service_uri_with_ticket(service, st)
|
|
220
220
|
raise ArgumentError, "Second argument must be a ServiceTicket!" unless st.kind_of? CASServer::Models::ServiceTicket
|
|
221
221
|
|
|
222
|
+
# This will choke with a URI::InvalidURIError if service URI is not properly URI-escaped...
|
|
223
|
+
# This exception is handled further upstream (i.e. in the controller).
|
|
222
224
|
service_uri = URI.parse(service)
|
|
223
225
|
|
|
224
226
|
if service.include? "?"
|
data/lib/casserver/conf.rb
CHANGED
|
@@ -47,9 +47,15 @@ begin
|
|
|
47
47
|
# attempt to instantiate the authenticator
|
|
48
48
|
$AUTH = $CONF[:authenticator][:class].constantize.new
|
|
49
49
|
rescue NameError
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
if !$CONF[:authenticator][:source].nil?
|
|
51
|
+
# config.yml explicitly names source file
|
|
52
|
+
require $CONF[:authenticator][:source]
|
|
53
|
+
else
|
|
54
|
+
# the authenticator class hasn't yet been loaded, so lets try to load it from the casserver/authenticators directory
|
|
55
|
+
auth_rb = $CONF[:authenticator][:class].underscore.gsub('cas_server/', '')
|
|
56
|
+
require 'casserver/'+auth_rb
|
|
57
|
+
end
|
|
58
|
+
|
|
53
59
|
$AUTH = $CONF[:authenticator][:class].constantize.new
|
|
54
60
|
end
|
|
55
61
|
rescue
|
|
@@ -24,14 +24,19 @@ module CASServer::Controllers
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
if tgt and !tgt_error
|
|
27
|
-
@message = {:type => 'notice', :message => %{You are currently logged in as "#{tgt.username}". If
|
|
27
|
+
@message = {:type => 'notice', :message => %{You are currently logged in as "#{tgt.username}". If this is not you, please log in below.}}
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
begin
|
|
31
|
+
if @service && !@renew && tgt && !tgt_error
|
|
32
|
+
st = generate_service_ticket(@service, tgt.username)
|
|
33
|
+
service_with_ticket = service_uri_with_ticket(@service, st)
|
|
34
|
+
$LOG.info("User '#{tgt.username}' authenticated based on ticket granting cookie. Redirecting to service '#{@service}'.")
|
|
35
|
+
return redirect(service_with_ticket, :status => 303) # response code 303 means "See Other" (see Appendix B in CAS Protocol spec)
|
|
36
|
+
end
|
|
37
|
+
rescue
|
|
38
|
+
$LOG.error("The service '#{@service}' is not a valid URI!")
|
|
39
|
+
@message = {:type => 'mistake', :message => "The target service your browser supplied appears to be invalid. Please contact your system administrator for help."}
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
lt = generate_login_ticket
|
|
@@ -98,19 +103,24 @@ module CASServer::Controllers
|
|
|
98
103
|
if @service.blank?
|
|
99
104
|
$LOG.info("Successfully authenticated user '#{@username}' at '#{tgt.client_hostname}'. No service param was given, so we will not redirect.")
|
|
100
105
|
@message = {:type => 'confirmation', :message => "You have successfully logged in."}
|
|
101
|
-
render :login
|
|
102
106
|
else
|
|
103
|
-
@st = generate_service_ticket(@service, @username)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
@st = generate_service_ticket(@service, @username)
|
|
108
|
+
begin
|
|
109
|
+
service_with_ticket = service_uri_with_ticket(@service, @st)
|
|
110
|
+
|
|
111
|
+
$LOG.info("Redirecting authenticated user '#{@username}' at '#{@st.client_hostname}' to service '#{@service}'")
|
|
112
|
+
return redirect(service_with_ticket, :status => 303) # response code 303 means "See Other" (see Appendix B in CAS Protocol spec)
|
|
113
|
+
rescue URI::InvalidURIError
|
|
114
|
+
$LOG.error("The service '#{@service}' is not a valid URI!")
|
|
115
|
+
@message = {:type => 'mistake', :message => "The target service your browser supplied appears to be invalid. Please contact your system administrator for help."}
|
|
116
|
+
end
|
|
108
117
|
end
|
|
109
118
|
else
|
|
110
119
|
$LOG.warn("Invalid credentials given for user '#{@username}'")
|
|
111
120
|
@message = {:type => 'mistake', :message => "Incorrect username or password."}
|
|
112
|
-
render :login
|
|
113
121
|
end
|
|
122
|
+
|
|
123
|
+
render :login
|
|
114
124
|
end
|
|
115
125
|
end
|
|
116
126
|
|
|
@@ -279,4 +289,4 @@ module CASServer::Controllers
|
|
|
279
289
|
end
|
|
280
290
|
end
|
|
281
291
|
end
|
|
282
|
-
end
|
|
292
|
+
end
|
data/lib/casserver/postambles.rb
CHANGED
|
@@ -47,9 +47,16 @@ module CASServer
|
|
|
47
47
|
trap(:INT) do
|
|
48
48
|
s.shutdown
|
|
49
49
|
end
|
|
50
|
+
trap(:TERM) do
|
|
51
|
+
s.shutdown
|
|
52
|
+
end
|
|
50
53
|
|
|
51
54
|
if $DAEMONIZE
|
|
52
|
-
WEBrick::Daemon.start
|
|
55
|
+
WEBrick::Daemon.start do
|
|
56
|
+
write_pid_file if $PID_FILE
|
|
57
|
+
s.start
|
|
58
|
+
clear_pid_file
|
|
59
|
+
end
|
|
53
60
|
else
|
|
54
61
|
s.start
|
|
55
62
|
end
|
|
@@ -64,24 +71,35 @@ module CASServer
|
|
|
64
71
|
# camping has fixes for mongrel currently only availabe in SVN
|
|
65
72
|
# ... you can install camping from svn (1.5.180) by running:
|
|
66
73
|
# gem install camping --source code.whytheluckystiff.net
|
|
67
|
-
|
|
74
|
+
gem 'camping', '~> 1.5.180'
|
|
75
|
+
|
|
76
|
+
if $DAEMONIZE
|
|
77
|
+
# check if log and pid are writable before daemonizing, otherwise we won't be able to notify
|
|
78
|
+
# the user if we run into trouble later (since once daemonized, we can't write to stdout/stderr)
|
|
79
|
+
check_pid_writable if $PID_FILE
|
|
80
|
+
check_log_writable
|
|
81
|
+
end
|
|
68
82
|
|
|
69
|
-
CASServer.create
|
|
83
|
+
CASServer.create
|
|
70
84
|
|
|
71
85
|
puts "\n** CASServer is starting. Look in '#{CASServer::Conf.log[:file]}' for further notices."
|
|
72
86
|
|
|
73
87
|
settings = {:host => "0.0.0.0", :log_file => CASServer::Conf.log[:file], :cwd => $CASSERVER_HOME}
|
|
74
88
|
|
|
75
|
-
# need to close all IOs
|
|
76
|
-
$LOG.close
|
|
89
|
+
# need to close all IOs before daemonizing
|
|
90
|
+
$LOG.close if $DAEMONIZE
|
|
77
91
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
begin
|
|
93
|
+
config = Mongrel::Configurator.new settings do
|
|
94
|
+
daemonize :log_file => CASServer::Conf.log[:file], :cwd => $CASSERVER_HOME if $DAEMONIZE
|
|
95
|
+
|
|
96
|
+
listener :port => CASServer::Conf.port do
|
|
97
|
+
uri CASServer::Conf.uri_path, :handler => Mongrel::Camping::CampingHandler.new(CASServer)
|
|
98
|
+
setup_signals
|
|
99
|
+
end
|
|
84
100
|
end
|
|
101
|
+
rescue Errno::EADDRINUSE
|
|
102
|
+
exit 1
|
|
85
103
|
end
|
|
86
104
|
|
|
87
105
|
config.run
|
|
@@ -89,8 +107,19 @@ module CASServer
|
|
|
89
107
|
CASServer.init_logger
|
|
90
108
|
CASServer.init_db_logger
|
|
91
109
|
|
|
110
|
+
if $DAEMONIZE && $PID_FILE
|
|
111
|
+
write_pid_file
|
|
112
|
+
unless File.exists? $PID_FILE
|
|
113
|
+
$LOG.error "CASServer could not start because pid file '#{$PID_FILE}' could not be created."
|
|
114
|
+
exit 1
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
92
118
|
puts "\n** CASServer is running at http://localhost:#{CASServer::Conf.port}#{CASServer::Conf.uri_path} and logging to '#{CASServer::Conf.log[:file]}'"
|
|
93
119
|
config.join
|
|
120
|
+
|
|
121
|
+
clear_pid_file
|
|
122
|
+
|
|
94
123
|
puts "\n** CASServer is stopped (#{Time.now})"
|
|
95
124
|
end
|
|
96
125
|
|
|
@@ -108,6 +137,41 @@ module CASServer
|
|
|
108
137
|
CASServer.create
|
|
109
138
|
puts CASServer.run
|
|
110
139
|
end
|
|
140
|
+
|
|
141
|
+
private
|
|
142
|
+
def check_log_writable
|
|
143
|
+
log_file = CASServer::Conf.log['file']
|
|
144
|
+
begin
|
|
145
|
+
f = open(log_file, 'w')
|
|
146
|
+
rescue
|
|
147
|
+
$stderr.puts "Couldn't write to log file at '#{log_file}' (#{$!})."
|
|
148
|
+
exit 1
|
|
149
|
+
end
|
|
150
|
+
f.close
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def check_pid_writable
|
|
154
|
+
$LOG.debug "Checking if pid file '#{$PID_FILE}' is writable"
|
|
155
|
+
begin
|
|
156
|
+
f = open($PID_FILE, 'w')
|
|
157
|
+
rescue
|
|
158
|
+
$stderr.puts "Couldn't write to log at '#{$PID_FILE}' (#{$!})."
|
|
159
|
+
exit 1
|
|
160
|
+
end
|
|
161
|
+
f.close
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def write_pid_file
|
|
165
|
+
$LOG.debug "Writing pid '#{Process.pid}' to pid file '#{$PID_FILE}'"
|
|
166
|
+
open($PID_FILE, "w") { |file| file.write(Process.pid) }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def clear_pid_file
|
|
170
|
+
if $PID_FILE && File.exists?($PID_FILE)
|
|
171
|
+
$LOG.debug "Clearing pid file '#{$PID_FILE}'"
|
|
172
|
+
File.unlink $PID_FILE
|
|
173
|
+
end
|
|
174
|
+
end
|
|
111
175
|
|
|
112
176
|
end
|
|
113
177
|
end
|
data/lib/casserver/version.rb
CHANGED
data/resources/init.d.sh
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#! /bin/sh
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2007 Urbacon Ltd.
|
|
4
|
+
#
|
|
5
|
+
# System startup script for the RubyCAS-Server
|
|
6
|
+
#
|
|
7
|
+
# Instructions:
|
|
8
|
+
# 1. Rename this file to 'rubycas-server'
|
|
9
|
+
# 2. Copy it to your '/etc/init.d' directory
|
|
10
|
+
# 3. chmod +x /etc/init.d/rubycas-server
|
|
11
|
+
#
|
|
12
|
+
# chkconfig - 85 15
|
|
13
|
+
# description: Provides single-sign-on authentication for web applications.
|
|
14
|
+
#
|
|
15
|
+
### BEGIN INIT INFO
|
|
16
|
+
# Provides: rubycas-server
|
|
17
|
+
# Required-Start: $syslog
|
|
18
|
+
# Should-Start:
|
|
19
|
+
# Required-Stop: $syslog
|
|
20
|
+
# Should-Stop:
|
|
21
|
+
# Default-Start: 3 5
|
|
22
|
+
# Default-Stop: 0 1 2 6
|
|
23
|
+
# Description: Start the RubyCAS-Server
|
|
24
|
+
### END INIT INFO
|
|
25
|
+
|
|
26
|
+
CASSERVER_CTL=rubycas-server-ctl
|
|
27
|
+
|
|
28
|
+
# Gracefully exit if the controller is missing.
|
|
29
|
+
which $CASSERVER_CTL > /dev/null || exit 0
|
|
30
|
+
|
|
31
|
+
# Source config
|
|
32
|
+
. /etc/rc.status
|
|
33
|
+
|
|
34
|
+
rc_reset
|
|
35
|
+
case "$1" in
|
|
36
|
+
start)
|
|
37
|
+
$CASSERVER_CTL start
|
|
38
|
+
rc_status -v
|
|
39
|
+
;;
|
|
40
|
+
stop)
|
|
41
|
+
$CASSERVER_CTL stop
|
|
42
|
+
rc_status -v
|
|
43
|
+
;;
|
|
44
|
+
restart)
|
|
45
|
+
$0 stop
|
|
46
|
+
$0 start
|
|
47
|
+
rc_status
|
|
48
|
+
;;
|
|
49
|
+
status)
|
|
50
|
+
$CASSERVER_CTL status
|
|
51
|
+
rc_status -v
|
|
52
|
+
;;
|
|
53
|
+
*)
|
|
54
|
+
echo "Usage: $0 {start|stop|status|restart}"
|
|
55
|
+
exit 1
|
|
56
|
+
;;
|
|
57
|
+
esac
|
|
58
|
+
rc_exit
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.9.
|
|
2
|
+
rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: rubycas-server
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.
|
|
7
|
-
date: 2007-
|
|
6
|
+
version: 0.4.0
|
|
7
|
+
date: 2007-06-04 00:00:00 -04:00
|
|
8
8
|
summary: Provides single sign on for web applications using the CAS protocol.
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- README.txt
|
|
36
36
|
- Rakefile
|
|
37
37
|
- bin/rubycas-server
|
|
38
|
+
- bin/rubycas-server-ctl
|
|
38
39
|
- config.example.yml
|
|
39
40
|
- lib/casserver.rb
|
|
40
41
|
- lib/casserver/authenticators/active_directory_ldap.rb
|
|
@@ -62,6 +63,7 @@ files:
|
|
|
62
63
|
- lib/themes/urbacon/logo.png
|
|
63
64
|
- lib/themes/urbacon/theme.css
|
|
64
65
|
- lib/themes/warning.png
|
|
66
|
+
- resources/init.d.sh
|
|
65
67
|
- setup.rb
|
|
66
68
|
- test/test_casserver.rb
|
|
67
69
|
test_files:
|
|
@@ -73,6 +75,7 @@ extra_rdoc_files: []
|
|
|
73
75
|
|
|
74
76
|
executables:
|
|
75
77
|
- rubycas-server
|
|
78
|
+
- rubycas-server-ctl
|
|
76
79
|
extensions: []
|
|
77
80
|
|
|
78
81
|
requirements: []
|