Class: OpenID::Consumer::AssociationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/consumer/associationmanager.rb

Overview

An object that manages creating and storing associations for an OpenID provider endpoint

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, server_url, compatibility_mode = false, negotiator = nil) ⇒ AssociationManager

Returns a new instance of AssociationManager.



103
104
105
106
107
108
109
# File 'lib/openid/consumer/associationmanager.rb', line 103

def initialize(store, server_url, compatibility_mode=false,
               negotiator=nil)
  @store = store
  @server_url = server_url
  @compatibility_mode = compatibility_mode
  @negotiator = negotiator || DefaultNegotiator
end

Class Method Details

.create_session(session_type) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/openid/consumer/associationmanager.rb', line 89

def self.create_session(session_type)
  case session_type
  when 'no-encryption'
    NoEncryptionSession.new
  when 'DH-SHA1'
    DiffieHellmanSHA1Session.new
  when 'DH-SHA256'
    DiffieHellmanSHA256Session.new
  else
    raise ArgumentError, "Unknown association session type: "\
                         "#{session_type.inspect}"
  end
end

Instance Method Details

#get_associationObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/openid/consumer/associationmanager.rb', line 111

def get_association
  if @store.nil?
    return nil
  end

  assoc = @store.get_association(@server_url)
  if assoc.nil? || assoc.expires_in <= 0
    assoc = negotiate_association
    if !assoc.nil?
      @store.store_association(@server_url, assoc)
    end
  end

  return assoc
end

#negotiate_associationObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openid/consumer/associationmanager.rb', line 127

def negotiate_association
  assoc_type, session_type = @negotiator.get_allowed_type
  begin
    return request_association(assoc_type, session_type)
  rescue ServerError => why
    supported_types = extract_supported_association_type(why, assoc_type)
    if !supported_types.nil?
      # Attempt to create an association from the assoc_type and
      # session_type that the server told us it supported.
      assoc_type, session_type = supported_types
      begin
        return request_association(assoc_type, session_type)
      rescue ServerError => why
        Util.log("Server #{@server_url} refused its suggested " \
                 "association type: session_type=#{session_type}, " \
                 "assoc_type=#{assoc_type}")
        return nil
      end
    end
  rescue InvalidOpenIDNamespace
    Util.log("Server #{@server_url} returned a malformed association " \
             "response.  Falling back to check_id mode for this request.")
    return nil
  end
end