Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Commit

Permalink
Local and remote OpenID Ownings
Browse files Browse the repository at this point in the history
  • Loading branch information
atd committed Mar 4, 2010
1 parent 94bab01 commit 69c8eac
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app/models/open_id_owning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ class OpenIdOwning < ActiveRecord::Base
belongs_to :agent, :polymorphic => true
belongs_to :uri

named_scope :local, lambda { { :conditions => { :local => true } } }
named_scope :remote, lambda { { :conditions => { :local => false } } }

validates_presence_of :agent_id, :agent_type, :uri_id
end
4 changes: 3 additions & 1 deletion app/models/open_id_trust.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Agents with OpenID Server have OpenID trusts when approve sign in a Remote Server
# Agents with OpenID Server have OpenID trusts when approve signing in a Remote Server
#
# The URI of the Remove Server is the trusted URI
#
class OpenIdTrust < ActiveRecord::Base
belongs_to :agent, :polymorphic => true
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/station_3_to_4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def self.up

drop_table :categories
drop_table :categorizations

# local column should be in OpenID ownings, not in OpenID trusts
remove_column :open_id_trusts, :local
add_column :open_id_ownings, :local, :boolean, :default => false
end

def self.down
Expand All @@ -39,5 +43,9 @@ def self.down
t.integer :categorizable_id
t.string :categorizable_type
end

# local column should be in OpenID ownings, not in OpenID trusts
add_column :open_id_trusts, :local, :boolean, :default => false
remove_column :open_id_ownings, :local
end
end
2 changes: 1 addition & 1 deletion generators/station/templates/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def self.up
t.integer :agent_id
t.string :agent_type
t.integer :uri_id
t.boolean :local, :default => false
end

create_table :open_id_trusts do |t|
t.integer :agent_id
t.string :agent_type
t.integer :uri_id
t.boolean :local, :default => false
end


Expand Down
3 changes: 2 additions & 1 deletion lib/active_record/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def needs_password?
# False is Login/Password is not supported by this Agent
return false unless agent_options[:authentication].include?(:login_and_password)
# False if OpenID is suported and there is already an OpenID Owning associated
! (agent_options[:authentication].include?(:openid) && !openid_identifier.blank?)
! (agent_options[:authentication].include?(:openid) &&
openid_identifier.present? || openid_ownings.remote.any?)
end

# All Stages in which this Agent has a Performance
Expand Down
8 changes: 6 additions & 2 deletions lib/active_record/agent/authentication/openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ def self.included(base) #:nodoc:

module ClassMethods
# Find first Agent of this class owning this OpenID URI
#
# OpenIdOwning must be remote, since authenticated using local
# OpenID is a chicken and egg action.
def authenticate_with_openid(uri)
owning = uri.openid_ownings.find :first,
:conditions => [ "agent_type = ?", self.to_s ]
owning =
uri.openid_ownings.remote.find :first,
:conditions => { :agent_type => self.name }
owning ? owning.agent : nil
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/active_record/agent/openid_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ module InstanceMethods
# Create OpenID Ownings for the URIs hosted in this server
def create_openid_server_ownings
uris_path = "#{ Site.current.domain }/#{ self.class.to_s.tableize }/#{ to_param }"
uris = [ Uri.find_or_create_by_uri("http://#{ uris_path }", :local => true) ]
uris << Uri.find_or_create_by_uri("https://#{ uris_path }", :local => true) if Site.current.ssl?
uris = [ Uri.find_or_create_by_uri("http://#{ uris_path }") ]
uris << Uri.find_or_create_by_uri("https://#{ uris_path }") if Site.current.ssl?

uris.each do |u|
openid_uris << u unless openid_uris.include?(u)
unless openid_ownings.local.map(&:uri).include?(u)
openid_ownings.local.create :uri => u
end
end
end
end
Expand Down

0 comments on commit 69c8eac

Please sign in to comment.