authlogic 4.5.0 → 6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/authlogic/acts_as_authentic/base.rb +19 -19
- data/lib/authlogic/acts_as_authentic/email.rb +3 -170
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -1
- data/lib/authlogic/acts_as_authentic/login.rb +7 -174
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +7 -4
- data/lib/authlogic/acts_as_authentic/password.rb +67 -256
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +8 -5
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -4
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +36 -20
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +12 -8
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -8
- data/lib/authlogic/config.rb +9 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +28 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +7 -30
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/md5.rb +6 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha1.rb +7 -6
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha256.rb +5 -0
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/crypto_providers/sha512.rb +9 -5
- data/lib/authlogic/crypto_providers.rb +5 -20
- data/lib/authlogic/errors.rb +50 -0
- data/lib/authlogic/i18n/translator.rb +4 -1
- data/lib/authlogic/i18n.rb +3 -1
- data/lib/authlogic/random.rb +2 -0
- data/lib/authlogic/session/base.rb +2197 -39
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case/mock_api_controller.rb +52 -0
- data/lib/authlogic/test_case/mock_controller.rb +3 -1
- data/lib/authlogic/test_case/mock_cookie_jar.rb +32 -6
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +12 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +9 -1
- data/lib/authlogic/test_case.rb +5 -0
- data/lib/authlogic/version.rb +2 -1
- data/lib/authlogic.rb +5 -28
- metadata +175 -200
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
- data/.github/ISSUE_TEMPLATE/feature_proposal.md +0 -32
- data/.github/triage.md +0 -86
- data/.gitignore +0 -15
- data/.rubocop.yml +0 -133
- data/.rubocop_todo.yml +0 -74
- data/.travis.yml +0 -24
- data/CHANGELOG.md +0 -348
- data/CONTRIBUTING.md +0 -91
- data/Gemfile +0 -6
- data/LICENSE +0 -20
- data/README.md +0 -448
- data/Rakefile +0 -21
- data/UPGRADING.md +0 -22
- data/authlogic.gemspec +0 -40
- data/doc/use_normal_rails_validation.md +0 -82
- data/gemfiles/Gemfile.rails-4.2.x +0 -6
- data/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -106
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -35
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -81
- data/lib/authlogic/crypto_providers/aes256.rb +0 -71
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -72
- data/lib/authlogic/regex.rb +0 -79
- data/lib/authlogic/session/activation.rb +0 -73
- data/lib/authlogic/session/active_record_trickery.rb +0 -65
- data/lib/authlogic/session/brute_force_protection.rb +0 -127
- data/lib/authlogic/session/callbacks.rb +0 -153
- data/lib/authlogic/session/cookies.rb +0 -329
- data/lib/authlogic/session/existence.rb +0 -103
- data/lib/authlogic/session/foundation.rb +0 -105
- data/lib/authlogic/session/http_auth.rb +0 -107
- data/lib/authlogic/session/id.rb +0 -53
- data/lib/authlogic/session/klass.rb +0 -73
- data/lib/authlogic/session/magic_columns.rb +0 -119
- data/lib/authlogic/session/magic_states.rb +0 -82
- data/lib/authlogic/session/params.rb +0 -130
- data/lib/authlogic/session/password.rb +0 -318
- data/lib/authlogic/session/perishable_token.rb +0 -24
- data/lib/authlogic/session/persistence.rb +0 -77
- data/lib/authlogic/session/priority_record.rb +0 -38
- data/lib/authlogic/session/scopes.rb +0 -138
- data/lib/authlogic/session/session.rb +0 -77
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -56
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -27
- data/test/acts_as_authentic_test/email_test.rb +0 -241
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -64
- data/test/acts_as_authentic_test/login_test.rb +0 -153
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -29
- data/test/acts_as_authentic_test/password_test.rb +0 -263
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -98
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -62
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -48
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -150
- data/test/acts_as_authentic_test/single_access_test.rb +0 -46
- data/test/adapter_test.rb +0 -23
- data/test/authenticates_many_test.rb +0 -33
- data/test/config_test.rb +0 -38
- data/test/crypto_provider_test/aes256_test.rb +0 -16
- data/test/crypto_provider_test/bcrypt_test.rb +0 -16
- data/test/crypto_provider_test/scrypt_test.rb +0 -16
- data/test/crypto_provider_test/sha1_test.rb +0 -25
- data/test/crypto_provider_test/sha256_test.rb +0 -16
- data/test/crypto_provider_test/sha512_test.rb +0 -16
- data/test/crypto_provider_test/wordpress_test.rb +0 -26
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -35
- data/test/libs/affiliate.rb +0 -9
- data/test/libs/company.rb +0 -8
- data/test/libs/employee.rb +0 -9
- data/test/libs/employee_session.rb +0 -4
- data/test/libs/ldaper.rb +0 -5
- data/test/libs/project.rb +0 -5
- data/test/libs/user.rb +0 -9
- data/test/libs/user_session.rb +0 -27
- data/test/random_test.rb +0 -15
- data/test/session_test/activation_test.rb +0 -45
- data/test/session_test/active_record_trickery_test.rb +0 -78
- data/test/session_test/brute_force_protection_test.rb +0 -110
- data/test/session_test/callbacks_test.rb +0 -42
- data/test/session_test/cookies_test.rb +0 -244
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -88
- data/test/session_test/foundation_test.rb +0 -24
- data/test/session_test/http_auth_test.rb +0 -60
- data/test/session_test/id_test.rb +0 -19
- data/test/session_test/klass_test.rb +0 -42
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -60
- data/test/session_test/params_test.rb +0 -61
- data/test/session_test/password_test.rb +0 -107
- data/test/session_test/perishability_test.rb +0 -17
- data/test/session_test/persistence_test.rb +0 -35
- data/test/session_test/scopes_test.rb +0 -68
- data/test/session_test/session_test.rb +0 -80
- data/test/session_test/timeout_test.rb +0 -84
- data/test/session_test/unauthorized_record_test.rb +0 -15
- data/test/session_test/validation_test.rb +0 -25
- data/test/test_helper.rb +0 -272
@@ -1,106 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module ActsAsAuthentic
|
3
|
-
# This module is responsible for transitioning existing applications from
|
4
|
-
# the restful_authentication plugin.
|
5
|
-
module RestfulAuthentication
|
6
|
-
def self.included(klass)
|
7
|
-
klass.class_eval do
|
8
|
-
extend Config
|
9
|
-
include InstanceMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Configures the restful_authentication aspect of acts_as_authentic.
|
14
|
-
# These methods become class methods of ::ActiveRecord::Base.
|
15
|
-
module Config
|
16
|
-
DPR_MSG = <<~STR.squish
|
17
|
-
Support for transitioning to authlogic from restful_authentication
|
18
|
-
(%s) is deprecated without replacement. restful_authentication is no
|
19
|
-
longer used in the ruby community, and the transition away from it is
|
20
|
-
complete. There is only one version of restful_authentication on
|
21
|
-
rubygems.org, it was released in 2009, and it's only compatible with
|
22
|
-
rails 2.3. It has been nine years since it was released.
|
23
|
-
STR
|
24
|
-
|
25
|
-
# Switching an existing app to Authlogic from restful_authentication? No
|
26
|
-
# problem, just set this true and your users won't know anything
|
27
|
-
# changed. From your database perspective nothing will change at all.
|
28
|
-
# Authlogic will continue to encrypt passwords just like
|
29
|
-
# restful_authentication, so your app won't skip a beat. Although, might
|
30
|
-
# consider transitioning your users to a newer and stronger algorithm.
|
31
|
-
# Checkout the transition_from_restful_authentication option.
|
32
|
-
#
|
33
|
-
# * <tt>Default:</tt> false
|
34
|
-
# * <tt>Accepts:</tt> Boolean
|
35
|
-
def act_like_restful_authentication(value = nil)
|
36
|
-
r = rw_config(:act_like_restful_authentication, value, false)
|
37
|
-
set_restful_authentication_config if value
|
38
|
-
r
|
39
|
-
end
|
40
|
-
|
41
|
-
def act_like_restful_authentication=(value = nil)
|
42
|
-
::ActiveSupport::Deprecation.warn(
|
43
|
-
format(DPR_MSG, "act_like_restful_authentication="),
|
44
|
-
caller(1)
|
45
|
-
)
|
46
|
-
act_like_restful_authentication(value)
|
47
|
-
end
|
48
|
-
|
49
|
-
# This works just like act_like_restful_authentication except that it
|
50
|
-
# will start transitioning your users to the algorithm you specify with
|
51
|
-
# the crypto provider option. The next time they log in it will resave
|
52
|
-
# their password with the new algorithm and any new record will use the
|
53
|
-
# new algorithm as well. Make sure to update your users table if you are
|
54
|
-
# using the default migration since it will set crypted_password and
|
55
|
-
# salt columns to a maximum width of 40 characters which is not enough.
|
56
|
-
def transition_from_restful_authentication(value = nil)
|
57
|
-
r = rw_config(:transition_from_restful_authentication, value, false)
|
58
|
-
set_restful_authentication_config if value
|
59
|
-
r
|
60
|
-
end
|
61
|
-
|
62
|
-
def transition_from_restful_authentication=(value = nil)
|
63
|
-
::ActiveSupport::Deprecation.warn(
|
64
|
-
format(DPR_MSG, "transition_from_restful_authentication="),
|
65
|
-
caller(1)
|
66
|
-
)
|
67
|
-
transition_from_restful_authentication(value)
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def set_restful_authentication_config
|
73
|
-
self.restful_auth_crypto_provider = CryptoProviders::Sha1
|
74
|
-
if !defined?(::REST_AUTH_SITE_KEY) || ::REST_AUTH_SITE_KEY.nil?
|
75
|
-
unless defined?(::REST_AUTH_SITE_KEY)
|
76
|
-
class_eval("::REST_AUTH_SITE_KEY = ''", __FILE__, __LINE__)
|
77
|
-
end
|
78
|
-
CryptoProviders::Sha1.stretches = 1
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# @api private
|
83
|
-
def restful_auth_crypto_provider=(provider)
|
84
|
-
if act_like_restful_authentication
|
85
|
-
self.crypto_provider = provider
|
86
|
-
else
|
87
|
-
self.transition_from_crypto_providers = provider
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# :nodoc:
|
93
|
-
module InstanceMethods
|
94
|
-
private
|
95
|
-
|
96
|
-
def act_like_restful_authentication?
|
97
|
-
self.class.act_like_restful_authentication == true
|
98
|
-
end
|
99
|
-
|
100
|
-
def transition_from_restful_authentication?
|
101
|
-
self.class.transition_from_restful_authentication == true
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module ActsAsAuthentic
|
3
|
-
# Allows you to scope everything to specific fields. See the Config
|
4
|
-
# submodule for more info. For information on how to scope off of a parent
|
5
|
-
# object see Authlogic::AuthenticatesMany
|
6
|
-
module ValidationsScope
|
7
|
-
def self.included(klass)
|
8
|
-
klass.class_eval do
|
9
|
-
extend Config
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# All configuration for the scope feature.
|
14
|
-
module Config
|
15
|
-
# Allows you to scope everything to specific field(s). Works just like
|
16
|
-
# validates_uniqueness_of. For example, let's say a user belongs to a
|
17
|
-
# company, and you want to scope everything to the company:
|
18
|
-
#
|
19
|
-
# acts_as_authentic do |c|
|
20
|
-
# c.validations_scope = :company_id
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# * <tt>Default:</tt> nil
|
24
|
-
# * <tt>Accepts:</tt> Symbol or Array of symbols
|
25
|
-
#
|
26
|
-
# @deprecated
|
27
|
-
def validations_scope(value = nil)
|
28
|
-
deprecate_authlogic_config("validations_scope") if value
|
29
|
-
rw_config(:validations_scope, value)
|
30
|
-
end
|
31
|
-
alias_method :validations_scope=, :validations_scope
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module AuthenticatesMany
|
3
|
-
# An object of this class is used as a proxy for the authenticates_many
|
4
|
-
# relationship. It basically allows you to "save" scope details and call
|
5
|
-
# them on an object, which allows you to do the following:
|
6
|
-
#
|
7
|
-
# @account.user_sessions.new
|
8
|
-
# @account.user_sessions.find
|
9
|
-
# # ... etc
|
10
|
-
#
|
11
|
-
# You can call all of the class level methods off of an object with a saved
|
12
|
-
# scope, so that calling the above methods scopes the user sessions down to
|
13
|
-
# that specific account. To implement this via ActiveRecord do something
|
14
|
-
# like:
|
15
|
-
#
|
16
|
-
# class User < ApplicationRecord
|
17
|
-
# authenticates_many :user_sessions
|
18
|
-
# end
|
19
|
-
class Association
|
20
|
-
attr_accessor :klass, :find_options, :id
|
21
|
-
|
22
|
-
# - id: Usually `nil`, but if the `scope_cookies` option is used, then
|
23
|
-
# `id` is a string like "company_123". It may seem strange to refer
|
24
|
-
# to such a string as an "id", but the naming is intentional, and
|
25
|
-
# is derived from `Authlogic::Session::Id`.
|
26
|
-
def initialize(klass, find_options, id)
|
27
|
-
self.klass = klass
|
28
|
-
self.find_options = find_options
|
29
|
-
self.id = id
|
30
|
-
end
|
31
|
-
|
32
|
-
%i[create create! find new].each do |method|
|
33
|
-
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
34
|
-
def #{method}(*args)
|
35
|
-
klass.with_scope(scope_options) do
|
36
|
-
klass.#{method}(*args)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
EOS
|
40
|
-
end
|
41
|
-
alias_method :build, :new
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def scope_options
|
46
|
-
{ find_options: find_options, id: id }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
# This allows you to scope your authentication. For example, let's say all users belong
|
3
|
-
# to an account, you want to make sure only users that belong to that account can
|
4
|
-
# actually login into that account. Simple, just do:
|
5
|
-
#
|
6
|
-
# class Account < ApplicationRecord
|
7
|
-
# authenticates_many :user_sessions
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# Now you can scope sessions just like everything else in ActiveRecord:
|
11
|
-
#
|
12
|
-
# @account.user_sessions.new(*args)
|
13
|
-
# @account.user_sessions.create(*args)
|
14
|
-
# @account.user_sessions.find(*args)
|
15
|
-
# # ... etc
|
16
|
-
#
|
17
|
-
# Checkout the authenticates_many method for a list of options.
|
18
|
-
# You may also want to checkout Authlogic::ActsAsAuthentic::Scope to scope your model.
|
19
|
-
module AuthenticatesMany
|
20
|
-
# These methods become class methods of ::ActiveRecord::Base.
|
21
|
-
module Base
|
22
|
-
DPR_AUTH_MANY = <<~EOS.freeze
|
23
|
-
authenticates_many is deprecated without replacement. Let us know
|
24
|
-
if you would like to take over maintenance of this feature as a separate
|
25
|
-
gem. If no one volunteers to extract and maintain a new gem, then this
|
26
|
-
feature will simply be deleted.
|
27
|
-
EOS
|
28
|
-
|
29
|
-
# Allows you to set up a relationship with your sessions. See module
|
30
|
-
# definition above for more details.
|
31
|
-
#
|
32
|
-
# === Options
|
33
|
-
#
|
34
|
-
# * <tt>session_class:</tt> default: "#{name}Session",
|
35
|
-
# This is the related session class.
|
36
|
-
#
|
37
|
-
# * <tt>relationship_name:</tt>
|
38
|
-
# default: options[:session_class].klass_name.underscore.pluralize,
|
39
|
-
# This is the name of the relationship you want to use to scope
|
40
|
-
# everything. For example an Account has many Users. There should be a
|
41
|
-
# relationship called :users that you defined with a has_many. The
|
42
|
-
# reason we use the relationship is so you don't have to repeat
|
43
|
-
# yourself. The relationship could have all kinds of custom options. So
|
44
|
-
# instead of repeating yourself we essentially use the scope that the
|
45
|
-
# relationship creates.
|
46
|
-
#
|
47
|
-
# * <tt>find_options:</tt> default: nil,
|
48
|
-
# By default the find options are created from the relationship you
|
49
|
-
# specify with :relationship_name. But if you want to override this and
|
50
|
-
# manually specify find_options you can do it here. Specify options just
|
51
|
-
# as you would in ActiveRecord::Base.find.
|
52
|
-
#
|
53
|
-
# * <tt>scope_cookies:</tt> default: false
|
54
|
-
# By the nature of cookies they scope themselves if you are using
|
55
|
-
# subdomains to access accounts. If you aren't using subdomains you need
|
56
|
-
# to have separate cookies for each account, assuming a user is logging
|
57
|
-
# into more than one account. Authlogic can take care of this for you by
|
58
|
-
# prefixing the name of the cookie and session with the model id.
|
59
|
-
# Because it affects both cookies names and session keys, the name
|
60
|
-
# `scope_cookies` is misleading. Perhaps simply `scope` or `scoped`
|
61
|
-
# would have been better.
|
62
|
-
def authenticates_many(name, options = {})
|
63
|
-
::ActiveSupport::Deprecation.warn(DPR_AUTH_MANY)
|
64
|
-
options[:session_class] ||= name.to_s.classify.constantize
|
65
|
-
options[:relationship_name] ||= options[:session_class].klass_name.underscore.pluralize
|
66
|
-
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
67
|
-
def #{name}
|
68
|
-
find_options = #{options[:find_options].inspect} || #{options[:relationship_name]}.where(nil)
|
69
|
-
@#{name} ||= Authlogic::AuthenticatesMany::Association.new(
|
70
|
-
#{options[:session_class]},
|
71
|
-
find_options,
|
72
|
-
#{options[:scope_cookies] ? "self.class.model_name.name.underscore + '_' + self.send(self.class.primary_key).to_s" : 'nil'}
|
73
|
-
)
|
74
|
-
end
|
75
|
-
EOS
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
::ActiveRecord::Base.extend(Base) if defined?(::ActiveRecord)
|
80
|
-
end
|
81
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require "openssl"
|
2
|
-
|
3
|
-
module Authlogic
|
4
|
-
module CryptoProviders
|
5
|
-
# This encryption method is reversible if you have the supplied key. So in
|
6
|
-
# order to use this encryption method you must supply it with a key first.
|
7
|
-
# In an initializer, or before your application initializes, you should do
|
8
|
-
# the following:
|
9
|
-
#
|
10
|
-
# Authlogic::CryptoProviders::AES256.key = "long, unique, and random key"
|
11
|
-
#
|
12
|
-
# My final comment is that this is a strong encryption method, but its main
|
13
|
-
# weakness is that it's reversible. If you do not need to reverse the hash
|
14
|
-
# then you should consider Sha512 or BCrypt instead.
|
15
|
-
#
|
16
|
-
# Keep your key in a safe place, some even say the key should be stored on a
|
17
|
-
# separate server. This won't hurt performance because the only time it will
|
18
|
-
# try and access the key on the separate server is during initialization,
|
19
|
-
# which only happens once. The reasoning behind this is if someone does
|
20
|
-
# compromise your server they won't have the key also. Basically, you don't
|
21
|
-
# want to store the key with the lock.
|
22
|
-
class AES256
|
23
|
-
class << self
|
24
|
-
attr_writer :key
|
25
|
-
|
26
|
-
def encrypt(*tokens)
|
27
|
-
aes.encrypt
|
28
|
-
aes.key = @key
|
29
|
-
[aes.update(tokens.join) + aes.final].pack("m").chomp
|
30
|
-
end
|
31
|
-
|
32
|
-
def matches?(crypted, *tokens)
|
33
|
-
aes.decrypt
|
34
|
-
aes.key = @key
|
35
|
-
(aes.update(crypted.unpack("m").first) + aes.final) == tokens.join
|
36
|
-
rescue OpenSSL::CipherError
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def aes
|
43
|
-
if @key.blank?
|
44
|
-
raise ArgumentError.new(
|
45
|
-
"You must provide a key like #{name}.key = my_key before using the #{name}"
|
46
|
-
)
|
47
|
-
end
|
48
|
-
|
49
|
-
@aes ||= openssl_cipher_class.new("AES-256-ECB")
|
50
|
-
end
|
51
|
-
|
52
|
-
# `::OpenSSL::Cipher::Cipher` has been deprecated since at least 2014,
|
53
|
-
# in favor of `::OpenSSL::Cipher`, but a deprecation warning was not
|
54
|
-
# printed until 2016
|
55
|
-
# (https://github.com/ruby/openssl/commit/5c20a4c014) when openssl
|
56
|
-
# became a gem. Its first release as a gem was 2.0.0, in ruby 2.4.
|
57
|
-
# (See https://github.com/ruby/ruby/blob/v2_4_0/NEWS)
|
58
|
-
#
|
59
|
-
# When we eventually drop support for ruby < 2.4, we can probably also
|
60
|
-
# drop support for openssl gem < 2.
|
61
|
-
def openssl_cipher_class
|
62
|
-
if ::Gem::Version.new(::OpenSSL::VERSION) < ::Gem::Version.new("2.0.0")
|
63
|
-
::OpenSSL::Cipher::Cipher
|
64
|
-
else
|
65
|
-
::OpenSSL::Cipher
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require "digest/md5"
|
2
|
-
|
3
|
-
::ActiveSupport::Deprecation.warn(
|
4
|
-
<<~EOS,
|
5
|
-
authlogic/crypto_providers/wordpress.rb is deprecated without replacement.
|
6
|
-
Yes, the entire file. Don't `require` it. Let us know ASAP if you are still
|
7
|
-
using it.
|
8
|
-
|
9
|
-
Reasons for deprecation: This file is not autoloaded by
|
10
|
-
`authlogic/crypto_providers.rb`. It's not documented. There are no tests.
|
11
|
-
So, it's likely used by a *very* small number of people, if any. It's never
|
12
|
-
had any contributions except by its original author, Jeffry Degrande, in
|
13
|
-
2009. It is unclear why it should live in the main authlogic codebase. It
|
14
|
-
could be in a separate gem, authlogic-wordpress, or it could just live in
|
15
|
-
Jeffry's codebase, if he still even needs it, in 2018, nine years later.
|
16
|
-
EOS
|
17
|
-
caller(1)
|
18
|
-
)
|
19
|
-
|
20
|
-
module Authlogic
|
21
|
-
module CryptoProviders
|
22
|
-
# Crypto provider to transition from wordpress user accounts. Written by
|
23
|
-
# Jeffry Degrande in 2009. First released in 2.1.3.
|
24
|
-
#
|
25
|
-
# Problems:
|
26
|
-
#
|
27
|
-
# - There are no tests.
|
28
|
-
# - We can't even figure out how to run this without it crashing.
|
29
|
-
# - Presumably it implements some spec, but it doesn't mention which.
|
30
|
-
# - It is not documented anywhere.
|
31
|
-
# - There is no PR associated with this, and no discussion about it could be found.
|
32
|
-
#
|
33
|
-
class Wordpress
|
34
|
-
class << self
|
35
|
-
ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".freeze
|
36
|
-
|
37
|
-
def matches?(crypted, *tokens)
|
38
|
-
stretches = 1 << ITOA64.index(crypted[3, 1])
|
39
|
-
plain, salt = *tokens
|
40
|
-
hashed = Digest::MD5.digest(salt + plain)
|
41
|
-
stretches.times do
|
42
|
-
hashed = Digest::MD5.digest(hashed + plain)
|
43
|
-
end
|
44
|
-
crypted[0, 12] + encode_64(hashed, 16) == crypted
|
45
|
-
end
|
46
|
-
|
47
|
-
def encode_64(input, length)
|
48
|
-
output = ""
|
49
|
-
i = 0
|
50
|
-
while i < length
|
51
|
-
value = input[i]
|
52
|
-
i += 1
|
53
|
-
break if value.nil?
|
54
|
-
output += ITOA64[value & 0x3f, 1]
|
55
|
-
value |= input[i] << 8 if i < length
|
56
|
-
output += ITOA64[(value >> 6) & 0x3f, 1]
|
57
|
-
|
58
|
-
i += 1
|
59
|
-
break if i >= length
|
60
|
-
value |= input[i] << 16 if i < length
|
61
|
-
output += ITOA64[(value >> 12) & 0x3f, 1]
|
62
|
-
|
63
|
-
i += 1
|
64
|
-
break if i >= length
|
65
|
-
output += ITOA64[(value >> 18) & 0x3f, 1]
|
66
|
-
end
|
67
|
-
output
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/authlogic/regex.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
# This is a module the contains regular expressions used throughout Authlogic.
|
3
|
-
# The point of extracting them out into their own module is to make them
|
4
|
-
# easily available to you for other uses. Ex:
|
5
|
-
#
|
6
|
-
# validates_format_of :my_email_field, :with => Authlogic::Regex.email
|
7
|
-
module Regex
|
8
|
-
# A general email regular expression. It allows top level domains (TLD) to
|
9
|
-
# be from 2 - 24 in length. The decisions behind this regular expression
|
10
|
-
# were made by analyzing the list of top-level domains maintained by IANA
|
11
|
-
# and by reading this website:
|
12
|
-
# http://www.regular-expressions.info/email.html, which is an excellent
|
13
|
-
# resource for regular expressions.
|
14
|
-
EMAIL = /
|
15
|
-
\A
|
16
|
-
[A-Z0-9_.&%+\-']+ # mailbox
|
17
|
-
@
|
18
|
-
(?:[A-Z0-9\-]+\.)+ # subdomains
|
19
|
-
(?:[A-Z]{2,25}) # TLD
|
20
|
-
\z
|
21
|
-
/ix
|
22
|
-
|
23
|
-
# A draft regular expression for internationalized email addresses. Given
|
24
|
-
# that the standard may be in flux, this simply emulates @email_regex but
|
25
|
-
# rather than allowing specific characters for each part, it instead
|
26
|
-
# disallows the complement set of characters:
|
27
|
-
#
|
28
|
-
# - email_name_regex disallows: @[]^ !"#$()*,/:;<=>?`{|}~\ and control characters
|
29
|
-
# - domain_head_regex disallows: _%+ and all characters in email_name_regex
|
30
|
-
# - domain_tld_regex disallows: 0123456789- and all characters in domain_head_regex
|
31
|
-
#
|
32
|
-
# http://en.wikipedia.org/wiki/Email_address#Internationalization
|
33
|
-
# http://tools.ietf.org/html/rfc6530
|
34
|
-
# http://www.unicode.org/faq/idn.html
|
35
|
-
# http://ruby-doc.org/core-2.1.5/Regexp.html#class-Regexp-label-Character+Classes
|
36
|
-
# http://en.wikipedia.org/wiki/Unicode_character_property#General_Category
|
37
|
-
EMAIL_NONASCII = /
|
38
|
-
\A
|
39
|
-
[^[:cntrl:][@\[\]\^ \!"\#$\(\)*,\/:;<=>?`{|}~\\]]+ # mailbox
|
40
|
-
@
|
41
|
-
(?:[^[:cntrl:][@\[\]\^ \!\"\#$&\(\)*,\/:;<=>\?`{|}~\\_.%+']]+\.)+ # subdomains
|
42
|
-
(?:[^[:cntrl:][@\[\]\^ \!\"\#$&\(\)*,\/:;<=>\?`{|}~\\_.%+\-'0-9]]{2,25}) # TLD
|
43
|
-
\z
|
44
|
-
/x
|
45
|
-
|
46
|
-
# A simple regular expression that only allows for letters, numbers, spaces, and
|
47
|
-
# .-_@+. Just a standard login / username regular expression.
|
48
|
-
LOGIN = /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/
|
49
|
-
|
50
|
-
# Accessing the above constants using the following methods is deprecated.
|
51
|
-
|
52
|
-
# @deprecated
|
53
|
-
def self.email
|
54
|
-
::ActiveSupport::Deprecation.warn(
|
55
|
-
"Authlogic::Regex.email is deprecated, use Authlogic::Regex::EMAIL",
|
56
|
-
caller(1)
|
57
|
-
)
|
58
|
-
EMAIL
|
59
|
-
end
|
60
|
-
|
61
|
-
# @deprecated
|
62
|
-
def self.email_nonascii
|
63
|
-
::ActiveSupport::Deprecation.warn(
|
64
|
-
"Authlogic::Regex.email_nonascii is deprecated, use Authlogic::Regex::EMAIL_NONASCII",
|
65
|
-
caller(1)
|
66
|
-
)
|
67
|
-
EMAIL_NONASCII
|
68
|
-
end
|
69
|
-
|
70
|
-
# @deprecated
|
71
|
-
def self.login
|
72
|
-
::ActiveSupport::Deprecation.warn(
|
73
|
-
"Authlogic::Regex.login is deprecated, use Authlogic::Regex::LOGIN",
|
74
|
-
caller(1)
|
75
|
-
)
|
76
|
-
LOGIN
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require "request_store"
|
2
|
-
|
3
|
-
module Authlogic
|
4
|
-
module Session
|
5
|
-
# Activating Authlogic requires that you pass it an
|
6
|
-
# Authlogic::ControllerAdapters::AbstractAdapter object, or a class that
|
7
|
-
# extends it. This is sort of like a database connection for an ORM library,
|
8
|
-
# Authlogic can't do anything until it is "connected" to a controller. If
|
9
|
-
# you are using a supported framework, Authlogic takes care of this for you.
|
10
|
-
module Activation
|
11
|
-
class NotActivatedError < ::StandardError # :nodoc:
|
12
|
-
def initialize
|
13
|
-
super(
|
14
|
-
"You must activate the Authlogic::Session::Base.controller with " \
|
15
|
-
"a controller object before creating objects"
|
16
|
-
)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.included(klass)
|
21
|
-
klass.class_eval do
|
22
|
-
extend ClassMethods
|
23
|
-
include InstanceMethods
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module ClassMethods
|
28
|
-
# Returns true if a controller has been set and can be used properly.
|
29
|
-
# This MUST be set before anything can be done. Similar to how
|
30
|
-
# ActiveRecord won't allow you to do anything without establishing a DB
|
31
|
-
# connection. In your framework environment this is done for you, but if
|
32
|
-
# you are using Authlogic outside of your framework, you need to assign
|
33
|
-
# a controller object to Authlogic via
|
34
|
-
# Authlogic::Session::Base.controller = obj. See the controller= method
|
35
|
-
# for more information.
|
36
|
-
def activated?
|
37
|
-
!controller.nil?
|
38
|
-
end
|
39
|
-
|
40
|
-
# This accepts a controller object wrapped with the Authlogic controller
|
41
|
-
# adapter. The controller adapters close the gap between the different
|
42
|
-
# controllers in each framework. That being said, Authlogic is expecting
|
43
|
-
# your object's class to extend
|
44
|
-
# Authlogic::ControllerAdapters::AbstractAdapter. See
|
45
|
-
# Authlogic::ControllerAdapters for more info.
|
46
|
-
#
|
47
|
-
# Lastly, this is thread safe.
|
48
|
-
def controller=(value)
|
49
|
-
RequestStore.store[:authlogic_controller] = value
|
50
|
-
end
|
51
|
-
|
52
|
-
# The current controller object
|
53
|
-
def controller
|
54
|
-
RequestStore.store[:authlogic_controller]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module InstanceMethods
|
59
|
-
# Making sure we are activated before we start creating objects
|
60
|
-
def initialize(*args)
|
61
|
-
raise NotActivatedError unless self.class.activated?
|
62
|
-
super
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def controller
|
68
|
-
self.class.controller
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module Session
|
3
|
-
# Authlogic looks like ActiveRecord, sounds like ActiveRecord, but its not
|
4
|
-
# ActiveRecord. That's the goal here. This is useful for the various rails
|
5
|
-
# helper methods such as form_for, error_messages_for, or any method that
|
6
|
-
# expects an ActiveRecord object. The point is to disguise the object as an
|
7
|
-
# ActiveRecord object so we can take advantage of the many ActiveRecord
|
8
|
-
# tools.
|
9
|
-
module ActiveRecordTrickery
|
10
|
-
def self.included(klass)
|
11
|
-
klass.extend ActiveModel::Naming
|
12
|
-
klass.extend ActiveModel::Translation
|
13
|
-
|
14
|
-
# Support ActiveModel::Name#name for Rails versions before 4.0.
|
15
|
-
unless klass.model_name.respond_to?(:name)
|
16
|
-
ActiveModel::Name.module_eval do
|
17
|
-
alias_method :name, :to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
klass.extend ClassMethods
|
22
|
-
klass.send(:include, InstanceMethods)
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
# How to name the class, works JUST LIKE ActiveRecord, except it uses
|
27
|
-
# the following namespace:
|
28
|
-
#
|
29
|
-
# authlogic.models.user_session
|
30
|
-
def human_name(*)
|
31
|
-
I18n.t("models.#{name.underscore}", count: 1, default: name.humanize)
|
32
|
-
end
|
33
|
-
|
34
|
-
def i18n_scope
|
35
|
-
I18n.scope
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module InstanceMethods
|
40
|
-
# Don't use this yourself, this is to just trick some of the helpers
|
41
|
-
# since this is the method it calls.
|
42
|
-
def new_record?
|
43
|
-
new_session?
|
44
|
-
end
|
45
|
-
|
46
|
-
def persisted?
|
47
|
-
!(new_record? || destroyed?)
|
48
|
-
end
|
49
|
-
|
50
|
-
def destroyed?
|
51
|
-
record.nil?
|
52
|
-
end
|
53
|
-
|
54
|
-
def to_key
|
55
|
-
new_record? ? nil : record.to_key
|
56
|
-
end
|
57
|
-
|
58
|
-
# For rails >= 3.0
|
59
|
-
def to_model
|
60
|
-
self
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|