Class: Cassette::Authentication
- Inherits:
-
Object
- Object
- Cassette::Authentication
- Defined in:
- lib/cassette/authentication.rb
Defined Under Namespace
Modules: Filter Classes: Authorities, Cache, User
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Authentication
constructor
A new instance of Authentication.
- #ticket_user(ticket, service = config.service) ⇒ Object
- #validate_ticket(ticket, service = config.service) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Authentication
Returns a new instance of Authentication.
13 14 15 16 17 18 |
# File 'lib/cassette/authentication.rb', line 13 def initialize(opts = {}) self.config = opts.fetch(:config, Cassette.config) self.logger = opts.fetch(:logger, Cassette.logger) self.http = opts.fetch(:http_client, Cassette) self.cache = opts.fetch(:cache, Cassette::Authentication::Cache.new(logger)) end |
Class Method Details
.method_missing(name, *args) ⇒ Object
8 9 10 11 |
# File 'lib/cassette/authentication.rb', line 8 def self.method_missing(name, *args) @@default_authentication ||= new @@default_authentication.send(name, *args) end |
Instance Method Details
#ticket_user(ticket, service = config.service) ⇒ Object
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 |
# File 'lib/cassette/authentication.rb', line 32 def ticket_user(ticket, service = config.service) cache.fetch_authentication(ticket) do begin logger.info("Validating #{ticket} on #{validate_uri}") response = http.post(validate_uri, ticket: ticket, service: service).body logger.info("Validation resut: #{response.inspect}") user = nil ActiveSupport::XmlMini.with_backend("LibXML") do result = ActiveSupport::XmlMini.parse(response) login = result.try(:[], "serviceResponse").try(:[], "authenticationSuccess").try(:[], "user").try(:[], "__content__") if login attributes = result["serviceResponse"]["authenticationSuccess"]["attributes"] name = attributes.try(:[], "cn").try(:[], "__content__") = attributes.try(:[], "authorities").try(:[], "__content__") user = Cassette::Authentication::User.new(login: login, name: name, authorities: , ticket: ticket, config: config) end end user rescue => exception logger.error "Error while authenticating ticket #{ticket}: #{exception.}" raise Cassette::Errors::Forbidden.new(exception.) end end end |
#validate_ticket(ticket, service = config.service) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cassette/authentication.rb', line 20 def validate_ticket(ticket, service = config.service) logger.debug "Cassette::Authentication validating ticket: #{ticket}" raise Cassette::Errors::AuthorizationRequired if ticket.nil? || ticket.blank? user = ticket_user(ticket, service) logger.info "Cassette::Authentication user: #{user.inspect}" raise Cassette::Errors::Forbidden unless user user end |