Permalink
Browse files

Updating strategies config format to allow for strategy reuse

  • Loading branch information...
1 parent de16184 commit c863d1ac837e4457f34127577a5733fc243613aa @Slotos committed Jul 4, 2012
Showing with 12 additions and 10 deletions.
  1. +8 −7 lib/casserver/server.rb
  2. +2 −3 spec/strategy_config.yml
  3. +2 −0 spec/strategy_spec.rb
View
15 lib/casserver/server.rb
@@ -67,7 +67,7 @@ def self.use_public_folder?
:maximum_unused_login_ticket_lifetime => 5.minutes,
:maximum_unused_service_ticket_lifetime => 5.minutes, # CAS Protocol Spec, sec. 3.2.1 (recommended expiry time)
:maximum_session_lifetime => 2.days, # all tickets are deleted after this period of time
- :log => {:file => 'casserver.log', :level => 'DEBUG'},
+ :log => {:file => 'log/casserver.log', :level => 'DEBUG'},
:uri_path => ""
)
set :config, config
@@ -226,19 +226,20 @@ def self.handler_ssl_options
end
def self.init_strategies!
- return nil unless config[:strategy]
+ strategies = config[:strategies] || config[:strategy]
+ return unless strategies
+ strategies = [strategies] unless strategies.is_a?(::Array)
- config[:strategy].each do |name, conf|
+ strategies.each do |conf|
set :workhorse, conf
begin
- require ( conf[:require] || "rubycas-strategy-#{name}" )
+ require "rubycas-strategy-#{conf[:strategy].downcase}"
rescue LoadError => e
- $LOG.debug "Failed require with error #{e}, attempting to load #{name} strategy anyway"
+ $LOG.debug "Failed require with error #{e}, attempting to load #{conf[:strategy]} strategy anyway"
end
- strategy = ( conf[:register] || "CASServer::Strategy::#{name.capitalize}" ).constantize
- register strategy
+ register "CASServer::Strategy::#{conf[:strategy]}".constantize
set :workhorse, nil
end
View
5 spec/strategy_config.yml
@@ -23,9 +23,8 @@ authenticator:
class: CASServer::Authenticators::Test
password: spec_password
-strategy:
- dummy:
- require: <%= "#{Dir.pwd}/spec/strategy_dummy" %>
+strategies:
+ strategy: Dummy
theme: simple
View
2 spec/strategy_spec.rb
@@ -1,5 +1,7 @@
# encoding: UTF-8
require File.dirname(__FILE__) + '/spec_helper'
+require File.dirname(__FILE__) + '/strategy_dummy'
+
include Rack::Test::Methods
$LOG = Logger.new(File.basename(__FILE__).gsub('.rb','.log'))

0 comments on commit c863d1a

Please sign in to comment.