Permalink
Browse files

Look up the user via the devise annotated model and field name

Decreased the log level of several messages
  • Loading branch information...
1 parent 1b6be0e commit b0b439466ad2a249a7aab333a622c1e7b1b8967f Joe George committed Jul 27, 2012
Showing with 12 additions and 12 deletions.
  1. +12 −12 lib/devise_shibboleth_authenticatable/model.rb
@@ -27,22 +27,22 @@ def update_without_password(params={})
module ClassMethods
def authenticate_with_shibboleth(env)
- resource = User.find_by_email(env['eppn'])
+ auth_key = self.authentication_keys.first
+ auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? env['eppn'].downcase : env['eppn']
- if (!resource.nil? && !Devise.shibboleth_create_user)
- logger.fatal("User(#{env['eppn']}) not found. Not configured to create the user.")
- return resource
+ resource = where(auth_key => auth_key_value).first
+
+ if (resource.nil? && !Devise.shibboleth_create_user)
+ logger.info("User(#{auth_key_value}) not found. Not configured to create the user.")
+ return nil
end
if (resource.nil? && Devise.shibboleth_create_user)
- logger.fatal("Creating user(#{env['eppn']}).")
- resource = User.new()
+ logger.info("Creating user(#{auth_key_value}).")
+ resource = new
+ save_user_shibboleth_headers(resource, env)
+ resource.save
end
- return nil unless resource
-
- save_user_shibboleth_headers(resource, env)
-
- resource.save
resource
end
@@ -54,7 +54,7 @@ def find_for_shibb_authentication(conditions)
def save_user_shibboleth_headers(user, env)
shib_config = YAML.load(ERB.new(File.read(::Devise.shibboleth_config || "#{Rails.root}/config/shibboleth.yml")).result)[Rails.env]
shib_config['user-mapping'].each do |model, header|
- logger.fatal("Saving #{env[header]} to #{model}")
+ logger.info("Saving #{env[header]} to #{model}")
field = "#{model}="
value = env[header]
user.send(field, value.to_s)

0 comments on commit b0b4394

Please sign in to comment.