Module: CASServer::Utils

Defined in:
lib/casserver/utils.rb

Class Method Summary collapse

Class Method Details

.initialize_service_whitelist(whitelist) ⇒ Object

Synapses CAS 0.1.2 - Thanks to github.com/dyson/rubycas-server



33
34
35
36
37
# File 'lib/casserver/utils.rb', line 33

def initialize_service_whitelist(whitelist)
  $LOG.debug("Initializing Service Whitelist")
  whitelist = whitelist || ''
  whitelist.split(',')
end

.log_controller_action(controller, params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/casserver/utils.rb', line 16

def log_controller_action(controller, params)
  $LOG << "\n"

  /`(.*)'/.match(caller[1])
  method = $~[1]

  if params.respond_to? :dup
    params2 = params.dup
    params2['password'] = '******' if params2['password']
  else
    params2 = params
  end
  $LOG.debug("Processing #{controller}::#{method} #{params2.inspect}")
end

.random_string(max_length = 29) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/casserver/utils.rb', line 6

def random_string(max_length = 29)
  rg =  Crypt::ISAAC.new
  max = 4294619050
  r = "#{Time.now.to_i}r%X%X%X%X%X%X%X%X" %
    [rg.rand(max), rg.rand(max), rg.rand(max), rg.rand(max),
     rg.rand(max), rg.rand(max), rg.rand(max), rg.rand(max)]
  r[0..max_length-1]
end

.validate_service(service, whitelist) ⇒ Object

Synapses CAS 0.1.2 - Thanks to github.com/dyson/rubycas-server



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/casserver/utils.rb', line 41

def validate_service(service, whitelist)
  $LOG.debug("Validating service \"#{service}\"")
  if !whitelist.empty?
    whitelist.each do |domain|
      return service if service.to_s[0, domain.length] == domain # starts with
    end
  else
    return service if whitelist.empty?
  end
  $LOG.warn("Service \"#{service}\" is not in service whitelist")
  return nil
end