devise_cas_authenticatable 1.0.0.alpha1 → 1.0.0.alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/app/controllers/cas_sessions_controller.rb +11 -1
- data/devise_cas_authenticatable.gemspec +55 -0
- data/lib/devise_cas_authenticatable/exceptions.rb +8 -0
- data/lib/devise_cas_authenticatable/model.rb +11 -7
- data/lib/devise_cas_authenticatable/routes.rb +2 -0
- data/lib/devise_cas_authenticatable/strategy.rb +12 -4
- data/lib/devise_cas_authenticatable.rb +1 -0
- metadata +4 -2
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            1.0.0. | 
| 1 | 
            +
            1.0.0.alpha2
         | 
| @@ -1,7 +1,17 @@ | |
| 1 1 | 
             
            class CasSessionsController < ApplicationController
         | 
| 2 | 
            -
              prepend_before_filter :require_no_authentication, :only => [:login]
         | 
| 3 2 | 
             
              include Devise::Controllers::InternalHelpers
         | 
| 4 3 |  | 
| 4 | 
            +
              def create
         | 
| 5 | 
            +
                resource = authenticate(resource_name)
         | 
| 6 | 
            +
                if resource
         | 
| 7 | 
            +
                  sign_in_and_redirect(resource)
         | 
| 8 | 
            +
                elsif warden.result == :redirect
         | 
| 9 | 
            +
                  throw :warden, :scope => resource_name
         | 
| 10 | 
            +
                else
         | 
| 11 | 
            +
                  throw InvalidCasTicketException.new(params[:ticket])
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
                  
         | 
| 5 15 | 
             
              def destroy
         | 
| 6 16 | 
             
                sign_out(resource_name)
         | 
| 7 17 | 
             
                destination = request.protocol
         | 
| @@ -0,0 +1,55 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{devise_cas_authenticatable}
         | 
| 8 | 
            +
              s.version = "1.0.0.alpha2"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Nat Budin"]
         | 
| 12 | 
            +
              s.date = %q{2010-05-06}
         | 
| 13 | 
            +
              s.description = %q{CAS authentication module for Devise}
         | 
| 14 | 
            +
              s.email = %q{natbudin@gmail.com}
         | 
| 15 | 
            +
              s.extra_rdoc_files = [
         | 
| 16 | 
            +
                "README.md"
         | 
| 17 | 
            +
              ]
         | 
| 18 | 
            +
              s.files = [
         | 
| 19 | 
            +
                ".project",
         | 
| 20 | 
            +
                 "README.md",
         | 
| 21 | 
            +
                 "Rakefile",
         | 
| 22 | 
            +
                 "VERSION",
         | 
| 23 | 
            +
                 "app/controllers/cas_sessions_controller.rb",
         | 
| 24 | 
            +
                 "devise_cas_authenticatable.gemspec",
         | 
| 25 | 
            +
                 "lib/devise_cas_authenticatable.rb",
         | 
| 26 | 
            +
                 "lib/devise_cas_authenticatable/exceptions.rb",
         | 
| 27 | 
            +
                 "lib/devise_cas_authenticatable/model.rb",
         | 
| 28 | 
            +
                 "lib/devise_cas_authenticatable/routes.rb",
         | 
| 29 | 
            +
                 "lib/devise_cas_authenticatable/schema.rb",
         | 
| 30 | 
            +
                 "lib/devise_cas_authenticatable/strategy.rb",
         | 
| 31 | 
            +
                 "rails/init.rb"
         | 
| 32 | 
            +
              ]
         | 
| 33 | 
            +
              s.homepage = %q{http://github.com/nbudin/devise_cas_authenticatable}
         | 
| 34 | 
            +
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 35 | 
            +
              s.require_paths = ["lib"]
         | 
| 36 | 
            +
              s.rubygems_version = %q{1.3.6}
         | 
| 37 | 
            +
              s.summary = %q{CAS authentication module for Devise}
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              if s.respond_to? :specification_version then
         | 
| 40 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 41 | 
            +
                s.specification_version = 3
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
         | 
| 44 | 
            +
                  s.add_runtime_dependency(%q<devise>, ["~> 1.0.6"])
         | 
| 45 | 
            +
                  s.add_runtime_dependency(%q<rubycas-client>, ["~> 2.1.0"])
         | 
| 46 | 
            +
                else
         | 
| 47 | 
            +
                  s.add_dependency(%q<devise>, ["~> 1.0.6"])
         | 
| 48 | 
            +
                  s.add_dependency(%q<rubycas-client>, ["~> 2.1.0"])
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              else
         | 
| 51 | 
            +
                s.add_dependency(%q<devise>, ["~> 1.0.6"])
         | 
| 52 | 
            +
                s.add_dependency(%q<rubycas-client>, ["~> 2.1.0"])
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| 55 | 
            +
             | 
| @@ -4,12 +4,13 @@ module Devise | |
| 4 4 | 
             
                  def self.included(base)
         | 
| 5 5 | 
             
                    base.extend ClassMethods
         | 
| 6 6 | 
             
                  end
         | 
| 7 | 
            -
             | 
| 7 | 
            +
                        
         | 
| 8 8 | 
             
                  module ClassMethods
         | 
| 9 9 | 
             
                    def authenticate_with_cas_ticket(ticket)
         | 
| 10 10 | 
             
                      ::Devise.cas_client.validate_service_ticket(ticket) unless ticket.has_been_validated?
         | 
| 11 11 |  | 
| 12 12 | 
             
                      if ticket.is_valid?
         | 
| 13 | 
            +
                        logger.debug "Ticket is valid and is for user #{ticket.response.user}"
         | 
| 13 14 | 
             
                        conditions = {:username => ticket.response.user}
         | 
| 14 15 | 
             
                        puts conditions.inspect
         | 
| 15 16 |  | 
| @@ -18,27 +19,30 @@ module Devise | |
| 18 19 | 
             
                        return nil unless resource
         | 
| 19 20 |  | 
| 20 21 | 
             
                        if resource.new_record?
         | 
| 22 | 
            +
                          logger.debug "Creating new user record"
         | 
| 21 23 | 
             
                          if resource.respond_to? :cas_extra_attributes=
         | 
| 22 24 | 
             
                            resource.cas_extra_attributes = ticket.response.extra_attributes
         | 
| 23 25 | 
             
                          end
         | 
| 24 26 |  | 
| 25 27 | 
             
                          create(conditions)
         | 
| 26 28 | 
             
                        else
         | 
| 27 | 
            -
                          if  | 
| 28 | 
            -
                             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
                            end
         | 
| 29 | 
            +
                          if resource.respond_to? :cas_extra_attributes=
         | 
| 30 | 
            +
                            logger.debug "Updating existing user record"
         | 
| 31 | 
            +
                            resource.cas_extra_attributes = ticket.response.extra_attributes
         | 
| 32 | 
            +
                            resource.save
         | 
| 32 33 | 
             
                          end
         | 
| 33 34 |  | 
| 34 35 | 
             
                          resource
         | 
| 35 36 | 
             
                        end
         | 
| 37 | 
            +
                      else
         | 
| 38 | 
            +
                        logger.debug "Ticket is invalid"
         | 
| 39 | 
            +
                        return nil
         | 
| 36 40 | 
             
                      end
         | 
| 37 41 | 
             
                    end
         | 
| 38 42 |  | 
| 39 43 | 
             
                    protected
         | 
| 40 44 | 
             
                    def find_for_cas_authentication(conditions)
         | 
| 41 | 
            -
                      find(:first, :conditions => conditions)
         | 
| 45 | 
            +
                      self.find(:first, :conditions => conditions)
         | 
| 42 46 | 
             
                    end
         | 
| 43 47 | 
             
                  end
         | 
| 44 48 | 
             
                end
         | 
| @@ -3,6 +3,8 @@ ActionController::Routing::RouteSet::Mapper.class_eval do | |
| 3 3 |  | 
| 4 4 | 
             
              def cas_authenticatable(routes, mapping)
         | 
| 5 5 | 
             
                routes.with_options(:controller => 'cas_sessions', :name_prefix => nil) do |session|
         | 
| 6 | 
            +
                  session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :get})
         | 
| 7 | 
            +
                  session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => {:method => :post})
         | 
| 6 8 | 
             
                  session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], :action => 'destroy', :conditions => { :method => :get })
         | 
| 7 9 | 
             
                end
         | 
| 8 10 | 
             
              end
         | 
| @@ -9,6 +9,7 @@ module Devise | |
| 9 9 |  | 
| 10 10 | 
             
                  def authenticate!
         | 
| 11 11 | 
             
                    ticket = read_ticket(params)
         | 
| 12 | 
            +
                    RAILS_DEFAULT_LOGGER.debug "Received CAS ticket: #{ticket.inspect}"
         | 
| 12 13 | 
             
                    if ticket
         | 
| 13 14 | 
             
                      if resource = mapping.to.authenticate_with_cas_ticket(ticket)
         | 
| 14 15 | 
             
                        success!(resource)
         | 
| @@ -26,9 +27,16 @@ module Devise | |
| 26 27 | 
             
                  def returning_from_cas?
         | 
| 27 28 | 
             
                    request.referer =~ /^#{::Devise.cas_client.cas_base_url}/
         | 
| 28 29 | 
             
                  end
         | 
| 29 | 
            -
             | 
| 30 | 
            +
                  
         | 
| 31 | 
            +
                  def service_url
         | 
| 32 | 
            +
                    url = URI.parse(request.url)
         | 
| 33 | 
            +
                    url.path = "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}"
         | 
| 34 | 
            +
                    url.query = nil
         | 
| 35 | 
            +
                    url.to_s
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                  
         | 
| 30 38 | 
             
                  def login_url
         | 
| 31 | 
            -
                    ::Devise.cas_client.add_service_to_login_url( | 
| 39 | 
            +
                    ::Devise.cas_client.add_service_to_login_url(service_url)
         | 
| 32 40 | 
             
                  end
         | 
| 33 41 |  | 
| 34 42 | 
             
                  def read_ticket(params)
         | 
| @@ -36,9 +44,9 @@ module Devise | |
| 36 44 | 
             
                    return nil unless ticket
         | 
| 37 45 |  | 
| 38 46 | 
             
                    if ticket =~ /^PT-/
         | 
| 39 | 
            -
                      ::CASClient::ProxyTicket.new(ticket,  | 
| 47 | 
            +
                      ::CASClient::ProxyTicket.new(ticket, service_url, params[:renew])
         | 
| 40 48 | 
             
                    else
         | 
| 41 | 
            -
                      ::CASClient::ServiceTicket.new(ticket,  | 
| 49 | 
            +
                      ::CASClient::ServiceTicket.new(ticket, service_url, params[:renew])
         | 
| 42 50 | 
             
                    end
         | 
| 43 51 | 
             
                  end
         | 
| 44 52 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version | |
| 6 6 | 
             
              - 1
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.0.0. | 
| 9 | 
            +
              - alpha2
         | 
| 10 | 
            +
              version: 1.0.0.alpha2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Nat Budin
         | 
| @@ -60,7 +60,9 @@ files: | |
| 60 60 | 
             
            - Rakefile
         | 
| 61 61 | 
             
            - VERSION
         | 
| 62 62 | 
             
            - app/controllers/cas_sessions_controller.rb
         | 
| 63 | 
            +
            - devise_cas_authenticatable.gemspec
         | 
| 63 64 | 
             
            - lib/devise_cas_authenticatable.rb
         | 
| 65 | 
            +
            - lib/devise_cas_authenticatable/exceptions.rb
         | 
| 64 66 | 
             
            - lib/devise_cas_authenticatable/model.rb
         | 
| 65 67 | 
             
            - lib/devise_cas_authenticatable/routes.rb
         | 
| 66 68 | 
             
            - lib/devise_cas_authenticatable/schema.rb
         |