devise_pam_authenticatable 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.8.7@lithium18
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ Devise - PAM Authentication
2
+ ===========================
3
+
4
+ devise_pam_authenticatable is a Devise (http://github.com/plataformatec/devise)
5
+ extension for authenticating using PAM (Pluggable Authentication Modulues)
6
+ via the rpam gem.
7
+
8
+ This allows you to authenticate against the local hosts authentication
9
+ system including local account usernames and passwords.
10
+
11
+ There are obvious security risks with using PAM authentication via a
12
+ web-based application. Make sure you at least use SSL to keep usernames and
13
+ passwords encrypted via HTTPS.
14
+
15
+ Installation
16
+ ------------
17
+
18
+ In the Gemfile for your application:
19
+
20
+ gem "devise_pam_authenticatable", :git => "git://github.com/jwilson511/devise_pam_authenticatable.git"
21
+
22
+ Setup
23
+ -----
24
+
25
+ The devise_pam_authenticatable extension required the use of 'username' as
26
+ the login credential (not email). Make sure your Devise model is using
27
+ 'username' and not 'email'.
28
+
29
+ In your Devise model, ensure the following is present:
30
+
31
+ class User < ActiveRecord::Base
32
+
33
+ devise :pam_authenticatable
34
+
35
+ # Setup accessible (or protected) attributes for your model
36
+ attr_accessible :username, :password
37
+
38
+ end
39
+
40
+
41
+ References
42
+ ----------
43
+
44
+ * [Devise](http://github.com/plataformatec/devise)
45
+ * [Warden](http://github.com/hassox/warden)
46
+
47
+
48
+ Released under the MIT license
49
+
50
+ Copyright (c) 2011 James Wilson, LithiumCorp Pty Ltd
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the devise_pam_authenticatable plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the devise_pam_authenticatable plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'DevisePAMAuthenticatable'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+ begin
26
+ require 'jeweler'
27
+ Jeweler::Tasks.new do |gemspec|
28
+ gemspec.name = "devise_pam_authenticatable"
29
+ gemspec.summary = "Devise PAM authentication module using rpam"
30
+ gemspec.description = "For authenticating against PAM (Pluggable Authentication Modules)"
31
+ gemspec.email = "jwilson@lithiumcorp.com"
32
+ gemspec.homepage = "http://github.com/jwilson511/devise_pam_authenticatable"
33
+ gemspec.authors = ["James Wilson"]
34
+ gemspec.add_runtime_dependency "devise", "> 1.1.0"
35
+ gemspec.add_runtime_dependency "rpam"
36
+ end
37
+ Jeweler::GemcutterTasks.new
38
+ rescue LoadError
39
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
40
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{devise_pam_authenticatable}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["James Wilson"]
12
+ s.date = %q{2011-01-13}
13
+ s.description = %q{For authenticating against PAM (Pluggable Authentication Modules)}
14
+ s.email = %q{jwilson@lithiumcorp.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".rvmrc",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "devise_pam_authenticatable.gemspec",
25
+ "lib/devise_pam_authenticatable.rb",
26
+ "lib/devise_pam_authenticatable/model.rb",
27
+ "lib/devise_pam_authenticatable/pam_adapter.rb",
28
+ "lib/devise_pam_authenticatable/routes.rb",
29
+ "lib/devise_pam_authenticatable/strategy.rb",
30
+ "rails/init.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/jwilson511/devise_pam_authenticatable}
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.4.1}
35
+ s.summary = %q{Devise PAM authentication module using rpam}
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<devise>, ["> 1.1.0"])
42
+ s.add_runtime_dependency(%q<rpam>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<devise>, ["> 1.1.0"])
45
+ s.add_dependency(%q<rpam>, [">= 0"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<devise>, ["> 1.1.0"])
49
+ s.add_dependency(%q<rpam>, [">= 0"])
50
+ end
51
+ end
52
+
@@ -0,0 +1,10 @@
1
+ require 'devise'
2
+
3
+ $: << File.expand_path("..", __FILE__)
4
+
5
+ require 'devise_pam_authenticatable/model'
6
+ require 'devise_pam_authenticatable/strategy'
7
+ require 'devise_pam_authenticatable/routes'
8
+ require 'devise_pam_authenticatable/pam_adapter'
9
+
10
+ Devise.add_module(:pam_authenticatable, :strategy => true, :model => "devise_pam_authenticatable/model", :route => true)
@@ -0,0 +1,43 @@
1
+ require 'devise_pam_authenticatable/strategy'
2
+
3
+ module Devise
4
+ module Models
5
+ module PamAuthenticatable
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ extend ClassMethods
10
+
11
+ attr_accessor :password
12
+ end
13
+ end
14
+
15
+ # Set password to nil
16
+ def clean_up_passwords
17
+ self.password = nil
18
+ end
19
+
20
+ # Checks if a resource is valid upon authentication.
21
+ def valid_pam_authentication?(password)
22
+ Devise::PamAdapter.valid_credentials?(self.username, password)
23
+ end
24
+
25
+ module ClassMethods
26
+ def authenticate_with_pam(attributes={})
27
+ return nil unless attributes[:username].present?
28
+
29
+ resource = new
30
+ resource[:username] = attributes[:username]
31
+ resource[:password] = attributes[:password]
32
+
33
+ if resource.try(:valid_pam_authentication?, attributes[:password])
34
+ resource.save if resource.new_record?
35
+ return resource
36
+ else
37
+ return nil
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ require 'rpam'
2
+ include Rpam
3
+
4
+ module Devise
5
+
6
+ module PamAdapter
7
+
8
+ def self.valid_credentials?(username, password)
9
+ authpam(username, password)
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,4 @@
1
+ ActionController::Routing::Mapper.class_eval do
2
+ protected
3
+ alias_method :devise_pam_authenticatable, :devise_session
4
+ end
@@ -0,0 +1,37 @@
1
+ require 'devise/strategies/base'
2
+
3
+ module Devise
4
+ module Strategies
5
+ class PamAuthenticatable < Base
6
+
7
+ def valid?
8
+ puts "Asked if valid"
9
+ valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate_with_pam)
10
+ end
11
+
12
+ def authenticate!
13
+ puts "Asked to authenticate"
14
+ if resource = mapping.to.authenticate_with_pam(params[scope])
15
+ success!(resource)
16
+ else
17
+ fail(:invalid)
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def valid_controller?
24
+ puts "Controller is #{params[:controller]}"
25
+ params[:controller] == 'devise/sessions'
26
+ end
27
+
28
+ def valid_params?
29
+ puts "Scope is #{params[scope]}"
30
+ params[scope] && params[scope][:password].present?
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+
37
+ Warden::Strategies.add(:pam_authenticatable, Devise::Strategies::PamAuthenticatable)
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'devise'
2
+
3
+ $: << File.expand_path("..", __FILE__)
4
+
5
+ require 'lib/devise_pam_authenticatable'
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_pam_authenticatable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - James Wilson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-13 00:00:00 +11:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: devise
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 0
34
+ version: 1.1.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rpam
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: For authenticating against PAM (Pluggable Authentication Modules)
52
+ email: jwilson@lithiumcorp.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.md
59
+ files:
60
+ - .rvmrc
61
+ - MIT-LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - VERSION
65
+ - devise_pam_authenticatable.gemspec
66
+ - lib/devise_pam_authenticatable.rb
67
+ - lib/devise_pam_authenticatable/model.rb
68
+ - lib/devise_pam_authenticatable/pam_adapter.rb
69
+ - lib/devise_pam_authenticatable/routes.rb
70
+ - lib/devise_pam_authenticatable/strategy.rb
71
+ - rails/init.rb
72
+ has_rdoc: true
73
+ homepage: http://github.com/jwilson511/devise_pam_authenticatable
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.4.1
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Devise PAM authentication module using rpam
106
+ test_files: []
107
+