authlogic_drc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rich Davis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ MIT-LICENSE
2
+ README
3
+ Rakefile
4
+ init.rb
5
+ install.rb
6
+ lib/authlogic_drc.rb
7
+ lib/authlogic_drc/session.rb
8
+ spec/fixtures/users.yml
9
+ spec/models/user_session_spec.rb
10
+ spec/spec.opts
11
+ spec/spec_helper.rb
12
+ tasks/authlogic_cas_tasks.rake
13
+ test/authlogic_cas_test.rb
14
+ test/test_helper.rb
15
+ uninstall.rb
16
+ Manifest
data/README ADDED
@@ -0,0 +1,29 @@
1
+ AuthlogicDRC
2
+ ============
3
+
4
+ AuthlogicDRC is a DRC (DeRose Connect) add-on for the Authlogic authentication system.
5
+
6
+ This extension requires the DRCClient gem and a working DRC server with which it will communicate for authentication. You can get this plugin at http://github.com/dwaynemac/drc_client.
7
+
8
+ When using this extension, calls to persist your Authlogic session should work seamlessly, such as:
9
+
10
+ UserSession.find
11
+
12
+ You will need to add a session persistence before_filter in your controller like
13
+
14
+ before_filter DRCClient.filter
15
+
16
+ or
17
+
18
+ before_filter DRCClient.filter(:gateway => true)
19
+
20
+ to set current_drc_user for use with this add-on.
21
+
22
+ Copyright (c) 2010 Dwayne Macgowan, released under the MIT license
23
+
24
+ ============================
25
+ Code based on authlogic_cas:
26
+
27
+ http://github.com/thurisaz/authlogic_cas
28
+
29
+ Copyright (c) 2009 Rich Davis, released under the MIT license
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'echoe'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the authlogic_drc plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Generate documentation for the authlogic_drc plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'AuthlogicDRC'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ Echoe.new('authlogic_drc', '0.1.0') do |p|
28
+ p.description = "Authlogic Add-on for DRC"
29
+ p.url = "http://github.com/dwaynemac/authlogic_drc"
30
+ p.author = "Dwayne Macgowan"
31
+ p.email = "dwaynemac@gmail.com"
32
+ # p.ignore_pattern = ["tmp/*", "script/*"]
33
+ p.development_dependencies = ['drc_client']
34
+ end
35
+
36
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{authlogic_drc}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dwayne Macgowan"]
9
+ s.date = %q{2010-08-30}
10
+ s.description = %q{Authlogic Add-on for DRC}
11
+ s.email = %q{dwaynemac@gmail.com}
12
+ s.extra_rdoc_files = ["README", "lib/authlogic_drc.rb", "lib/authlogic_drc/session.rb", "tasks/authlogic_cas_tasks.rake"]
13
+ s.files = ["MIT-LICENSE", "README", "Rakefile", "init.rb", "install.rb", "lib/authlogic_drc.rb", "lib/authlogic_drc/session.rb", "spec/fixtures/users.yml", "spec/models/user_session_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/authlogic_cas_tasks.rake", "test/authlogic_cas_test.rb", "test/test_helper.rb", "uninstall.rb", "Manifest", "authlogic_drc.gemspec"]
14
+ s.homepage = %q{http://github.com/dwaynemac/authlogic_drc}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Authlogic_drc", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{authlogic_drc}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Authlogic Add-on for DRC}
20
+ s.test_files = ["test/test_helper.rb", "test/authlogic_cas_test.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<drc_client>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<drc_client>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<drc_client>, [">= 0"])
33
+ end
34
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'authlogic_cas'
2
+
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,3 @@
1
+ require "authlogic_drc/session"
2
+
3
+ Authlogic::Session::Base.send(:include, AuthlogicDRC::Session)
@@ -0,0 +1,44 @@
1
+ module AuthlogicDRC
2
+ module Session
3
+ def self.included(klass)
4
+ klass.class_eval do
5
+ include Methods
6
+ end
7
+ end
8
+
9
+ module Methods
10
+ def self.included(klass)
11
+ klass.class_eval do
12
+ persist.reject{|cb| [:persist_by_params,:persist_by_session,:persist_by_http_auth].include?(cb.method)}
13
+ persist :persist_by_drc, :if => :authenticating_with_drc?
14
+ end
15
+ end
16
+
17
+ # no credentials are passed in: the CAS server takes care of that and saving the session
18
+ # def credentials=(value)
19
+ # values = [:garbage]
20
+ # super
21
+ # end
22
+
23
+ def persist_by_drc
24
+ session_key = CASClient::Frameworks::Rails::Filter.client.username_session_key # TODO wrap in DRCClient
25
+
26
+ unless controller.session[session_key].blank?
27
+ self.attempted_record = search_for_record("find_by_#{klass.login_field}", controller.session[session_key])
28
+ end
29
+ !self.attempted_record.nil?
30
+ end
31
+
32
+ def authenticating_with_drc?
33
+ attempted_record.nil? && errors.empty? && drc_defined?
34
+ end
35
+
36
+ private
37
+
38
+ #todo: validate that cas filters have run. Authlogic controller adapter doesn't provide access to the filter_chain
39
+ def drc_defined?
40
+ defined?(DRCClient) && !DRCClient.config.nil?
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ charles:
2
+ login: charles
3
+ email: charles@example.com
4
+ password_salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
5
+ crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1
6
+ persistence_token: 00742970dc9e6319f8019fd54864d3ea740f04b1
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'authlogic/test_case'
3
+
4
+ describe UserSession do
5
+ fixtures :users
6
+
7
+ before(:all) do
8
+ activate_authlogic
9
+ @charles = User.find_by_login 'charles'
10
+ end
11
+
12
+ it "checks to see that the Rubycas plugin is installed before persisting" do
13
+ user_session = UserSession.new
14
+ has_plugin = user_session.send :drc_defined?
15
+ has_plugin.should == (CASClient::Frameworks::Rails::Filter.config.nil? ? false : true)
16
+ end
17
+
18
+ it "checks for existing user records before persisting" do
19
+ controller.session[CASClient::Frameworks::Rails::Filter.client.username_session_key] = @charles.login
20
+ user_session = UserSession.find
21
+ user_session.user.login.should == @charles.login
22
+ end
23
+
24
+ it "checks for the existence of the CAS session key" do
25
+ controller.session.delete CASClient::Frameworks::Rails::Filter.client.username_session_key
26
+ user_session = UserSession.find
27
+ user_session.should == nil
28
+ end
29
+
30
+ it "creates a user if none exists with the login column in CAS session" do
31
+ controller.session[CASClient::Frameworks::Rails::Filter.client.username_session_key] = 'darwin'
32
+
33
+ user_session = UserSession.find
34
+ user_session.user.login.should == 'darwin'
35
+ end
36
+
37
+ it "throws an error if it cannot create a new user when none previously existed" do
38
+ big_name = 'must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?'
39
+ controller.session[CASClient::Frameworks::Rails::Filter.client.username_session_key] = big_name
40
+ user_session = UserSession.find
41
+ user_session.should == nil
42
+ end
43
+
44
+ it "looks up CAS users with nonstandard columns" do
45
+ @user = users(:charles)
46
+ controller.session[CASClient::Frameworks::Rails::Filter.client.username_session_key] = @user.email
47
+ UserSession.cas_user_identifier = 'email'
48
+ user_session = UserSession.find
49
+ user_session.user.login.should == @user.email
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,13 @@
1
+ begin
2
+ require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
3
+ rescue LoadError
4
+ puts "You need to install rspec in your base app"
5
+ exit
6
+ end
7
+
8
+ plugin_spec_dir = File.dirname(__FILE__)
9
+ ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.fixture_path = './fixtures'
13
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :authlogic_cas do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class AuthlogicCasTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: authlogic_drc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dwayne Macgowan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-08-30 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: drc_client
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Authlogic Add-on for DRC
26
+ email: dwaynemac@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - lib/authlogic_drc.rb
34
+ - lib/authlogic_drc/session.rb
35
+ - tasks/authlogic_cas_tasks.rake
36
+ files:
37
+ - MIT-LICENSE
38
+ - README
39
+ - Rakefile
40
+ - init.rb
41
+ - install.rb
42
+ - lib/authlogic_drc.rb
43
+ - lib/authlogic_drc/session.rb
44
+ - spec/fixtures/users.yml
45
+ - spec/models/user_session_spec.rb
46
+ - spec/spec.opts
47
+ - spec/spec_helper.rb
48
+ - tasks/authlogic_cas_tasks.rake
49
+ - test/authlogic_cas_test.rb
50
+ - test/test_helper.rb
51
+ - uninstall.rb
52
+ - Manifest
53
+ - authlogic_drc.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/dwaynemac/authlogic_drc
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ - --title
63
+ - Authlogic_drc
64
+ - --main
65
+ - README
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "1.2"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project: authlogic_drc
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Authlogic Add-on for DRC
87
+ test_files:
88
+ - test/test_helper.rb
89
+ - test/authlogic_cas_test.rb