Module: Devise::Models::SamlAuthenticatable::ClassMethods

Defined in:
lib/devise_saml_authenticatable/model.rb

Instance Method Summary collapse

Instance Method Details

#attribute_map ⇒ Object



73
74
75
# File 'lib/devise_saml_authenticatable/model.rb', line 73

def attribute_map
  @attribute_map ||= attribute_map_for_environment
end

#authenticate_with_saml(saml_response) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/devise_saml_authenticatable/model.rb', line 31

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?
    if Devise.saml_create_user
      logger.info("Creating user(#{auth_value}).")
      resource = new
    else
      logger.info("User(#{auth_value}) not found.  Not configured to create the user.")
      return nil
    end
  end

  if Devise.saml_update_user || (resource.new_record? && Devise.saml_create_user)
    set_user_saml_attributes(resource, attributes)
    if (Devise.saml_use_subject)
      resource.send "#{key}=", auth_value
    end
    resource.save!
  end

  resource
end

#find_for_shibb_authentication(conditions) ⇒ Object



69
70
71
# File 'lib/devise_saml_authenticatable/model.rb', line 69

def find_for_shibb_authentication(conditions)
  find_for_authentication(conditions)
end

#reset_session_key_for(name_id) ⇒ Object



64
65
66
67
# File 'lib/devise_saml_authenticatable/model.rb', line 64

def reset_session_key_for(name_id)
  resource = find_by(Devise.saml_default_user_key => name_id)
  resource.update_attribute(Devise.saml_session_index_key, nil) unless resource.nil?
end