43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/devise_saml_authenticatable/model.rb', line 43
def authenticate_with_saml(saml_response)
key = Devise.saml_default_user_key
attributes = saml_response.attributes
if (Devise.saml_use_subject)
auth_value = saml_response.name_id
else
inv_attr = attribute_map.invert
auth_value = attributes[inv_attr[key.to_s]]
auth_value.try(:downcase!) if Devise.case_insensitive_keys.include?(key)
end
resource = where(key => auth_value).first
if (resource.nil? && !Devise.saml_create_user)
logger.info("User(#{auth_value}) not found. Not configured to create the user.")
return nil
end
if (resource.nil? && Devise.saml_create_user)
logger.info("Creating user(#{auth_value}).")
resource = new
set_user_saml_attributes(resource,attributes)
if (Devise.saml_use_subject)
resource.send "#{key}=", auth_value
end
resource.save!
end
resource
end
|