Module: CASServer

Includes:
GetText
Defined in:
lib/casserver/utils.rb,
lib/casserver/version.rb,
lib/casserver/postambles.rb,
lib/casserver/localization.rb,
lib/casserver/authenticators/base.rb,
lib/casserver/authenticators/ntlm.rb

Overview

Misc utility function used throughout by the RubyCAS-server.

Defined Under Namespace

Modules: Authenticators, CAS, Controllers, Models, Postambles, Utils, VERSION, Views Classes: AuthenticatorError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createObject



30
31
32
33
34
35
36
37
38
# File 'lib/casserver.rb', line 30

def CASServer.create
  CASServer::Models::Base.establish_connection($CONF[:database])
  CASServer::Models.create_schema
  
  CASServer::Models::ServiceTicket.cleanup_expired($CONF[:service_ticket_expiry])
  CASServer::Models::LoginTicket.cleanup_expired($CONF[:login_ticket_expiry])
  CASServer::Models::ProxyGrantingTicket.cleanup_expired($CONF[:proxy_granting_ticket_expiry])
  CASServer::Models::TicketGrantingTicket.cleanup_expired($CONF[:ticket_granting_ticket_expiry])
end

Instance Method Details

#available_localesObject



59
60
61
# File 'lib/casserver/localization.rb', line 59

def available_locales
  (Dir.glob(File.join(File.dirname(File.expand_path(__FILE__)), "../../locale/[a-z]*")).map{|path| File.basename(path)} << "en").uniq.collect{|l| l.gsub('_','-')}
end

#determine_localeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/casserver/localization.rb', line 14

def determine_locale
  lang = ($CONF[:default_locale] || "en")
  lang = @input['lang'] unless @input['lang'].blank? 
  lang ||= @cookies['lang'] unless @cookies['lang'].blank? 
  lang ||= @env.HTTP_ACCEPT_LANGUAGE unless @env.HTTP_ACCEPT_LANGUAGE.blank?
  lang ||= @env.HTTP_USER_AGENT =~ /[^a-z]([a-z]{2}(-[a-z]{2})?)[^a-z]/i && 
            lang = $~[1] unless @env.HTTP_USER_AGENT.blank?
  @cookies['lang'] = lang
  
  lang.gsub!('_','-')
  
  # TODO: Need to confirm that this method of splitting the accepted
  #       language string is correct.
  if lang =~ /[,;\|]/
    langs = lang.split(/[,;\|]/)
  else
    langs = [lang]
  end
  
  # TODO: This method of selecting the desired language might not be
  #       standards-compliant. For example, http://www.w3.org/TR/ltli/
  #       suggests that de-de and de-*-DE might be acceptable identifiers
  #       for selecting various wildcards. The algorithm below does not
  #       currently support anything like this.
  
  available = available_locales
  
  # Try to pick a locale exactly matching the desired identifier, otherwise
  # fall back to locale without region (i.e. given "en-US; de-DE", we would
  # first look for "en-US", then "en", then "de-DE", then "de").
  
  chosen_lang = nil
  langs.each do |l| 
    a = available.find{|a| a == l || a =~ Regexp.new("#{l}-\w*")}
    if a
      chosen_lang = a
      break
    end
  end
  
  chosen_lang = "en" if chosen_lang.blank?
  
  return chosen_lang
end

#service(*a) ⇒ Object



8
9
10
11
12
# File 'lib/casserver/localization.rb', line 8

def service(*a)
  GetText.locale = determine_locale
  #puts GetText.locale.inspect
  super(*a)
end