authlogic_crowd_rest 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/authlogic_crowd_rest.gemspec +3 -3
- data/lib/authlogic_crowd_rest/acts_as_authentic.rb +19 -0
- data/lib/authlogic_crowd_rest/session.rb +56 -10
- data/test/session_test.rb +16 -15
- data/test/test_helper.rb +1 -3
- metadata +13 -13
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{authlogic_crowd_rest}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rob Di Marco"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-07}
|
13
13
|
s.description = %q{Foo}
|
14
14
|
s.email = %q{rob.dimarco@416software.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
s.homepage = %q{http://github.com/robdimarco/authlogic_crowd_rest}
|
40
40
|
s.licenses = ["MIT"]
|
41
41
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.
|
42
|
+
s.rubygems_version = %q{1.6.0}
|
43
43
|
s.summary = %q{An Authlogic plugin to connect with Atlassian Crowd REST APIs}
|
44
44
|
s.test_files = [
|
45
45
|
"test/acts_as_authentic_test.rb",
|
@@ -8,13 +8,32 @@ module AuthlogicCrowdRest
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module Config
|
11
|
+
# Whether or not to validate the crowd_login field. If set to false ALL crowd validation will need to be
|
12
|
+
# handled by you.
|
13
|
+
#
|
14
|
+
# * <tt>Default:</tt> true
|
15
|
+
# * <tt>Accepts:</tt> Boolean
|
16
|
+
def validate_crowd_login(value = nil)
|
17
|
+
rw_config(:validate_crowd_login, value, true)
|
18
|
+
end
|
19
|
+
alias_method :validate_crowd_login=, :validate_crowd_login
|
11
20
|
end
|
12
21
|
|
13
22
|
module Methods
|
14
23
|
def self.included(klass)
|
24
|
+
return if !klass.column_names.include?("crowd_login")
|
15
25
|
klass.class_eval do
|
26
|
+
attr_accessor :crowd_password
|
27
|
+
|
28
|
+
if validate_crowd_login
|
29
|
+
validates_uniqueness_of :crowd_login, :scope => validations_scope, :if => :using_crowd?
|
30
|
+
end
|
16
31
|
end
|
17
32
|
end
|
33
|
+
private
|
34
|
+
def using_crowd?
|
35
|
+
respond_to?(:crowd_login) && !crowd_login.blank?
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
20
39
|
end
|
@@ -35,12 +35,56 @@ module AuthlogicCrowdRest
|
|
35
35
|
rw_config(:crowd_application_password, value)
|
36
36
|
end
|
37
37
|
alias_method :crowd_application_password=, :crowd_application_password
|
38
|
+
|
39
|
+
# Once Crowd authentication has succeeded we need to find the user in the database. By default this just calls the
|
40
|
+
# find_by_crowd_login method provided by ActiveRecord. If you have a more advanced set up and need to find users
|
41
|
+
# differently specify your own method and define your logic in there.
|
42
|
+
#
|
43
|
+
# For example, if you allow users to store multiple crowd logins with their account, you might do something like:
|
44
|
+
#
|
45
|
+
# class User < ActiveRecord::Base
|
46
|
+
# def self.find_by_crowd_login(login)
|
47
|
+
# first(:conditions => ["#{CrowdLogin.table_name}.login = ?", login], :join => :crowd_logins)
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# * <tt>Default:</tt> :find_by_crowd_login
|
52
|
+
# * <tt>Accepts:</tt> Symbol
|
53
|
+
def find_by_crowd_login_method(value = nil)
|
54
|
+
rw_config(:find_by_crowd_login_method, value, :find_by_crowd_login)
|
55
|
+
end
|
56
|
+
alias_method :find_by_crowd_login_method=, :find_by_crowd_login_method
|
38
57
|
end
|
39
58
|
|
40
59
|
module Methods
|
41
60
|
def self.included(klass)
|
42
61
|
klass.class_eval do
|
43
62
|
validate :validate_by_crowd_rest, :if => :authenticating_with_crowd_rest?
|
63
|
+
attr_accessor :crowd_login
|
64
|
+
attr_accessor :crowd_password
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Hooks into credentials so that you can pass an :ldap_login and :ldap_password key.
|
69
|
+
# Hooks into credentials to print out meaningful credentials for LDAP authentication.
|
70
|
+
def credentials
|
71
|
+
if authenticating_with_crowd_rest?
|
72
|
+
details = {}
|
73
|
+
details[:crowd_login] = send(login_field)
|
74
|
+
details[:crowd_password] = "<protected>"
|
75
|
+
details
|
76
|
+
else
|
77
|
+
super
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def credentials=(value)
|
82
|
+
super
|
83
|
+
values = value.is_a?(Array) ? value : [value]
|
84
|
+
hash = values.first.is_a?(Hash) ? values.first.with_indifferent_access : nil
|
85
|
+
if !hash.nil?
|
86
|
+
self.crowd_login = hash[:crowd_login] if hash.key?(:crowd_login)
|
87
|
+
self.crowd_password = hash[:crowd_password] if hash.key?(:crowd_password)
|
44
88
|
end
|
45
89
|
end
|
46
90
|
|
@@ -51,41 +95,40 @@ module AuthlogicCrowdRest
|
|
51
95
|
|
52
96
|
def validate_by_crowd_rest
|
53
97
|
self.invalid_password = false
|
54
|
-
|
55
|
-
errors.add(
|
98
|
+
|
99
|
+
errors.add(:crowd_login, I18n.t('error_messages.crowd_login_blank', :default => "can not be blank")) if crowd_login.blank?
|
100
|
+
errors.add(:crowd_password, I18n.t('error_messages.crowd_password_blank', :default => "can not be blank")) if crowd_password.blank?
|
56
101
|
return if errors.count > 0
|
57
102
|
|
58
|
-
self.attempted_record = search_for_record(
|
103
|
+
self.attempted_record = search_for_record(find_by_crowd_login_method, crowd_login)
|
59
104
|
if attempted_record.blank?
|
60
105
|
generalize_credentials_error_messages? ?
|
61
106
|
add_general_credentials_error :
|
62
|
-
errors.add(
|
107
|
+
errors.add("crowd_login", I18n.t('error_messages.crowd_login_not_found', :default => "is not valid"))
|
63
108
|
return
|
64
109
|
end
|
65
110
|
|
66
111
|
if !(send( :verify_crowd_password, attempted_record))
|
67
|
-
puts "Invalid!"
|
68
112
|
self.invalid_password = true
|
69
113
|
generalize_credentials_error_messages? ?
|
70
114
|
add_general_credentials_error :
|
71
|
-
errors.add(
|
115
|
+
errors.add("crowd_password", I18n.t('error_messages.crowd_password_invalid', :default => "is not valid"))
|
72
116
|
return
|
73
117
|
end
|
74
118
|
end
|
75
119
|
|
76
120
|
def verify_crowd_password(attempted_record)
|
77
|
-
password = attempted_record.send(verify_password_method, send("protected_#{password_field}"))
|
78
121
|
require 'net/http'
|
79
122
|
require 'net/https'
|
80
|
-
uri = URI.parse(send("crowd_base_url"))
|
123
|
+
uri = URI.parse(send("crowd_base_url") + "/rest/usermanagement/latest/authentication")
|
81
124
|
|
82
125
|
begin
|
83
126
|
http = Net::HTTP.new(uri.host, uri.port)
|
84
127
|
http.use_ssl = uri.scheme == "https"
|
85
128
|
http.start {|http|
|
86
|
-
req = Net::HTTP::Post.new(uri.path + "?" + "username=#{
|
129
|
+
req = Net::HTTP::Post.new(uri.path + "?" + "username=#{crowd_login}")
|
87
130
|
req.basic_auth send("crowd_application_name"), send("crowd_application_password")
|
88
|
-
req.body="<password><value>#{
|
131
|
+
req.body="<password><value>#{crowd_password}</value></password>"
|
89
132
|
req.add_field 'Content-Type', 'text/xml'
|
90
133
|
resp, data = http.request(req)
|
91
134
|
resp.code.to_i == 200
|
@@ -105,6 +148,9 @@ module AuthlogicCrowdRest
|
|
105
148
|
def crowd_base_url
|
106
149
|
self.class.crowd_base_url
|
107
150
|
end
|
151
|
+
def find_by_crowd_login_method
|
152
|
+
self.class.find_by_crowd_login_method
|
153
|
+
end
|
108
154
|
end
|
109
155
|
end
|
110
156
|
end
|
data/test/session_test.rb
CHANGED
@@ -4,42 +4,43 @@ class SessionTest < ActiveSupport::TestCase
|
|
4
4
|
setup :setup_http_stubs, :setup_users
|
5
5
|
|
6
6
|
def setup_http_stubs
|
7
|
-
stub_request(:post, "http://example:bogus@localhost/crowd/console?username=ben").
|
8
|
-
with(:body => "<password><value>benrocks</value></password>",
|
7
|
+
stub_request(:post, "http://example:bogus@localhost/crowd/console/rest/usermanagement/latest/authentication?username=ben").
|
8
|
+
with(:body => "<password><value>benrocks</value></password>",
|
9
9
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml'}).
|
10
10
|
to_return(:status => 200, :body => %q[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><user name="ben" expand="attributes"><link rel="self" href="http://localhost/crowd/rest/usermanagement/latest/user?username=ben"/><first-name>Ben</first-name><last-name>Johnson</last-name><display-name>Rob Dimarco</display-name><email>ben@foo.com</email><password><link rel="edit" href="http://localhost/crowd/rest/usermanagement/latest/user/password?username=ben"/></password><active>true</active><attributes><link rel="self" href="http://localhost/crowd/rest/usermanagement/latest/user/attribute?username=ben"/></attributes></user>], :headers => {})
|
11
|
-
|
12
|
-
stub_request(:post, "http://example:bogus@localhost/crowd/console?username=ben").
|
13
|
-
with(:body => "<password><value>bogus</value></password>",
|
11
|
+
|
12
|
+
stub_request(:post, "http://example:bogus@localhost/crowd/console/rest/usermanagement/latest/authentication?username=ben").
|
13
|
+
with(:body => "<password><value>bogus</value></password>",
|
14
14
|
:headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml'}).
|
15
15
|
to_return(:status => 400, :body => %q[Incorrect], :headers => {})
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def setup_users
|
19
|
-
User.
|
19
|
+
u = User.find_or_create_by_crowd_login :crowd_login=>"ben", :email=>"foo@bar.com"
|
20
|
+
raise "Problem creating user...#{u.errors.inspect}" unless u.valid?
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
def test_use_crowd_rest_authentication
|
23
|
-
assert_not_nil User.
|
24
|
+
assert_not_nil User.find_by_crowd_login 'ben'
|
24
25
|
|
25
26
|
UserSession.crowd_base_url = "http://localhost/crowd/console"
|
26
27
|
UserSession.crowd_application_name = "example"
|
27
28
|
UserSession.crowd_application_password = "bogus"
|
28
|
-
|
29
|
-
session = UserSession.new(:
|
29
|
+
|
30
|
+
session = UserSession.new(:crowd_login => 'ben', :crowd_password => "benrocks")
|
30
31
|
|
31
32
|
assert session.save
|
32
33
|
end
|
33
34
|
|
34
35
|
def test_invalid_password
|
35
|
-
assert_not_nil User.
|
36
|
+
assert_not_nil User.find_by_crowd_login 'ben'
|
36
37
|
UserSession.crowd_base_url = "http://localhost/crowd/console"
|
37
38
|
UserSession.crowd_application_name = "example"
|
38
39
|
UserSession.crowd_application_password = "bogus"
|
39
|
-
|
40
|
-
session = UserSession.new(:
|
40
|
+
|
41
|
+
session = UserSession.new(:crowd_login => 'ben', :crowd_password => "bogus")
|
41
42
|
|
42
43
|
assert !session.save
|
43
|
-
assert_equal ["
|
44
|
+
assert_equal ["Crowd password is not valid"], session.errors.full_messages
|
44
45
|
end
|
45
46
|
end
|
data/test/test_helper.rb
CHANGED
@@ -32,15 +32,13 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
32
32
|
t.datetime :created_at
|
33
33
|
t.datetime :updated_at
|
34
34
|
t.integer :lock_version, :default => 0
|
35
|
-
t.string :login
|
36
|
-
t.string :crypted_password
|
37
|
-
t.string :password_salt
|
38
35
|
t.string :persistence_token
|
39
36
|
t.string :single_access_token
|
40
37
|
t.string :perishable_token
|
41
38
|
t.string :email
|
42
39
|
t.string :first_name
|
43
40
|
t.string :last_name
|
41
|
+
t.string :crowd_login
|
44
42
|
t.integer :login_count, :default => 0, :null => false
|
45
43
|
t.integer :failed_login_count, :default => 0, :null => false
|
46
44
|
t.datetime :last_request_at
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authlogic_crowd_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rob Di Marco
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-07 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
segments:
|
30
30
|
- 0
|
31
31
|
version: "0"
|
32
|
-
name: authlogic
|
33
32
|
version_requirements: *id001
|
33
|
+
name: authlogic
|
34
34
|
prerelease: false
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
type: :development
|
@@ -45,8 +45,8 @@ dependencies:
|
|
45
45
|
- 0
|
46
46
|
- 0
|
47
47
|
version: 1.0.0
|
48
|
-
name: bundler
|
49
48
|
version_requirements: *id002
|
49
|
+
name: bundler
|
50
50
|
prerelease: false
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
type: :development
|
@@ -61,8 +61,8 @@ dependencies:
|
|
61
61
|
- 5
|
62
62
|
- 2
|
63
63
|
version: 1.5.2
|
64
|
-
name: jeweler
|
65
64
|
version_requirements: *id003
|
65
|
+
name: jeweler
|
66
66
|
prerelease: false
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
type: :development
|
@@ -75,8 +75,8 @@ dependencies:
|
|
75
75
|
segments:
|
76
76
|
- 0
|
77
77
|
version: "0"
|
78
|
-
name: rcov
|
79
78
|
version_requirements: *id004
|
79
|
+
name: rcov
|
80
80
|
prerelease: false
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
type: :development
|
@@ -89,8 +89,8 @@ dependencies:
|
|
89
89
|
segments:
|
90
90
|
- 0
|
91
91
|
version: "0"
|
92
|
-
name: actionpack
|
93
92
|
version_requirements: *id005
|
93
|
+
name: actionpack
|
94
94
|
prerelease: false
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
type: :development
|
@@ -103,8 +103,8 @@ dependencies:
|
|
103
103
|
segments:
|
104
104
|
- 0
|
105
105
|
version: "0"
|
106
|
-
name: activerecord
|
107
106
|
version_requirements: *id006
|
107
|
+
name: activerecord
|
108
108
|
prerelease: false
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
type: :development
|
@@ -117,8 +117,8 @@ dependencies:
|
|
117
117
|
segments:
|
118
118
|
- 0
|
119
119
|
version: "0"
|
120
|
-
name: sqlite3
|
121
120
|
version_requirements: *id007
|
121
|
+
name: sqlite3
|
122
122
|
prerelease: false
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
type: :development
|
@@ -131,8 +131,8 @@ dependencies:
|
|
131
131
|
segments:
|
132
132
|
- 0
|
133
133
|
version: "0"
|
134
|
-
name: webmock
|
135
134
|
version_requirements: *id008
|
135
|
+
name: webmock
|
136
136
|
prerelease: false
|
137
137
|
description: Foo
|
138
138
|
email: rob.dimarco@416software.com
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
requirements: []
|
193
193
|
|
194
194
|
rubyforge_project:
|
195
|
-
rubygems_version: 1.
|
195
|
+
rubygems_version: 1.6.0
|
196
196
|
signing_key:
|
197
197
|
specification_version: 3
|
198
198
|
summary: An Authlogic plugin to connect with Atlassian Crowd REST APIs
|