修改rubycas-server/lib/casserver/authenticators/sql_bcrypt.rb中的以下代码
def matching_users
results = user_model.find(:all, :conditions => ["#{username_column} = ?", @username])
results.select { |user| BCrypt::Password.new(user.send(password_column.to_sym)) == @password }
end
至
def matching_users
if username_column.include?(',')
columns = username_column.split(',')
sql = ''
conditions = []
columns.each do |field|
if sql.length != 0
sql += ' or '
end
sql += "#{field} = ?"
conditions << @username
end
conditions.unshift(sql)
else
conditions = ["#{username_column} = ?", @username]
end
results = user_model.find(:all, :conditions => conditions)
results.select { |user| BCrypt::Password.new(user.send(password_column.to_sym)) == @password }
end
然后你可以像这样在 config.yml 中使用 mutli-fieds:
authenticator:
class: CASServer::Authenticators::SQLBcrypt
database:
adapter: mysql2
database: test
username: root
password: map
host: localhost
user_table: users
username_column: email,nickname,tel
password_column: encrypted_password