casino_core-authenticator-activerecord 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@casino_core-authenticator-activerecord"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.15.8 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ casino_core-authenticator-activerecord (0.0.1)
5
+ activerecord (~> 3.2.12)
6
+ unix-crypt (~> 1.0.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.12)
12
+ activesupport (= 3.2.12)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.12)
15
+ activemodel (= 3.2.12)
16
+ activesupport (= 3.2.12)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.12)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ arel (3.0.2)
23
+ builder (3.0.4)
24
+ diff-lcs (1.1.3)
25
+ i18n (0.6.1)
26
+ multi_json (1.6.1)
27
+ rake (10.0.3)
28
+ rspec (2.12.0)
29
+ rspec-core (~> 2.12.0)
30
+ rspec-expectations (~> 2.12.0)
31
+ rspec-mocks (~> 2.12.0)
32
+ rspec-core (2.12.2)
33
+ rspec-expectations (2.12.1)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.12.1)
36
+ simplecov (0.7.1)
37
+ multi_json (~> 1.0)
38
+ simplecov-html (~> 0.7.1)
39
+ simplecov-html (0.7.1)
40
+ sqlite3 (1.3.7)
41
+ tzinfo (0.3.35)
42
+ unix-crypt (1.0.2)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ casino_core-authenticator-activerecord!
49
+ rake (~> 10.0)
50
+ rspec (~> 2.12)
51
+ simplecov (~> 0.7)
52
+ sqlite3 (~> 1.3.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Nils Caspar
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # casino_core-authenticator-activerecord [![Build Status](https://travis-ci.org/rbCAS/casino_core-authenticator-activerecord.png?branch=master)](https://travis-ci.org/rbCAS/casino_core-authenticator-activerecord)
2
+
3
+ Provides mechanism to use ActiveRecord as an authenticator for [CASinoCore](https://github.com/rbCAS/CASinoCore).
4
+
5
+ ActiveRecord supports many SQL databases such as MySQL, PostgreSQL, SQLite, ...
6
+
7
+ To use the ActiveRecord authenticator, configure it in your cas.yml:
8
+
9
+ authenticators:
10
+ my_company_sql:
11
+ authenticator: "ActiveRecord"
12
+ options:
13
+ connection:
14
+ adapter: "mysql"
15
+ host: "localhost"
16
+ username: "casino"
17
+ password: "secret"
18
+ database: "users"
19
+ table: "users"
20
+ username_column: "username"
21
+ password_column: "password"
22
+ extra_attributes:
23
+ email: "email_database_column"
24
+ fullname: "displayname_database_column"
25
+
26
+ ## Contributing to casino_core-authenticator-activerecord
27
+
28
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
29
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
30
+ * Fork the project.
31
+ * Start a feature/bugfix branch.
32
+ * Commit and push until you are happy with your contribution.
33
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
34
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
35
+
36
+ ## Copyright
37
+
38
+ Copyright (c) 2013 Nils Caspar. See LICENSE.txt
39
+ for further details.
40
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task :default => :spec
7
+
8
+ desc 'Run all specs'
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb']
11
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'casino_core/authenticator/activerecord/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'casino_core-authenticator-activerecord'
7
+ s.version = CASinoCore::Authenticator::ActiveRecord::VERSION
8
+ s.authors = ['Nils Caspar', 'Raffael Schmid']
9
+ s.email = ['ncaspar@me.com', 'raffael@yux.ch']
10
+ s.homepage = 'http://rbcas.org/'
11
+ s.license = 'MIT'
12
+ s.summary = 'Provides mechanism to use ActiveRecord as an authenticator for CASinoCore.'
13
+ s.description = 'This gem can be used to allow the CASinoCore backend to authenticate against an SQL server using ActiveRecord.'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_development_dependency 'rake', '~> 10.0'
21
+ s.add_development_dependency 'rspec', '~> 2.12'
22
+ s.add_development_dependency 'simplecov', '~> 0.7'
23
+ s.add_development_dependency 'sqlite3', '~> 1.3.7'
24
+
25
+ s.add_runtime_dependency 'activerecord', '~> 3.2.12'
26
+ s.add_runtime_dependency 'unix-crypt', '~> 1.0.2'
27
+ end
@@ -0,0 +1,2 @@
1
+ require 'casino_core/authenticator/activerecord/version'
2
+ require 'casino_core/authenticator/activerecord'
@@ -0,0 +1,45 @@
1
+ require 'active_record'
2
+ require 'unix_crypt'
3
+
4
+ class CASinoCore::Authenticator::ActiveRecord
5
+
6
+ # @param [Hash] options
7
+ def initialize(options)
8
+ @options = options
9
+ ::ActiveRecord::Base.establish_connection @options[:connection]
10
+
11
+ eval <<-END
12
+ class #{@options[:table].classify} < ActiveRecord::Base
13
+ end
14
+ END
15
+
16
+ @model = "#{self.class.to_s}::#{@options[:table].classify}".constantize
17
+ end
18
+
19
+ def validate(username, password)
20
+ user = @model.send("find_by_#{@options[:username_column]}!", username)
21
+ password_from_database = user.send(@options[:password_column])
22
+
23
+ if valid_password?(password, password_from_database)
24
+ { username: user.send(@options[:username_column]) }.merge(extra_attributes(user))
25
+ else
26
+ false
27
+ end
28
+
29
+ rescue ActiveRecord::RecordNotFound
30
+ false
31
+ end
32
+
33
+ private
34
+ def valid_password?(password, password_from_database)
35
+ UnixCrypt.valid?(password, password_from_database)
36
+ end
37
+
38
+ def extra_attributes(user)
39
+ attributes = {}
40
+ @options[:extra_attributes].each do |attribute_name, database_column|
41
+ attributes[attribute_name] = user.send(database_column)
42
+ end
43
+ attributes
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ module CASinoCore
2
+ class Authenticator
3
+ class ActiveRecord
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'casino_core/authenticator/activerecord'
3
+
4
+ describe CASinoCore::Authenticator::ActiveRecord do
5
+
6
+ let(:options) do
7
+ {
8
+ connection: {
9
+ adapter: 'sqlite3',
10
+ database: ':memory:'
11
+ },
12
+ table: 'users',
13
+ username_column: 'username',
14
+ password_column: 'password',
15
+ extra_attributes: {
16
+ email: 'mail_address'
17
+ }
18
+ }
19
+ end
20
+
21
+ before do
22
+
23
+ @authenticator = CASinoCore::Authenticator::ActiveRecord.new(options)
24
+
25
+ ActiveRecord::Migration.suppress_messages do
26
+ ActiveRecord::Schema.define do
27
+ create_table :users do |t|
28
+ t.string :username
29
+ t.string :password
30
+ t.string :mail_address
31
+ end
32
+ end
33
+ end
34
+
35
+ CASinoCore::Authenticator::ActiveRecord::User.create!(
36
+ username: 'test',
37
+ password: '$5$cegeasjoos$vPX5AwDqOTGocGjehr7k1IYp6Kt.U4FmMUa.1l6NrzD', # password: testpassword
38
+ mail_address: 'mail@example.org')
39
+ end
40
+
41
+ describe '#validate' do
42
+
43
+ context 'valid username' do
44
+ context 'valid password' do
45
+ it 'returns the username' do
46
+ @authenticator.validate('test', 'testpassword')[:username].should eq('test')
47
+ end
48
+
49
+ it 'returns the extra attributes' do
50
+ @authenticator.validate('test', 'testpassword')[:email].should eq('mail@example.org')
51
+ end
52
+ end
53
+
54
+ context 'invalid password' do
55
+ it 'returns false' do
56
+ @authenticator.validate('test', 'wrongpassword').should eq(false)
57
+ end
58
+ end
59
+ end
60
+
61
+ context 'invalid username' do
62
+ it 'returns false' do
63
+ @authenticator.validate('does-not-exist', 'testpassword').should eq(false)
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+
70
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter '/spec'
7
+ end
8
+
9
+ require 'rspec'
10
+ require 'casino_core-authenticator-activerecord'
11
+
12
+ # Requires supporting files with custom matchers and macros, etc,
13
+ # in ./support/ and its subdirectories.
14
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
15
+
16
+ RSpec.configure do |config|
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: casino_core-authenticator-activerecord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nils Caspar
9
+ - Raffael Schmid
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-02-19 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '10.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '10.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '2.12'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2.12'
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '0.7'
63
+ - !ruby/object:Gem::Dependency
64
+ name: sqlite3
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.7
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.7
79
+ - !ruby/object:Gem::Dependency
80
+ name: activerecord
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 3.2.12
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 3.2.12
95
+ - !ruby/object:Gem::Dependency
96
+ name: unix-crypt
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 1.0.2
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.2
111
+ description: This gem can be used to allow the CASinoCore backend to authenticate
112
+ against an SQL server using ActiveRecord.
113
+ email:
114
+ - ncaspar@me.com
115
+ - raffael@yux.ch
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - .gitignore
121
+ - .rvmrc
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - VERSION
128
+ - casino_core-authenticator-activerecord.gemspec
129
+ - lib/casino_core-authenticator-activerecord.rb
130
+ - lib/casino_core/authenticator/activerecord.rb
131
+ - lib/casino_core/authenticator/activerecord/version.rb
132
+ - spec/casino_core/authenticator/activerecord_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: http://rbcas.org/
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.24
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: Provides mechanism to use ActiveRecord as an authenticator for CASinoCore.
159
+ test_files:
160
+ - spec/casino_core/authenticator/activerecord_spec.rb
161
+ - spec/spec_helper.rb