Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial check-in

  • Loading branch information...
commit 085a59296d0f31db139e442208f239644cb9db9b 0 parents
Joe George authored
BIN  .DS_Store
Binary file not shown
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
48 .gitignore
@@ -0,0 +1,48 @@
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+#.DS_Store
+
+# For TextMate
+#*.tmproj
+#tmtags
+
+# For emacs:
+#*~
+#\#*
+#.\#*
+
+# For vim:
+#*.swp
+
+# For redcar:
+#.redcar
+
+# For rubinius:
+#*.rbc
8 Gemfile
@@ -0,0 +1,8 @@
+source "http://rubygems.org"
+
+group :development do
+ gem "shoulda", ">= 0"
+ gem "bundler", "~> 1.0.0"
+ gem "jeweler", "~> 1.6.4"
+ gem "rcov", ">= 0"
+end
20 Gemfile.lock
@@ -0,0 +1,20 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ git (1.2.5)
+ jeweler (1.6.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rake (0.9.2)
+ rcov (0.9.11)
+ shoulda (2.11.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (~> 1.0.0)
+ jeweler (~> 1.6.4)
+ rcov
+ shoulda
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Joe George
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 README.rdoc
@@ -0,0 +1,19 @@
+= devise_shibboleth_authenticatable
+
+Devise Shibboleth Authenticatable is a Shibboleth based authentication strategy for the [Devise](http://github.com/plataformatec/devise) authentication framework.
+
+== Contributing to devise_shibboleth_authenticatable
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
+* Fork the project
+* Start a feature/bugfix branch
+* Commit and push until you are happy with your contribution
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+== Copyright
+
+Copyright (c) 2011 Joe George. See LICENSE.txt for
+further details.
+
40 Rakefile
@@ -0,0 +1,40 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the devise_imapable plugin.'
+Rake::TestTask.new(:test) do |t|
+ # t.libs << 'lib'
+ # t.libs << 'test'
+ # t.pattern = 'test/**/*_test.rb'
+ # t.verbose = true
+end
+
+desc 'Generate documentation for the devise_shibboleth_authenticatable plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'DeviseShibbolethAuthenticatable'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "devise_shibboleth_authenticatable"
+ gemspec.summary = "Shibboleth authentication module for Devise"
+ gemspec.description = "Shibboleth authentication module for Devise"
+ gemspec.email = "joe.george@osumc.edu"
+ gemspec.homepage = "http://github.com/jgeorge300/devise_shibboleth_authenticatable"
+ gemspec.authors = ["Joe George"]
+ gemspec.add_runtime_dependency "devise", "~> 1.4.0"
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
1  VERSION
@@ -0,0 +1 @@
+0.0.1
57 devise_shibboleth_authenticatable.gemspec
@@ -0,0 +1,57 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "devise_shibboleth_authenticatable"
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Joe George"]
+ s.date = "2011-10-18"
+ s.description = "Shibboleth authentication module for Devise"
+ s.email = "joe.george@osumc.edu"
+ s.extra_rdoc_files = [
+ "LICENSE.txt",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ "Gemfile",
+ "LICENSE.txt",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/devise_shibboleth_authenticatable.rb"
+ ]
+ s.homepage = "http://github.com/jgeorge300/devise_shibboleth_authenticatable"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.10"
+ s.summary = "Shibboleth authentication module for Devise"
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
+ s.add_development_dependency(%q<rcov>, [">= 0"])
+ s.add_runtime_dependency(%q<devise>, ["~> 1.4.0"])
+ else
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ s.add_dependency(%q<devise>, ["~> 1.4.0"])
+ end
+ else
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ s.add_dependency(%q<devise>, ["~> 1.4.0"])
+ end
+end
+
30 lib/devise_shibboleth_authenticatable.rb
@@ -0,0 +1,30 @@
+# encoding: utf-8
+require 'devise'
+
+require 'devise_shibboleth_authenticatable/exception'
+require 'devise_shibboleth_authenticatable/logger'
+require 'devise_shibboleth_authenticatable/schema'
+require 'devise_shibboleth_authenticatable/routes'
+
+# Get shibboleth information from config/shibboleth.yml now
+module Devise
+ # Allow logging
+ mattr_accessor :shibboleth_logger
+ @@shibboleth_logger = true
+
+ # Add valid users to database
+ mattr_accessor :shibboleth_create_user
+ @@shibboleth_create_user = false
+
+ mattr_accessor :shibboleth_config
+ # @@shibboleth_config = "#{Rails.root}/config/shibboleth.yml"
+
+end
+
+# Add shibboleth_authenticatable strategy to defaults.
+#
+Devise.add_module(:shibboleth_authenticatable,
+ :route => :session, ## This will add the routes, rather than in the routes.rb
+ :strategy => true,
+ :controller => :sessions,
+ :model => 'devise_shibboleth_authenticatable/model')
BIN  lib/devise_shibboleth_authenticatable/.DS_Store
Binary file not shown
6 lib/devise_shibboleth_authenticatable/exception.rb
@@ -0,0 +1,6 @@
+module DeviseShibbolethAuthenticatable
+
+ class ShibbolethException < Exception
+ end
+
+end
11 lib/devise_shibboleth_authenticatable/logger.rb
@@ -0,0 +1,11 @@
+module DeviseShibbolethAuthenticatable
+
+ class Logger
+ def self.send(message, logger = Rails.logger)
+ if ::Devise.shibboleth_logger
+ logger.add 0, " \e[36mShibboleth:\e[0m #{message}"
+ end
+ end
+ end
+
+end
32 lib/devise_shibboleth_authenticatable/model.rb
@@ -0,0 +1,32 @@
+require 'devise_shibboleth_authenticatable/strategy'
+
+module Devise
+ module Models
+ module ShibbolethAuthenticatable
+ extend ActiveSupport::Concern
+
+ included do
+ attr_reader :password, :current_password
+ attr_accessor :password_confirmation
+ end
+
+ module ClassMethods
+ def authenticate_with_shibboleth(env)
+ resource = User.find_by_email(env['eppn'])
+
+ resource = new() if (resource.nil?)
+ return nil unless resource
+
+ resource.email = env['eppn']
+ resource.name = env['LAST-NAME']
+ resource.save
+ resource
+ end
+
+ def find_for_shibb_authentication(conditions)
+ find_for_authentication(conditions)
+ end
+ end
+ end
+ end
+end
8 lib/devise_shibboleth_authenticatable/routes.rb
@@ -0,0 +1,8 @@
+## No routes needed anymore since Devise.add_module with the :route parameter will take care of it.
+
+# ActionController::Routing::RouteSet::Mapper.class_eval do
+#
+# protected
+# # reuse the session routes and controller
+# alias :shibboleth_authenticatable :database_authenticatable
+# end
14 lib/devise_shibboleth_authenticatable/schema.rb
@@ -0,0 +1,14 @@
+## Using email now instead of login. Will add an option later on.
+
+# Devise::Schema.class_eval do
+# # Creates login
+# #
+# # == Options
+# # * :null - When true, allow columns to be null.
+# def shibboleth_authenticatable(options={})
+# null = options[:null] || false
+#
+# apply_schema :login, String, :null => null
+# end
+#
+# end
36 lib/devise_shibboleth_authenticatable/strategy.rb
@@ -0,0 +1,36 @@
+require 'devise/strategies/authenticatable'
+
+module Devise
+ module Strategies
+ class ShibbolethAuthenticatable < Authenticatable
+ def valid?
+ request.env['eppn']
+ end
+
+ def authenticate!
+ eppn = read_shibbolethvars(params)
+
+ if resource = mapping.to.authenticate_with_shibboleth(request.env)
+ success!(resource)
+ else
+ fail!(:invalid)
+ end
+
+ end
+
+ protected
+
+ def read_shibbolethvars(params)
+
+ eppn = request.env['eppn']
+ lname = request.env['LAST-NAME']
+ fname = request.env['FIRST-NAME']
+ eppn
+
+ end
+
+ end
+ end
+end
+
+Warden::Strategies.add(:shibboleth_authenticatable, Devise::Strategies::ShibbolethAuthenticatable)
4 lib/devise_shibboleth_authenticatable/version.rb
@@ -0,0 +1,4 @@
+module DeviseShibbolethAuthenticatable
+ VERSION = "0.0.1"
+end
+
56 lib/generators/devise_shibboleth_authenticatable/install_generator.rb
@@ -0,0 +1,56 @@
+module DeviseShibbolethAuthenticatable
+ class InstallGenerator < Rails::Generators::Base
+ source_root File.expand_path("../templates", __FILE__)
+
+ class_option :user_model, :type => :string, :default => "user", :desc => "Model to update"
+ class_option :update_model, :type => :boolean, :default => true, :desc => "Update model to change from database_authenticatable to shibboleth_authenticatable"
+ class_option :add_rescue, :type => :boolean, :default => true, :desc => "Update Application Controller with resuce_from for DeviseShibbolethAuthenticatable::ShibbolethException"
+ class_option :advanced, :type => :boolean, :desc => "Add advanced config options to the devise initializer"
+
+
+ def create_shibboleth_config
+ copy_file "shibboleth.yml", "config/shibboleth.yml"
+ end
+
+ def create_default_devise_settings
+ inject_into_file "config/initializers/devise.rb", default_devise_settings, :after => "Devise.setup do |config|\n"
+ end
+
+ def update_user_model
+ gsub_file "app/models/#{options.user_model}.rb", /:database_authenticatable/, ":shibboleth_authenticatable" if options.update_model?
+ end
+
+ def update_application_controller
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController, rescue_from_exception if options.add_rescue?
+ end
+
+ private
+
+ def default_devise_settings
+ settings = <<-eof
+ # ==> Shibboleth Configuration
+ # config.shibboleth_logger = true
+ # config.shibboleth_create_user = false
+ # config.shibboleth_config = "\#{Rails.root}/config/shibboleth.yml"
+
+ eof
+ if options.advanced?
+ settings << <<-eof
+ # ==> Advanced Shibboleth Configuration
+
+ eof
+ end
+
+ settings
+ end
+
+ def rescue_from_exception
+ <<-eof
+ rescue_from DeviseShibbolethAuthenticatable::ShibbolethException do |exception|
+ render :text => exception, :status => 500
+ end
+ eof
+ end
+
+ end
+end
7 lib/generators/devise_shibboleth_authenticatable/templates/shibboleth.yml
@@ -0,0 +1,7 @@
+## Enviornments
+
+development:
+
+test:
+
+production:
2  rails/init.rb
@@ -0,0 +1,2 @@
+# Include hook code here
+require 'devise_shibboleth_authenticatable'
Please sign in to comment.
Something went wrong with that request. Please try again.