Module: Cassette::Rubycas::Helper

Extended by:
ActiveSupport::Concern
Defined in:
lib/cassette/rubycas/helper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#cas_logout(to = root_url) ⇒ Object



36
37
38
39
# File 'lib/cassette/rubycas/helper.rb', line 36

def cas_logout(to = root_url)
  session.destroy
  ::CASClient::Frameworks::Rails::Filter.logout(self, to)
end

#current_userObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cassette/rubycas/helper.rb', line 59

def current_user
  return fake_user if ENV['NOAUTH']
  return nil unless session[:cas_user]

  @current_user ||= begin
    attributes = session[:cas_extra_attributes]
    Cassette::Authentication::User.new(login: session[:cas_user],
                                       name: attributes.try(:[], :cn),
                                       email: attributes.try(:[], :email),
                                       authorities: attributes.try(:[], :authorities),
                                       type: attributes.try(:[], :type).try(:downcase))
  end
end

#customer_only_filterObject



31
32
33
34
# File 'lib/cassette/rubycas/helper.rb', line 31

def customer_only_filter
  return if ENV['NOAUTH'] || current_user.blank?
  fail Cassette::Errors::NotACustomer unless current_user.customer?
end

#employee_only_filterObject



26
27
28
29
# File 'lib/cassette/rubycas/helper.rb', line 26

def employee_only_filter
  return if ENV['NOAUTH'] || current_user.blank?
  fail Cassette::Errors::NotAnEmployee unless current_user.employee?
end

#fake_userObject



41
42
43
44
45
46
47
# File 'lib/cassette/rubycas/helper.rb', line 41

def fake_user
  Cassette::Authentication::User.new(login: 'fake.user',
                                     name: 'Fake User',
                                     email: '[email protected]',
                                     authorities: [],
                                     type: 'customer')
end

#validate_authentication_ticketObject



21
22
23
24
# File 'lib/cassette/rubycas/helper.rb', line 21

def validate_authentication_ticket
  return if ENV['NOAUTH']
  ::CASClient::Frameworks::Rails::Filter.filter(self)
end

#validate_raw_role!(role) ⇒ Object



54
55
56
57
# File 'lib/cassette/rubycas/helper.rb', line 54

def validate_raw_role!(role)
  return if ENV['NOAUTH']
  fail Cassette::Errors::Forbidden unless current_user.has_raw_role?(role)
end

#validate_role!(role) ⇒ Object



49
50
51
52
# File 'lib/cassette/rubycas/helper.rb', line 49

def validate_role!(role)
  return if ENV['NOAUTH']
  fail Cassette::Errors::Forbidden unless current_user.has_role?(role)
end