2013-08-17 21:48:01 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2014-05-03 12:34:36 +00:00
|
|
|
class Auth
|
|
|
|
include ApplicationLib
|
2013-08-17 21:48:01 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
authenticate user via username and password
|
|
|
|
|
|
|
|
result = Auth.check( username, password, user )
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = user_model # if authentication was successfully
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.check(username, password, user)
|
|
|
|
|
|
|
|
# use std. auth backends
|
|
|
|
config = [
|
|
|
|
{
|
|
|
|
:adapter => 'Auth::Internal',
|
|
|
|
},
|
|
|
|
{
|
2014-12-31 09:04:14 +00:00
|
|
|
:adapter => 'Auth::Developer',
|
2013-08-17 21:48:01 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
# added configured backends
|
|
|
|
Setting.where( :area => 'Security::Authentication' ).each {|setting|
|
|
|
|
if setting.state[:value]
|
|
|
|
config.push setting.state[:value]
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# try to login against configure auth backends
|
|
|
|
user_auth = nil
|
|
|
|
config.each {|config_item|
|
|
|
|
next if !config_item[:adapter]
|
|
|
|
|
|
|
|
# load backend
|
|
|
|
backend = self.load_adapter( config_item[:adapter] )
|
|
|
|
return if !backend
|
|
|
|
|
|
|
|
user_auth = backend.check( username, password, config_item, user )
|
|
|
|
|
|
|
|
# auth ok
|
|
|
|
if user_auth
|
|
|
|
|
|
|
|
# remember last login date
|
|
|
|
user_auth.update_last_login
|
|
|
|
|
|
|
|
return user_auth
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|