engines/adva_user/vendor/plugins/authentication/lib/authentication.rb
# Should be called on whatever ActiveRecord::Base subclass is
# being authenticated (i.e. User, Profile, etc.). The common
# case should look something like:
#
#   class User < ActiveRecord::Base
#     acts_as_authenticated_user
#   end
#
# Most of the time you will simply call this method with no
# arguments. In this case sane defaults will cause the
# application to authenticate with the local database. These
# sane defaults will attempt to provide you with the following:
#
# * A salted hash password authentication
# * A single token authentication ideal for URL tokens
# * A remember me authentication ideal for cookie remember me
#   functionality
#
# Those methods will only be provided if the model being
# authenticated provides the proper fields. See the documentation
# on those various authentication modules for what is required
# to make a module work.
#
# If you are interested in using other modules then you need to know
# the following:
#
# There are two types of authentication modules.
# The password auth type has the traditional user/password
# requirement to authenticate. A user can also typically change
# their password (although this is not required). An example
# of this module is the Authentication::SaltedHash module.
#
# The other type of module is a token module. A token module
# typically consist of a user and some sort of token that is
# not usually user entered. For example a single-signon system
# may use a token to avoid having to prompt the user. Examples
# of token modules are the Authentication::SingleToken module
# and the Authentication::RememberMe module. A token module may
# authenticate many different tokens for the same user. This allows
# a token module to assign different valid tokens to different
# systems so that a token can be revoked if desired. Token
# authentications often also have a time expiration that a token
# is valid for. After that time has expired the token no longer
# works.
#
# If you desire to change the modules used this macro method
# accepts two options in the option hash. The option
# :authenticate_with is how you specify one or more password auth
# modules. The option :token_with is how you specify one or more
# token modules to authenticate with.
#
# Both options can accept values in following formats:
#
# single module::
#   In this case a single module name is provided to authenticate
#   against. For example:
#     acts_as_authenticated_user :authenticate_with => 'Authentication::POP3'
# chain of modules::
#   In this case a list of modules will be used to authenticate
#   against. If any of them are a success then the user
#   authenticates. Otherwise the user will not successfully login.
#   For example:
#     acts_as_authenticated_user :authenticate_with =>
#       ['Authentication::ActiveDirectory', 'Authentication::POP3']
# module with arguments::
#   In this case a single module is being used but it has arguments
#   which are passed to the module when instantated. For example:
#     acts_as_authenticated_user :authenticate_with =>
#       {'Authentication::POP3' => ['pop3.example.org', 110]}
#   In this case the code will call
#   Authentication::POP3.new('pop3.example.org', 110) when
#   instantionating the object. More than likely the authentication
#   module will just have one argument which is an option hash. In
#   this case you might initialize that module like the following:
#     acts_as_authenticated_user :authenticate_with =>
#       {'Authentication::POP3' =>
#       {:server => 'pop3.example.org', :port => 110}}
# chain of modules with arguments::
#   You can also chain modules and use arguments. In this case you
#   just pass the method an array of hashes. For example:
#     acts_as_authenticated_user :authenticate_with =>
#       [
#         {'Authentication::POP3' =>
#           {:server => 'pop3.example.com', :port => 5000}},
#         {'Autnentication::ActiveDirectory' =>
#           {:server => 'ad.example.com'}}
#       ]
#
# If you wish to provide a different scheme depending on the
# environment (i.e. production vs. development) then you can
# assign your argument to the Module method "default_scheme"
# on the Authentication module in the proper environment file.
# For example:
#
#   Authentication.default_scheme = {
#     :authenticate_with => 'Authentication::POP3',
#     :token_with => []
#   }
#
# This would authenticate with POP3 and not provide any token
# mechanism.
Should be called on whatever ActiveRecord::Base subclass is
being authenticated . The common
case should look something like.



Most of the time you will simply call this method with no
arguments. In this case sane defaults will cause the
application to authenticate with the local database. These
sane defaults will attempt to provide you with the following.

A salted hash password authentication
A single token authentication ideal for URL tokens
A remember me authentication ideal for cookie remember me
functionality

Those methods will only be provided if the model being
authenticated provides the proper fields. See the documentation
on those various authentication modules for what is required
to make a module work.

If you are interested in using other modules then you need to know
the following.

There are two types of authentication modules.
The password auth type has the traditional user/password
requirement to authenticate. A user can also typically change
their password (although this is not required). An example
of this module is the Authentication::SaltedHash module.

The other type of module is a token module. A token module
typically consist of a user and some sort of token that is
not usually user entered. For example a single-signon system
may use a token to avoid having to prompt the user. Examples
of token modules are the Authentication::SingleToken module
and the Authentication::RememberMe module. A token module may
authenticate many different tokens for the same user. This allows
a token module to assign different valid tokens to different
systems so that a token can be revoked if desired. Token
authentications often also have a time expiration that a token
is valid for. After that time has expired the token no longer
works.

If you desire to change the modules used this macro method
accepts two options in the option hash. The option
:authenticate_with is how you specify one or more password auth
modules. The option :token_with is how you specify one or more
token modules to authenticate with.

Both options can accept values in following formats.

single module::
In this case a single module name is provided to authenticate
against.

If you wish to provide a different scheme depending on the
environment  then you can
assign your argument to the Module method "default_scheme"
on the Authentication module in the proper environment file.
For example.

Authentication.default_scheme = {
:authenticate_with => 'Authentication::POP3',
:token_with => []
}

This would authenticate with POP3 and not provide any token
mechanism.
Should be called on whatever ActiveRecord :: Base subclass is being authenticated . The common case should look something like . Most of the time you will simply call this method with no arguments . In this case sane defaults will cause the application to authenticate with the local database . These sane defaults will attempt to provide you with the following . A salted hash password authentication A single token authentication ideal for URL tokens A remember me authentication ideal for cookie remember me functionality Those methods will only be provided if the model being authenticated provides the proper fields . See the documentation on those various authentication modules for what is required to make a module work . If you are interested in using other modules then you need to know the following . There are two types of authentication modules . The password auth type has the traditional user / password requirement to authenticate . A user can also typically change their password ( although this is not required ) . An example of this module is the Authentication :: SaltedHash module . The other type of module is a token module . A token module typically consist of a user and some sort of token that is not usually user entered . For example a single - signon system may use a token to avoid having to prompt the user . Examples of token modules are the Authentication :: SingleToken module and the Authentication :: RememberMe module . A token module may authenticate many different tokens for the same user . This allows a token module to assign different valid tokens to different systems so that a token can be revoked if desired . Token authentications often also have a time expiration that a token is valid for . After that time has expired the token no longer works . If you desire to change the modules used this macro method accepts two options in the option hash . The option : authenticate_with is how you specify one or more password auth modules . The option : token_with is how you specify one or more token modules to authenticate with . Both options can accept values in following formats . single module :: In this case a single module name is provided to authenticate against . If you wish to provide a different scheme depending on the environment then you can assign your argument to the Module method " default_scheme " on the Authentication module in the proper environment file . For example . Authentication . default_scheme = { : authenticate_with = > ' Authentication :: POP3 ' : token_with = > [] } This would authenticate with POP3 and not provide any token mechanism .
def acts_as_authenticated_user(options={})
      options.reverse_merge! Authentication.default_scheme
      {
        :authenticate_with => :authentication_modules,
        :token_with => :token_modules,
      }.each do |option, mod_type|
        mods = [options[option]].flatten.compact
        mods = mods.inject([]) do |memo, mod|
          if mod.is_a? Hash
            mod.each do |m, args|
              args = [args] unless args.is_a? Array
              memo << m.constantize.new(*args)
            end
          else
            memo << mod.constantize.new
          end
          memo
        end
        class_inheritable_accessor mod_type
        private
        self.send "#{mod_type.to_s}=".to_sym, mods
      end
      include Authentication::InstanceMethods
      if method_defined?(:password=) 
        before_validation :assign_password
      end
    end
def acts_as_authenticated_user ( options = { } ) options . reverse_merge! Authentication . default_scheme { :authenticate_with => :authentication_modules , :token_with => :token_modules , } . each do | option , mod_type | mods = [ options [ option ] ] . flatten . compact mods = mods . inject ( [ ] ) do | memo , mod | if mod . is_a? Hash mod . each do | m , args | args = [ args ] unless args . is_a? Array memo << m . constantize . new ( * args ) end else memo << mod . constantize . new end memo end class_inheritable_accessor mod_type private self . send "#{mod_type.to_s}=" . to_sym , mods end include Authentication :: InstanceMethods if method_defined? ( :password= ) before_validation :assign_password end end
Should be called on whatever ActiveRecord::Base subclass is
being authenticated (i.e.
Should be called on whatever ActiveRecord :: Base subclass is being authenticated ( i . e .
# Process arguments and store in instantiated auth modules # TODO rather have these in the client class? # after_save :reset_password
options