Module: Cassette::Authentication::Filter
- Defined in:
- lib/cassette/authentication/filter.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #accepts_authentication_service?(service) ⇒ Boolean
- #authentication_service ⇒ Object
- #validate_authentication_ticket(service = authentication_service) ⇒ Object
- #validate_raw_role!(role) ⇒ Object
- #validate_role!(role) ⇒ Object
Class Method Details
.included(controller) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/cassette/authentication/filter.rb', line 8 def self.included(controller) controller.extend(ClassMethods) if controller.respond_to?(:before_action) controller.before_action(:validate_authentication_ticket) else controller.before_filter(:validate_authentication_ticket) end controller.send(:attr_accessor, :current_user) end |
Instance Method Details
#accepts_authentication_service?(service) ⇒ Boolean
28 29 30 31 32 33 34 35 36 |
# File 'lib/cassette/authentication/filter.rb', line 28 def accepts_authentication_service?(service) config = Cassette.config if config.respond_to?(:services) config.services.member?(service) || config.service == service else config.service == service end end |
#authentication_service ⇒ Object
51 52 53 |
# File 'lib/cassette/authentication/filter.rb', line 51 def authentication_service Cassette.config.service end |
#validate_authentication_ticket(service = authentication_service) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cassette/authentication/filter.rb', line 38 def validate_authentication_ticket(service = authentication_service) ticket = request.headers['Service-Ticket'] || params[:ticket] if ENV['NOAUTH'] Cassette.logger.debug 'NOAUTH set and no Service Ticket, skipping authentication' self.current_user = Cassette::Authentication::User.new return end fail Cassette::Errors::Forbidden unless accepts_authentication_service?(authentication_service) self.current_user = Cassette::Authentication.validate_ticket(ticket, service) end |
#validate_raw_role!(role) ⇒ Object
60 61 62 63 |
# File 'lib/cassette/authentication/filter.rb', line 60 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
55 56 57 58 |
# File 'lib/cassette/authentication/filter.rb', line 55 def validate_role!(role) return if ENV['NOAUTH'] fail Cassette::Errors::Forbidden unless current_user.has_role?(role) end |