Class: UCB::Rails::Security::CASAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/ucb_rails_security_casauthentication.rb

Overview

CAS Authentication Class

This class is where you override the default CAS settings.

Constant Summary collapse

ENV_DEVELOPMENT =
'development'
ENV_DEV_INTEGRATION =
'dev_integration'
ENV_TEST =
'test'
ENV_PRODUCTION =
'production'
CAS_BASE_URL_TEST =
"https://auth-test.berkeley.edu/cas"
CAS_BASE_URL_PRODUCTION =
"https://auth.berkeley.edu/cas"

Class Method Summary collapse

Class Method Details

.allow_test_entries=(bool) ⇒ Object



62
63
64
# File 'lib/ucb_rails_security_casauthentication.rb', line 62

def self.allow_test_entries=(bool)
  @allow_test_entries = bool
end

.allow_test_entries?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/ucb_rails_security_casauthentication.rb', line 58

def self.allow_test_entries?
  @allow_test_entries ||= (environment != ENV_PRODUCTION)
end

.cas_base_urlObject

Returns CAS base url to be used for CAS authentication. Default is based on Rails environment (RAILS_ENV).



53
54
55
56
# File 'lib/ucb_rails_security_casauthentication.rb', line 53

def self.cas_base_url
  return @cas_base_url if @cas_base_url
  (environment == ENV_PRODUCTION) ? CAS_BASE_URL_PRODUCTION : CAS_BASE_URL_TEST
end

.cas_base_url=(url) ⇒ Object

Setter for cas_base_url



67
68
69
# File 'lib/ucb_rails_security_casauthentication.rb', line 67

def self.cas_base_url=(url)
  @cas_base_url = url
end

.environmentObject

This method exists so it can be stubbed to test cas_base_url()



85
86
87
# File 'lib/ucb_rails_security_casauthentication.rb', line 85

def self.environment #:nodoc:
  RAILS_ENV
end

.filter(controller) ⇒ Object

Filter for CAS authentication. To use filter, in controller:

before_filter UCB::Rails::Security::CASAuthentication

or use the controller method instead

before_filter :filter_logged_in


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ucb_rails_security_casauthentication.rb', line 31

def self.filter(controller) #:nodoc:
  logger.debug("In UCB::Rails::Security::CASAuthentication.filter")
  if environment == ENV_TEST && 
    controller.session[:cas_user] = 
    return true
  end
  CASClient::Frameworks::Rails::Filter.configure(
    :cas_base_url => self.cas_base_url(),
    :logger => self.logger()
  )

  logger.debug("Before CASClient::Frameworks::Rails::Filter.filter(controller)")
  if CASClient::Frameworks::Rails::Filter.filter(controller)
    logger.debug("After CASClient::Frameworks::Rails::Filter.filter(controller)")
    return true
  else
    return false
  end
end

.force_login_filter_true_forObject

LDAP Uid for which login is forced successful if in test environemnt.



91
92
93
# File 'lib/ucb_rails_security_casauthentication.rb', line 91

def self.()
  @force_login_filter_true_for || false
end

.force_login_filter_true_for=(ldap_uid) ⇒ Object

In test environment, every call to #filter() will simulate successful authentication for ldap_uid if this method is called.



98
99
100
# File 'lib/ucb_rails_security_casauthentication.rb', line 98

def self.(ldap_uid)
  @force_login_filter_true_for = ldap_uid
end

.home_urlObject



80
81
82
# File 'lib/ucb_rails_security_casauthentication.rb', line 80

def self.home_url
  @home_url || "ucb_security"
end

.home_url=(url) ⇒ Object



76
77
78
# File 'lib/ucb_rails_security_casauthentication.rb', line 76

def self.home_url=(url)
  @home_url = url
end

.loggerObject



19
20
21
# File 'lib/ucb_rails_security_casauthentication.rb', line 19

def self.logger()
  UCB::Rails::Security.logger
end

.logout_urlObject

Returns CAS logout url



72
73
74
# File 'lib/ucb_rails_security_casauthentication.rb', line 72

def self.logout_url
  "#{self.cas_base_url}/logout"
end

.reset_instance_variablesObject

Used for testing



108
109
110
111
112
113
# File 'lib/ucb_rails_security_casauthentication.rb', line 108

def self.reset_instance_variables() #:nodoc:
  self. = nil
  self.cas_base_url = nil
  self.allow_test_entries = nil
  self.home_url = nil
end