authlogic 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of authlogic might be problematic. Click here for more details.

data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'activerecord', '~> 3.0.7'
3
+ gem 'activerecord', '>= 3.0.7'
4
4
 
5
5
  group :test do
6
6
  gem 'bcrypt-ruby'
@@ -42,7 +42,7 @@ PLATFORMS
42
42
  ruby
43
43
 
44
44
  DEPENDENCIES
45
- activerecord (~> 3.0.7)
45
+ activerecord (>= 3.0.7)
46
46
  bcrypt-ruby
47
47
  jeweler
48
48
  ruby-debug19
@@ -1,5 +1,7 @@
1
1
  = Authlogic
2
2
 
3
+ ** Please note the latest version is compatible with rails 3 only. Rails 2 should use version 2.X.X **
4
+
3
5
  Authlogic is a clean, simple, and unobtrusive ruby authentication solution.
4
6
 
5
7
  A code example can replace a thousand words...
@@ -70,7 +72,9 @@ If you find a bug or a problem please post it in the issues section. If you need
70
72
  * <b>Authlogic Facebook Connect (New JS API):</b> http://github.com/studybyte/authlogic_facebook_connect
71
73
  * <b>Authlogic Facebook Shim</b> http://github.com/james2m/authlogic_facebook_shim
72
74
  * <b>Authlogic OAuth (Twitter):</b> http://github.com/jrallison/authlogic_oauth
75
+ * <b>Authlogic Oauth and OpenID:</b> http://github.com/viatropos/authlogic-connect
73
76
  * <b>Authlogic PAM:</b> http://github.com/nbudin/authlogic_pam
77
+ * <b>Authlogic x509:</b> http://github.com/auth-scc/authlogic_x509
74
78
 
75
79
  If you create one of your own, please let me know about it so I can add it to this list. Or just fork the project, add your link, and send me a pull request.
76
80
 
@@ -152,7 +156,7 @@ What if your user sessions controller could look just like your other controller
152
156
  def new
153
157
  @user_session = UserSession.new
154
158
  end
155
-
159
+
156
160
  def create
157
161
  @user_session = UserSession.new(params[:user_session])
158
162
  if @user_session.save
@@ -161,7 +165,7 @@ What if your user sessions controller could look just like your other controller
161
165
  render :action => :new
162
166
  end
163
167
  end
164
-
168
+
165
169
  def destroy
166
170
  current_user_session.destroy
167
171
  redirect_to new_user_session_url
@@ -185,13 +189,13 @@ Or how about persisting the session...
185
189
 
186
190
  class ApplicationController
187
191
  helper_method :current_user_session, :current_user
188
-
192
+
189
193
  private
190
194
  def current_user_session
191
195
  return @current_user_session if defined?(@current_user_session)
192
196
  @current_user_session = UserSession.find
193
197
  end
194
-
198
+
195
199
  def current_user
196
200
  return @current_user if defined?(@current_user)
197
201
  @current_user = current_user_session && current_user_session.user
@@ -202,17 +206,15 @@ Or how about persisting the session...
202
206
 
203
207
  Install the gem / plugin (recommended)
204
208
 
205
- From rubyforge:
209
+ Rails 3:
206
210
 
207
211
  $ sudo gem install authlogic
208
212
 
209
- Or from github:
210
-
211
- $ sudo gem install binarylogic-authlogic
213
+ Rails 2:
212
214
 
213
- Now just add the gem dependency in your projects configuration.
215
+ $ sudo gem install authlogic --version=2.1.6
214
216
 
215
- Or you can install this as a plugin:
217
+ Or install as a plugin:
216
218
 
217
219
  script/plugin install git://github.com/binarylogic/authlogic.git
218
220
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 3
3
3
  :minor: 0
4
- :patch: 2
4
+ :patch: 3
5
5
  :build:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{authlogic}
8
- s.version = "3.0.2"
8
+ s.version = "3.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
12
- s.date = %q{2011-04-30}
12
+ s.date = %q{2011-05-17}
13
13
  s.email = %q{bjohnson@binarylogic.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -206,15 +206,15 @@ Gem::Specification.new do |s|
206
206
  s.specification_version = 3
207
207
 
208
208
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
209
- s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.7"])
210
- s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.7"])
209
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.7"])
210
+ s.add_runtime_dependency(%q<activerecord>, [">= 3.0.7"])
211
211
  else
212
- s.add_dependency(%q<activerecord>, ["~> 3.0.7"])
213
- s.add_dependency(%q<activerecord>, ["~> 3.0.7"])
212
+ s.add_dependency(%q<activerecord>, [">= 3.0.7"])
213
+ s.add_dependency(%q<activerecord>, [">= 3.0.7"])
214
214
  end
215
215
  else
216
- s.add_dependency(%q<activerecord>, ["~> 3.0.7"])
217
- s.add_dependency(%q<activerecord>, ["~> 3.0.7"])
216
+ s.add_dependency(%q<activerecord>, [">= 3.0.7"])
217
+ s.add_dependency(%q<activerecord>, [">= 3.0.7"])
218
218
  end
219
219
  end
220
220
 
@@ -4,6 +4,9 @@ module Authlogic
4
4
  module Base
5
5
  def self.included(klass)
6
6
  klass.class_eval do
7
+ class_attribute :acts_as_authentic_modules, :acts_as_authentic_config
8
+ self.acts_as_authentic_modules ||= []
9
+ self.acts_as_authentic_config ||= {}
7
10
  extend Config
8
11
  end
9
12
  end
@@ -41,7 +44,7 @@ module Authlogic
41
44
  #
42
45
  # That being said, this is your tool for extending Authlogic and "hooking" into the acts_as_authentic call.
43
46
  def add_acts_as_authentic_module(mod, action = :append)
44
- modules = acts_as_authentic_modules
47
+ modules = acts_as_authentic_modules.clone
45
48
  case action
46
49
  when :append
47
50
  modules << mod
@@ -49,21 +52,17 @@ module Authlogic
49
52
  modules = [mod] + modules
50
53
  end
51
54
  modules.uniq!
52
- write_inheritable_attribute(:acts_as_authentic_modules, modules)
55
+ self.acts_as_authentic_modules = modules
53
56
  end
54
57
 
55
58
  # This is the same as add_acts_as_authentic_module, except that it removes the module from the list.
56
59
  def remove_acts_as_authentic_module(mod)
57
- acts_as_authentic_modules.delete(mod)
58
- acts_as_authentic_modules
60
+ modules = acts_as_authentic_modules.clone
61
+ modules.delete(mod)
62
+ self.acts_as_authentic_modules = modules
59
63
  end
60
-
64
+
61
65
  private
62
- def acts_as_authentic_modules
63
- key = :acts_as_authentic_modules
64
- inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : []
65
- end
66
-
67
66
  def db_setup?
68
67
  begin
69
68
  column_names
@@ -75,9 +74,12 @@ module Authlogic
75
74
 
76
75
  def rw_config(key, value, default_value = nil, read_value = nil)
77
76
  if value == read_value
78
- inheritable_attributes.include?(key) ? read_inheritable_attribute(key) : default_value
77
+ acts_as_authentic_config.include?(key) ? acts_as_authentic_config[key] : default_value
79
78
  else
80
- write_inheritable_attribute(key, value)
79
+ config = acts_as_authentic_config.clone
80
+ config[key] = value
81
+ self.acts_as_authentic_config = config
82
+ value
81
83
  end
82
84
  end
83
85
 
@@ -9,7 +9,7 @@ module Authlogic
9
9
  end
10
10
  end
11
11
 
12
- # Confguration for the login field.
12
+ # Configuration for the login field.
13
13
  module Config
14
14
  # The name of the login field in the database.
15
15
  #
@@ -20,7 +20,7 @@ module Authlogic
20
20
  end
21
21
  alias_method :login_field=, :login_field
22
22
 
23
- # Whether or not the validate the login field
23
+ # Whether or not to validate the login field
24
24
  #
25
25
  # * <tt>Default:</tt> true
26
26
  # * <tt>Accepts:</tt> Boolean
@@ -42,7 +42,7 @@ module Authlogic
42
42
  end
43
43
  alias_method :validates_length_of_login_field_options=, :validates_length_of_login_field_options
44
44
 
45
- # A convenience function to merge options into the validates_length_of_login_field_options. So intead of:
45
+ # A convenience function to merge options into the validates_length_of_login_field_options. So instead of:
46
46
  #
47
47
  # self.validates_length_of_login_field_options = validates_length_of_login_field_options.merge(:my_option => my_value)
48
48
  #
@@ -89,7 +89,7 @@ module Authlogic
89
89
  self.validates_uniqueness_of_login_field_options = validates_uniqueness_of_login_field_options.merge(options)
90
90
  end
91
91
 
92
- # This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
92
+ # This method allows you to find a record with the given login. If you notice, with Active Record you have the
93
93
  # validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
94
94
  # manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
95
95
  # validates_uniqueness_of_login_field_options this method will modify the query to look something like:
@@ -6,6 +6,9 @@ module Authlogic
6
6
  module Foundation
7
7
  def self.included(klass)
8
8
  klass.class_eval do
9
+ class_attribute :acts_as_authentic_config
10
+ self.acts_as_authentic_config ||= {}
11
+
9
12
  extend ClassMethods
10
13
  include InstanceMethods
11
14
  end
@@ -15,10 +18,13 @@ module Authlogic
15
18
  private
16
19
  def rw_config(key, value, default_value = nil, read_value = nil)
17
20
  if value == read_value
18
- return read_inheritable_attribute(key) if inheritable_attributes.include?(key)
19
- write_inheritable_attribute(key, default_value)
21
+ return acts_as_authentic_config[key] if acts_as_authentic_config.include?(key)
22
+ rw_config(key, default_value)
20
23
  else
21
- write_inheritable_attribute(key, value)
24
+ config = acts_as_authentic_config.clone
25
+ config[key] = value
26
+ self.acts_as_authentic_config = config
27
+ value
22
28
  end
23
29
  end
24
30
  end
@@ -28,6 +28,41 @@ module Authlogic
28
28
  rw_config(:allow_http_basic_auth, value, true)
29
29
  end
30
30
  alias_method :allow_http_basic_auth=, :allow_http_basic_auth
31
+
32
+ # Whether or not to request HTTP authentication
33
+ #
34
+ # If set to true and no HTTP authentication credentials are sent with
35
+ # the request, the Rails controller method
36
+ # authenticate_or_request_with_http_basic will be used and a '401
37
+ # Authorization Required' header will be sent with the response. In
38
+ # most cases, this will cause the classic HTTP authentication popup to
39
+ # appear in the users browser.
40
+ #
41
+ # If set to false, the Rails controller method
42
+ # authenticate_with_http_basic is used and no 401 header is sent.
43
+ #
44
+ # Note: This parameter has no effect unless allow_http_basic_auth is
45
+ # true
46
+ #
47
+ # * <tt>Default:</tt> false
48
+ # * <tt>Accepts:</tt> Boolean
49
+ def request_http_basic_auth(value = nil)
50
+ rw_config(:request_http_basic_auth, value, false)
51
+ end
52
+ alias_method :request_http_basic_auth=, :request_http_basic_auth
53
+
54
+ # HTTP authentication realm
55
+ #
56
+ # Sets the HTTP authentication realm.
57
+ #
58
+ # Note: This option has no effect unless request_http_basic_auth is true
59
+ #
60
+ # * <tt>Default:</tt> 'Application'
61
+ # * <tt>Accepts:</tt> String
62
+ def http_basic_auth_realm(value = nil)
63
+ rw_config(:http_basic_auth_realm, value, 'Application')
64
+ end
65
+ alias_method :http_basic_auth_realm=, :http_basic_auth_realm
31
66
  end
32
67
 
33
68
  # Instance methods for the HTTP basic auth feature of authlogic.
@@ -38,13 +73,19 @@ module Authlogic
38
73
  end
39
74
 
40
75
  def persist_by_http_auth
41
- controller.authenticate_with_http_basic do |login, password|
76
+ login_proc = Proc.new do |login, password|
42
77
  if !login.blank? && !password.blank?
43
78
  send("#{login_field}=", login)
44
79
  send("#{password_field}=", password)
45
80
  return valid?
46
81
  end
47
82
  end
83
+
84
+ if self.class.request_http_basic_auth
85
+ controller.authenticate_or_request_with_http_basic(self.class.http_basic_auth_realm, &login_proc)
86
+ else
87
+ controller.authenticate_with_http_basic(&login_proc)
88
+ end
48
89
 
49
90
  false
50
91
  end
@@ -55,4 +96,4 @@ module Authlogic
55
96
  end
56
97
  end
57
98
  end
58
- end
99
+ end
@@ -3,7 +3,7 @@ module Authlogic
3
3
  # Basically acts like a controller but doesn't do anything. Authlogic can interact with this, do it's thing and then you
4
4
  # can look at the controller object to see if anything changed.
5
5
  class MockController < ControllerAdapters::AbstractAdapter
6
- attr_accessor :http_user, :http_password
6
+ attr_accessor :http_user, :http_password, :realm
7
7
  attr_writer :request_content_type
8
8
 
9
9
  def initialize
@@ -13,6 +13,12 @@ module Authlogic
13
13
  yield http_user, http_password
14
14
  end
15
15
 
16
+ def authenticate_or_request_with_http_basic(realm = 'DefaultRealm', &block)
17
+ self.realm = realm
18
+ @http_auth_requested = true
19
+ yield http_user, http_password
20
+ end
21
+
16
22
  def cookies
17
23
  @cookies ||= MockCookieJar.new
18
24
  end
@@ -40,6 +46,10 @@ module Authlogic
40
46
  def session
41
47
  @session ||= {}
42
48
  end
49
+
50
+ def http_auth_requested?
51
+ @http_auth_requested ||= false
52
+ end
43
53
  end
44
54
  end
45
- end
55
+ end
@@ -10,19 +10,47 @@ module SessionTest
10
10
  UserSession.allow_http_basic_auth true
11
11
  assert_equal true, UserSession.allow_http_basic_auth
12
12
  end
13
+
14
+ def test_request_http_basic_auth
15
+ UserSession.request_http_basic_auth = true
16
+ assert_equal true, UserSession.request_http_basic_auth
17
+
18
+ UserSession.request_http_basic_auth = false
19
+ assert_equal false, UserSession.request_http_basic_auth
20
+ end
21
+
22
+ def test_http_basic_auth_realm
23
+ assert_equal 'Application', UserSession.http_basic_auth_realm
24
+
25
+ UserSession.http_basic_auth_realm = 'TestRealm'
26
+ assert_equal 'TestRealm', UserSession.http_basic_auth_realm
27
+ end
13
28
  end
14
29
 
15
30
  class InstanceMethodsTest < ActiveSupport::TestCase
16
31
  def test_persist_persist_by_http_auth
17
32
  ben = users(:ben)
18
- http_basic_auth_for { assert !UserSession.find }
33
+ http_basic_auth_for do
34
+ assert !UserSession.find
35
+ end
36
+ http_basic_auth_for(ben) do
37
+ assert session = UserSession.find
38
+ assert_equal ben, session.record
39
+ assert_equal ben.login, session.login
40
+ assert_equal "benrocks", session.send(:protected_password)
41
+ assert !controller.http_auth_requested?
42
+ end
43
+ UserSession.request_http_basic_auth = true
44
+ UserSession.http_basic_auth_realm = 'PersistTestRealm'
19
45
  http_basic_auth_for(ben) do
20
46
  assert session = UserSession.find
21
47
  assert_equal ben, session.record
22
48
  assert_equal ben.login, session.login
23
49
  assert_equal "benrocks", session.send(:protected_password)
50
+ assert_equal 'PersistTestRealm', controller.realm
51
+ assert controller.http_auth_requested?
24
52
  end
25
53
  end
26
54
  end
27
55
  end
28
- end
56
+ end
@@ -6,6 +6,9 @@ require "active_record/fixtures"
6
6
 
7
7
  #ActiveRecord::Schema.verbose = false
8
8
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
+ logger = Logger.new(STDOUT)
10
+ logger.level= Logger::FATAL
11
+ ActiveRecord::Base.logger = logger
9
12
 
10
13
  ActiveRecord::Base.configurations = true
11
14
  ActiveRecord::Schema.define(:version => 1) do
@@ -127,7 +130,7 @@ class ActiveSupport::TestCase
127
130
  controller.http_password = password_for(user)
128
131
  end
129
132
  yield
130
- controller.http_user = controller.http_password = nil
133
+ controller.http_user = controller.http_password = controller.realm = nil
131
134
  end
132
135
 
133
136
  def set_cookie_for(user, id = nil)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.0.2
5
+ version: 3.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Johnson of Binary Logic
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-30 00:00:00 -04:00
13
+ date: 2011-05-17 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 3.0.7
24
24
  type: :runtime
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
- - - ~>
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 3.0.7
35
35
  type: :runtime
@@ -187,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
187
  requirements:
188
188
  - - ">="
189
189
  - !ruby/object:Gem::Version
190
- hash: 4144864465011850466
190
+ hash: 3531025750012429530
191
191
  segments:
192
192
  - 0
193
193
  version: "0"