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

Includes:
DeviseSamlAuthenticatable::SamlConfig
Defined in:
lib/devise_saml_authenticatable/model.rb

Instance Method Summary collapse

Methods included from DeviseSamlAuthenticatable::SamlConfig

#saml_config

Instance Method Details

#attribute_map ⇒ Object



87
88
89
# File 'lib/devise_saml_authenticatable/model.rb', line 87

def attribute_map
  @attribute_map ||= attribute_map_for_environment
end

#authenticate_with_saml(saml_response) ⇒ Object



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
71
72
73
74
75
76
# File 'lib/devise_saml_authenticatable/model.rb', line 45

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



83
84
85
# File 'lib/devise_saml_authenticatable/model.rb', line 83

def find_for_shibb_authentication(conditions)
  find_for_authentication(conditions)
end

#reset_session_key_for(name_id) ⇒ Object



78
79
80
81
# File 'lib/devise_saml_authenticatable/model.rb', line 78

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