Class: CASServer::Authenticators::SQLRestAuth

Inherits:
Base
  • Object
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 Classes: CASUser

Instance Attribute Summary

Attributes inherited from Base

#options, #username

Instance Method Summary collapse

Methods inherited from Base

#configure, #extra_attributes

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
# File 'lib/casserver/authenticators/sql_rest_auth.rb', line 23

def validate(credentials)
  read_standard_credentials(credentials)
  
  raise CASServer::AuthenticatorError, "Cannot validate credentials because the authenticator hasn't yet been configured" unless @options
  raise CASServer::AuthenticatorError, "Invalid authenticator configuration!" unless @options[:database]
  
  CASUser.establish_connection @options[:database]
  CASUser.set_table_name @options[:user_table] || "users"
  
  username_column = @options[:username_column] || "email"
  
  results = CASUser.find(:all, :conditions => ["#{username_column} = ?", @username])
  
  if results.size > 0
    $LOG.warn("Multiple matches found for user '#{@username}'") if results.size > 1
    user = results.first
    return (user.crypted_password == user.encrypt(@password)) 
  else
    return false
  end
end