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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/casserver.rb', line 30

def CASServer.create
  $LOG.info "Creating RubyCAS-Server with pid #{Process.pid}."


  CASServer::Models::Base.establish_connection($CONF.database) unless CASServer::Models::Base.connected?
  CASServer::Models.create_schema

  #TODO: these warnings should eventually be deleted
  if $CONF.service_ticket_expiry
    $LOG.warn "The 'service_ticket_expiry' option has been renamed to 'maximum_unused_service_ticket_lifetime'. Please make the necessary change to your config file!"
    $CONF.maximum_unused_service_ticket_lifetime ||= $CONF.service_ticket_expiry
  end
  if $CONF.
    $LOG.warn "The 'login_ticket_expiry' option has been renamed to 'maximum_unused_login_ticket_lifetime'. Please make the necessary change to your config file!"
    $CONF. ||= $CONF.
  end
  if $CONF.ticket_granting_ticket_expiry || $CONF.proxy_granting_ticket_expiry
    $LOG.warn "The 'ticket_granting_ticket_expiry' and 'proxy_granting_ticket_expiry' options have been renamed to 'maximum_session_lifetime'. Please make the necessary change to your config file!"
    $CONF.maximum_session_lifetime ||= $CONF.ticket_granting_ticket_expiry || $CONF.proxy_granting_ticket_expiry
  end

  if $CONF.maximum_session_lifetime
    CASServer::Models::ServiceTicket.cleanup($CONF.maximum_session_lifetime, $CONF.maximum_unused_service_ticket_lifetime)
    CASServer::Models::LoginTicket.cleanup($CONF.maximum_session_lifetime, $CONF.)
    CASServer::Models::ProxyGrantingTicket.cleanup($CONF.maximum_session_lifetime)
    CASServer::Models::TicketGrantingTicket.cleanup($CONF.maximum_session_lifetime)
  end
end

Instance Method Details

#available_localesObject



79
80
81
# File 'lib/casserver/localization.rb', line 79

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/casserver/localization.rb', line 14

def determine_locale

  source = nil
  lang = case
  when !input['lang'].blank?
    source = "'lang' request variable"
    cookies['lang'] = input['lang']
    input['lang']
  when !cookies['lang'].blank?
    source = "'lang' cookie"
    cookies['lang']
  when !@env['HTTP_ACCEPT_LANGUAGE'].blank?
    source = "'HTTP_ACCEPT_LANGUAGE' header"
    lang = @env['HTTP_ACCEPT_LANGUAGE']
  when !@env['HTTP_USER_AGENT'].blank? && @env['HTTP_USER_AGENT'] =~ /[^a-z]([a-z]{2}(-[a-z]{2})?)[^a-z]/i
    source = "'HTTP_USER_AGENT' header"
    $~[1]
  when !$CONF['default_locale'].blank?
    source = "'default_locale' config option"
    $CONF[:default_locale]
  else
    source = "default"
    "en"
  end

  $LOG.debug "Detected locale is #{lang.inspect} (from #{source})"

  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?

  $LOG.debug "Chosen locale is #{chosen_lang.inspect}"

  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