2013-04-21 00:32:23 -04:00
|
|
|
require 'krb5_auth'
|
|
|
|
include Krb5Auth
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
module KerberosAdapter
|
|
|
|
def self.valid_credentials?(username, password)
|
2015-06-22 13:09:42 -04:00
|
|
|
if test_environment? && username == 'test' && password == 'test' then
|
2014-01-26 09:29:38 -05:00
|
|
|
return true
|
2013-04-21 00:32:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
krb5 = Krb5.new
|
|
|
|
begin
|
2015-06-22 13:09:42 -04:00
|
|
|
krb5.get_init_creds_password(username_with_realm(username), password)
|
2013-04-21 00:32:23 -04:00
|
|
|
rescue Krb5Auth::Krb5::Exception
|
2014-01-25 09:23:11 -05:00
|
|
|
return false
|
2013-04-21 00:32:23 -04:00
|
|
|
end
|
|
|
|
|
2014-01-25 09:23:11 -05:00
|
|
|
return true
|
2013-04-21 00:32:23 -04:00
|
|
|
end
|
2015-06-22 13:09:42 -04:00
|
|
|
|
|
|
|
def username_with_realm(username)
|
|
|
|
"#{username}@#{::Devise.kerberos_realm}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.test_environment?
|
|
|
|
Rails.env.test? || Rails.env.development?
|
|
|
|
end
|
2013-04-21 00:32:23 -04:00
|
|
|
end
|
|
|
|
end
|