Class: Warden::Strategies::IdentityStrategy

Inherits:
Base
  • Object
show all
Defined in:
lib/warden/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/warden/strategy.rb', line 10

def authenticate!
  config = Rails.configuration
  handler = Identity::ConnectionHandler.new config.identity_key, config.identity_key_password, config.identity_certificate, config.identity_truststore
  # create the provider
  @provider = Identity::Provider::IdentityServiceProvider.new handler

  if session[:identity_username_key].nil? && session[:identity_display_items].nil?
    pretext = @provider.pre_authenticate params["username"], request.ip
    if pretext.result['content'] == 'SUCCESS'
      session[:identity_username_key] = pretext.name
      session[:identity_display_items] = pretext.display_items
    else
      fail! pretext.result['message']
    end
  elsif !session[:identity_display_items].nil?
    parameters = {}
    session[:identity_display_items].each do |display_item|
      key = display_item['name']
      Rails.logger.debug "looking for #{key}"
      parameters[key] = params[key]
    end
    context = @provider.authenticate session[:identity_username_key], request.ip, parameters
    case context.result['content']
    when 'CONTINUE'
      session[:identity_display_items] = context.display_items
      flash[:notice] = context.result['message']
    when 'RESET'
      session[:identity_username_key] = nil
      session[:identity_display_items] = nil
    when 'SUCCESS'
      username = context.name
      session[:identity_username_key] = nil
      session[:identity_display_items] = nil
      # this is an ephemeral user that needs to be handled in your custom login controller to associate with a "real" user account
      # password is explicitly nil, keep it that way
      user = User.new(:username => username)
      success! user
    else
      fail! context.result['message']
    end
  end
end

#valid?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/warden/strategy.rb', line 6

def valid?
  params["username"] || session[:identity_username_key]
end