authlogic_pam 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-10-19
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,9 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/authlogic_pam.rb
7
+ lib/authlogic_pam/acts_as_authentic.rb
8
+ lib/authlogic_pam/session.rb
9
+ test/test_authlogic_pam.rb
@@ -0,0 +1,40 @@
1
+ = authlogic_pam
2
+
3
+ http://github.com/nbudin/authlogic_pam
4
+
5
+ == DESCRIPTION:
6
+
7
+ Really simple PAM support for Authlogic via the rpam package. Code heavily
8
+ based on authlogic_ldap and authlogic_openid.
9
+
10
+ == REQUIREMENTS:
11
+
12
+ * A system supporting PAM (Linux only, AFAIK)
13
+ * rpam >= 1.0.1
14
+
15
+ == INSTALL:
16
+
17
+ * sudo gem install nbudin-authlogic_pam
18
+
19
+ == LICENSE:
20
+
21
+ Copyright (c) 2009 Nat Budin
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'authlogic_pam' do
7
+ developer('Nat Budin', 'natbudin@ironmountain.com')
8
+ self.url = 'http://github.com/nbudin/authlogic_pam'
9
+ self.extra_deps << ['authlogic']
10
+ self.extra_deps << ['rpam', '~> 1.0.1']
11
+ end
12
+
13
+ # vim: syntax=ruby
@@ -0,0 +1,9 @@
1
+ require 'authlogic_pam/acts_as_authentic'
2
+ require 'authlogic_pam/session'
3
+
4
+ module AuthlogicPam
5
+ VERSION = '0.1.0'
6
+ end
7
+
8
+ #ActiveRecord::Base.send(:include, AuthlogicPam::ActsAsAuthentic)
9
+ Authlogic::Session::Base.send(:include, AuthlogicPam::Session)
@@ -0,0 +1,45 @@
1
+ module AuthlogicPam
2
+ module ActsAsAuthentic
3
+ def self.included?(klass)
4
+ klass.class_eval do
5
+ extend Config
6
+ add_acts_as_authentic_module(Methods, :prepend)
7
+ end
8
+ end
9
+
10
+ module Config
11
+ def validate_pam_login(value = nil)
12
+ config(:validate_pam_login. value, true)
13
+ end
14
+ alias_method :validate_pam_login=, :validate_pam_login
15
+ end
16
+
17
+ module Methods
18
+ def self.included?(klass)
19
+ klass.class_eval do
20
+ attr_accessor :pam_password
21
+
22
+ if validate_pam_login
23
+ validates_uniqueness_of :pam_login, :scope => validations_scope, :if => :using_pam?
24
+ validates_presence_of :pam_password, :if => :validate_pam?
25
+ validate :validate_pam, :if => :validate_pam?
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+ def using_pam?
32
+ respond_to?(:pam_login) && respond_to?(:pam_password) &&
33
+ (!pam_login.blank? || !pam_password.blank?)
34
+ end
35
+
36
+ def validate_pam
37
+ return if errors.count > 0
38
+ end
39
+
40
+ def validate_pam?
41
+ pam_login_changed? && !pam_login.blank?
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,74 @@
1
+ require 'rpam'
2
+
3
+ module AuthlogicPam
4
+ module Session
5
+ def self.included(klass)
6
+ klass.class_eval do
7
+ extend Config
8
+ include Methods
9
+ include Rpam
10
+ end
11
+ end
12
+
13
+ module Config
14
+ def find_by_pam_login_method(value = nil)
15
+ rw_config(:find_by_pam_login_method, value, :find_by_pam_login)
16
+ end
17
+ alias_method :find_by_pam_login_method=, :find_by_pam_login_method
18
+ end
19
+
20
+ module Methods
21
+ def self.included(klass)
22
+ klass.class_eval do
23
+ attr_accessor :pam_login
24
+ attr_accessor :pam_password
25
+
26
+ validate :validate_by_pam, :if => :authenticating_with_pam?
27
+ end
28
+ end
29
+
30
+ def credentials
31
+ if authenticating_with_pam?
32
+ details = {}
33
+ details[:pam_login] = send(login_field)
34
+ details[:pam_password] = '<protected>'
35
+ details
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ def credentials=(value)
42
+ super
43
+ values = value.is_a?(Array) ? value : [value]
44
+ hash = values.first.is_a?(Hash) ? values.first.with_indifferent_access : nil
45
+ if !hash.nil?
46
+ self.pam_login = hash[:pam_login] if hash.key?(:pam_login)
47
+ self.pam_password = hash[:pam_password] if hash.key?(:pam_password)
48
+ end
49
+ end
50
+
51
+ private
52
+ def authenticating_with_pam?
53
+ !pam_login.blank? || !pam_password.blank?
54
+ end
55
+
56
+ def find_by_pam_login_method
57
+ self.class.find_by_pam_login_method
58
+ end
59
+
60
+ def validate_by_pam
61
+ errors.add(:pam_login, I18n.t('error_messages.pam_login_blank', :default => 'cannot be blank')) if pam_login.blank?
62
+ errors.add(:pam_password, I18n.t('error_messages.pam_password_blank', :default => 'cannot be blank')) if pam_password.blank?
63
+ return if errors.count > 0
64
+
65
+ if authpam(pam_login, pam_password)
66
+ self.attempted_record = klass.send(find_by_pam_login_method, pam_login)
67
+ errors.add(:pam_login, I18n.t('error_messages.pam_login_not_found', :default => "does not exist")) if attempted_record.blank?
68
+ else
69
+ errors.add_to_base("PAM authentication failed")
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "authlogic_pam"
3
+
4
+ class TestAuthlogicPam < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authlogic_pam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nat Budin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-19 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: authlogic
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rpam
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.3.3
44
+ version:
45
+ description: |-
46
+ Really simple PAM support for Authlogic via the rpam package. Code heavily
47
+ based on authlogic_ldap and authlogic_openid.
48
+ email:
49
+ - natbudin@ironmountain.com
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - History.txt
56
+ - Manifest.txt
57
+ - README.txt
58
+ files:
59
+ - .autotest
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.txt
63
+ - Rakefile
64
+ - lib/authlogic_pam.rb
65
+ - lib/authlogic_pam/acts_as_authentic.rb
66
+ - lib/authlogic_pam/session.rb
67
+ - test/test_authlogic_pam.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/nbudin/authlogic_pam
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --main
75
+ - README.txt
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project: authlogic_pam
93
+ rubygems_version: 1.3.5
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Really simple PAM support for Authlogic via the rpam package
97
+ test_files:
98
+ - test/test_authlogic_pam.rb