Sha256: 5e15fef9cfd6ad029088429c59543c58f32c303916d26d103e053d08397c78ed

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

require 'ruby-saml'
module DeviseSamlAuthenticatable
  module SamlConfig
    def saml_config(idp_entity_id = nil)
      return file_based_config if file_based_config
      return adapter_based_config(idp_entity_id) if Devise.idp_settings_adapter

      Devise.saml_config
    end

    private

    def file_based_config
      return @file_based_config if @file_based_config
      idp_config_path = "#{Rails.root}/config/idp.yml"

      if File.exists?(idp_config_path)
        @file_based_config ||= OneLogin::RubySaml::Settings.new(YAML.load(File.read(idp_config_path))[Rails.env])
      end
    end

    def adapter_based_config(idp_entity_id)
      config = Marshal.load(Marshal.dump(Devise.saml_config))

      idp_settings_adapter.settings(idp_entity_id).each do |k,v|
        acc = "#{k.to_s}=".to_sym

        if config.respond_to? acc
          config.send(acc, v)
        end
      end
      config
    end

    def get_idp_entity_id(params)
      idp_entity_id_reader.entity_id(params)
    end

    def idp_entity_id_reader
      if Devise.idp_entity_id_reader.respond_to?(:entity_id)
        Devise.idp_entity_id_reader
      else
        @idp_entity_id_reader ||= Devise.idp_entity_id_reader.constantize
      end
    end

    def idp_settings_adapter
      if Devise.idp_settings_adapter.respond_to?(:settings)
        Devise.idp_settings_adapter
      else
        @idp_settings_adapter ||= Devise.idp_settings_adapter.constantize
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
devise_saml_authenticatable-1.8.0 lib/devise_saml_authenticatable/saml_config.rb
devise_saml_authenticatable-1.7.0 lib/devise_saml_authenticatable/saml_config.rb
devise_saml_authenticatable-1.6.3 lib/devise_saml_authenticatable/saml_config.rb