Class: CASServer::Authenticators::SQLRestAuth

Inherits:
SQLEncrypted show all
Defined in:
lib/casserver/authenticators/sql_rest_auth.rb

Overview

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.

  • git://github.com/technoweenie/restful-authentication.git

Defined Under Namespace

Modules: EncryptedPassword

Instance Attribute Summary

Attributes inherited from Base

#options, #username

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SQL

user_model

Methods inherited from Base

#configure, #extra_attributes

Class Method Details

.setup(options) ⇒ Object



55
56
57
58
# File 'lib/casserver/authenticators/sql_rest_auth.rb', line 55

def self.setup(options)
  super(options)
  user_model.__send__(:include, EncryptedPassword)
end

Instance Method Details

#validate(credentials) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/casserver/authenticators/sql_rest_auth.rb', line 23

def validate(credentials)
  read_standard_credentials(credentials)
  raise_if_not_configured

  raise CASServer::AuthenticatorError, "You must specify a 'site_key' in the SQLRestAuth authenticator's configuration!" unless  @options[:site_key]
  raise CASServer::AuthenticatorError, "You must specify 'digest_streches' in the SQLRestAuth authenticator's configuration!" unless  @options[:digest_streches]

  user_model = self.class.user_model

  username_column = @options[:username_column] || "email"

  $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}"
  results = user_model.find(:all, :conditions => ["#{username_column} = ?", @username])
  user_model.connection_pool.checkin(user_model.connection)

  if results.size > 0
    $LOG.warn("Multiple matches found for user '#{@username}'") if results.size > 1
    user = results.first
    if user.crypted_password == user.encrypt(@password,@options[:site_key],@options[:digest_streches])
      unless @options[:extra_attributes].blank?
        extract_extra(user)
        log_extra
      end
      return true
    else
      return false
    end
  else
    return false
  end
end