| Class | CASServer::Authenticators::SQLRestAuth |
| In: |
lib/casserver/authenticators/sql_rest_auth.rb
|
| Parent: | CASServer::Authenticators::SQLEncrypted |
This is a version of the SQL authenticator that works nicely with RestfulAuthentication. Passwords are encrypted the same way as it done in RestfulAuthentication. Before use you this, you MUST configure rest_auth_digest_streches and rest_auth_site_key in config.
Using this authenticator requires restful authentication plugin on rails (client) side.
# File lib/casserver/authenticators/sql_rest_auth.rb, line 55
55: def self.setup(options)
56: super(options)
57: user_model.__send__(:include, EncryptedPassword)
58: end
# File lib/casserver/authenticators/sql_rest_auth.rb, line 23
23: def validate(credentials)
24: read_standard_credentials(credentials)
25: raise_if_not_configured
26:
27: raise CASServer::AuthenticatorError, "You must specify a 'site_key' in the SQLRestAuth authenticator's configuration!" unless @options[:site_key]
28: raise CASServer::AuthenticatorError, "You must specify 'digest_streches' in the SQLRestAuth authenticator's configuration!" unless @options[:digest_streches]
29:
30: user_model = self.class.user_model
31:
32: username_column = @options[:username_column] || "email"
33:
34: $LOG.debug "#{self.class}: [#{user_model}] " + "Connection pool size: #{user_model.connection_pool.instance_variable_get(:@checked_out).length}/#{user_model.connection_pool.instance_variable_get(:@connections).length}"
35: results = user_model.find(:all, :conditions => ["#{username_column} = ?", @username])
36: user_model.connection_pool.checkin(user_model.connection)
37:
38: if results.size > 0
39: $LOG.warn("Multiple matches found for user '#{@username}'") if results.size > 1
40: user = results.first
41: if user.crypted_password == user.encrypt(@password)
42: unless @options[:extra_attributes].blank?
43: extract_extra(user)
44: log_extra
45: end
46: return true
47: else
48: return false
49: end
50: else
51: return false
52: end
53: end