devise_pam_authenticatable2 3.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16387d390e7ee4a8e8c85d26e353126718a25e07
4
+ data.tar.gz: 0ed2cccb98705bdf0144e8b5a0c08df4d76e58d0
5
+ SHA512:
6
+ metadata.gz: c8ed07a8892ddbb2ac01d182dfc439f0f062a0384098e88ac1002423f532bc8183a93fdfb60538ca98f6cfb67e88638ca3d1381de4f4da7c76d5bdaf35b70234
7
+ data.tar.gz: ba2e9ec56067359e235c1d729a8c18f0a5c1ed27d883a80fc0adc59d1f89fdcd0964643de2b38e7efa406ce04c148bd0e31cb0792256f62ab0ea68e0e3bf946e
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,64 @@
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_authenticatable2"
21
+
22
+ Or, to use the latest from github:
23
+
24
+ gem "devise_pam_authenticatable2", :git => "git://github.com/devkral/devise_pam_authenticatable2.git"
25
+
26
+ Setup
27
+ -----
28
+
29
+ The devise_pam_authenticatable extension can use a username or extract the name from a special email address (suffix can be choosen)
30
+ username field and email field are configurable
31
+
32
+ In your Devise model, ensure the following is present:
33
+
34
+ class User < ActiveRecord::Base
35
+
36
+ devise :pam_authenticatable, pam_service: "system-auth", pam_suffix: "foo"
37
+
38
+ # Setup accessible (or protected) attributes for your model
39
+ attr_accessible :password, :<username or email field>
40
+
41
+ end
42
+
43
+ pam_service: "system-auth" is optional. By default the pam service specified in config.pam_default_service is used.
44
+
45
+ pam_suffix: "foo" is optional. By default the pam email extraction suffix specified in config.pam_default_suffix is used.
46
+
47
+ Options:
48
+
49
+ * config.pam_default_service = "rpam"
50
+ * config.pam_default_suffix = nil # extraction disabled by default
51
+ * config.pam_default_suffix = "pam" # username@pam = username
52
+ * config.emailfield = "email" # set emailfield, set to nil if not available
53
+ * config.usernamefield = "username" # set to nil to disable username (only email extraction)
54
+
55
+ References
56
+ ----------
57
+
58
+ * [Devise](http://github.com/plataformatec/devise)
59
+ * [Warden](http://github.com/hassox/warden)
60
+
61
+
62
+ Released under the MIT license
63
+
64
+ Copyright (c) 2011 James Wilson, LithiumCorp Pty Ltd
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc'
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
+ RDoc::Task.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_authenticatable2"
29
+ gemspec.summary = "Devise PAM authentication module using rpam2"
30
+ gemspec.description = "For authenticating against PAM (Pluggable Authentication Modules)"
31
+ gemspec.email = "devkral@web.de"
32
+ gemspec.homepage = "http://github.com/devkral/devise_pam_authenticatable2"
33
+ gemspec.license = "MIT"
34
+ gemspec.authors = ["James Wilson", "Alexander Kaftan"]
35
+ gemspec.add_runtime_dependency "devise", ">= 4.0.0"
36
+ gemspec.add_runtime_dependency "rpam2", "~> 3.0"
37
+ end
38
+ Jeweler::GemcutterTasks.new
39
+ rescue LoadError
40
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
@@ -0,0 +1,51 @@
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
+ # stub: devise_pam_authenticatable2 3.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "devise_pam_authenticatable2".freeze
9
+ s.version = "3.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["James Wilson".freeze, "Alexander Kaftan".freeze]
14
+ s.date = "2017-11-28"
15
+ s.description = "For authenticating against PAM (Pluggable Authentication Modules)".freeze
16
+ s.email = "devkral@web.de".freeze
17
+ s.extra_rdoc_files = [
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ "MIT-LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "devise_pam_authenticatable2.gemspec",
26
+ "lib/devise_pam_authenticatable.rb",
27
+ "lib/devise_pam_authenticatable/model.rb",
28
+ "lib/devise_pam_authenticatable/strategy.rb",
29
+ "lib/devise_pam_authenticatable2.rb"
30
+ ]
31
+ s.homepage = "http://github.com/devkral/devise_pam_authenticatable2".freeze
32
+ s.licenses = ["MIT".freeze]
33
+ s.rubygems_version = "2.6.13".freeze
34
+ s.summary = "Devise PAM authentication module using rpam2".freeze
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 4
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<devise>.freeze, [">= 4.0.0"])
41
+ s.add_runtime_dependency(%q<rpam2>.freeze, ["~> 3.0"])
42
+ else
43
+ s.add_dependency(%q<devise>.freeze, [">= 4.0.0"])
44
+ s.add_dependency(%q<rpam2>.freeze, ["~> 3.0"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<devise>.freeze, [">= 4.0.0"])
48
+ s.add_dependency(%q<rpam2>.freeze, ["~> 3.0"])
49
+ end
50
+ end
51
+
@@ -0,0 +1,20 @@
1
+ require 'devise'
2
+ require 'rpam2'
3
+
4
+ require 'devise_pam_authenticatable/model'
5
+ require 'devise_pam_authenticatable/strategy'
6
+ module Devise
7
+ mattr_accessor :pam_default_service
8
+ @@pam_default_service = "rpam"
9
+ mattr_accessor :pam_default_suffix
10
+ @@pam_default_suffix = nil
11
+ mattr_accessor :emailfield
12
+ @@emailfield = "email"
13
+ mattr_accessor :usernamefield
14
+ @@usernamefield = "username"
15
+ end
16
+ Devise.add_module(:pam_authenticatable,
17
+ :route => :session,
18
+ :strategy => true,
19
+ :controller => :sessions,
20
+ :model => "devise_pam_authenticatable/model")
@@ -0,0 +1,106 @@
1
+ require 'devise_pam_authenticatable/strategy'
2
+
3
+ module Devise
4
+ module Models
5
+ module PamAuthenticatable
6
+ def self.included(base)
7
+ base.class_eval do
8
+ extend ClassMethods
9
+ attr_accessor :password
10
+ end
11
+ end
12
+
13
+ def self.required_fields(klass)
14
+ []
15
+ end
16
+
17
+ # Set password to nil
18
+ def clean_up_passwords
19
+ self.password = nil
20
+ end
21
+
22
+ def get_service
23
+ return self.class.pam_service if self.class.instance_variable_defined?("@pam_service")
24
+ ::Devise::pam_default_service
25
+ end
26
+
27
+ def get_suffix
28
+ return self.class.pam_suffix if self.class.instance_variable_defined?("@pam_suffix")
29
+ ::Devise::pam_default_suffix
30
+ end
31
+
32
+ def pam_on_filled_pw(attributes)
33
+ # use blank password as discriminator between traditional login and pam login?
34
+ # to disable login with pam return nil elsewise return a (different?) user object
35
+ # as default assume there is no conflict and return user object
36
+ self
37
+ end
38
+
39
+ def pam_setup(attributes)
40
+ return unless ::Devise::emailfield && ::Devise::usernamefield
41
+ self[::Devise::emailfield] = Rpam2.getenv(get_service, get_pam_name, attributes[:password], "email", false)
42
+ self[::Devise::emailfield] = attributes[::Devise::emailfield] if self[::Devise::emailfield].nil?
43
+ self[::Devise::emailfield] = "#{self[::Devise::usernamefield]}@#{get_suffix}" if self[::Devise::emailfield].nil? && get_suffix
44
+ end
45
+
46
+ def password_required?
47
+ return false
48
+ end
49
+
50
+ def get_pam_name
51
+ return self[::Devise::usernamefield] if ::Devise::usernamefield
52
+ suffix = get_suffix()
53
+ return nil unless suffix && ::Devise::emailfield
54
+ email = "#{self[::Devise::emailfield]}\n"
55
+ pos = email.index("@#{suffix}\n")
56
+ return nil unless pos
57
+ email.slice(0, pos)
58
+ end
59
+
60
+ # Checks if a resource is valid upon authentication.
61
+ def valid_pam_authentication?(password)
62
+ Rpam2.auth(get_service, get_pam_name, password)
63
+ end
64
+
65
+ module ClassMethods
66
+ Devise::Models.config(self, :pam_service, :pam_suffix)
67
+
68
+ def authenticate_with_pam(attributes={})
69
+ if ::Devise::usernamefield && attributes[::Devise::usernamefield]
70
+ resource = where(::Devise::usernamefield => attributes[::Devise::usernamefield]).first
71
+
72
+ if resource.blank?
73
+ resource = new
74
+ resource[::Devise::usernamefield] = attributes[::Devise::usernamefield]
75
+ end
76
+ elsif ::Devise::emailfield
77
+ return nil unless attributes[::Devise::emailfield]
78
+ resource = where(::Devise::emailfield => attributes[::Devise::emailfield]).first
79
+
80
+ if resource.blank? && ::Devise::usernamefield.nil?
81
+ resource = new
82
+ resource[::Devise::emailfield] = attributes[::Devise::emailfield]
83
+ elsif resource.blank?
84
+ return nil
85
+ end
86
+ else
87
+ return nil
88
+ end
89
+
90
+ # potential conflict detected
91
+ resource = resource.pam_on_filled_pw(attributes) unless resource.password.blank?
92
+
93
+ if resource && resource.try(:valid_pam_authentication?, attributes[:password])
94
+ if resource.new_record?
95
+ resource.pam_setup(attributes)
96
+ resource.save!
97
+ end
98
+ return resource
99
+ else
100
+ return nil
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,15 @@
1
+ require 'devise/strategies/base'
2
+
3
+ class Devise::Strategies::PamAuthenticatable < Devise::Strategies::Authenticatable
4
+
5
+ def authenticate!
6
+ if resource = mapping.to.authenticate_with_pam(params[scope])
7
+ success!(resource)
8
+ else
9
+ fail(:invalid)
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ Warden::Strategies.add(:pam_authenticatable, Devise::Strategies::PamAuthenticatable)
@@ -0,0 +1 @@
1
+ require 'devise_pam_authenticatable'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_pam_authenticatable2
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Wilson
8
+ - Alexander Kaftan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 4.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 4.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rpam2
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ description: For authenticating against PAM (Pluggable Authentication Modules)
43
+ email: devkral@web.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - VERSION
53
+ - devise_pam_authenticatable2.gemspec
54
+ - lib/devise_pam_authenticatable.rb
55
+ - lib/devise_pam_authenticatable/model.rb
56
+ - lib/devise_pam_authenticatable/strategy.rb
57
+ - lib/devise_pam_authenticatable2.rb
58
+ homepage: http://github.com/devkral/devise_pam_authenticatable2
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.13
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Devise PAM authentication module using rpam2
82
+ test_files: []