casino 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/.powrc +4 -0
- data/.rspec +1 -0
- data/.rvmrc +48 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.txt +20 -0
- data/README.md +72 -0
- data/Rakefile +14 -0
- data/app/assets/images/rails.png +0 -0
- data/app/assets/javascripts/casino/index.js +15 -0
- data/app/assets/javascripts/casino/sessions.js.coffee +15 -0
- data/app/assets/stylesheets/casino/index.css.scss +28 -0
- data/app/controllers/casino/api/v1/tickets_controller.rb +48 -0
- data/app/controllers/casino/application_controller.rb +19 -0
- data/app/controllers/casino/proxy_tickets_controller.rb +9 -0
- data/app/controllers/casino/service_tickets_controller.rb +9 -0
- data/app/controllers/casino/sessions_controller.rb +23 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/casino/sessions_helper.rb +5 -0
- data/app/helpers/service_tickets_helper.rb +2 -0
- data/app/mailers/.gitkeep +0 -0
- data/app/models/.gitkeep +0 -0
- data/app/views/casino/service_tickets/validate.text.erb +2 -0
- data/app/views/casino/sessions/index.html.erb +43 -0
- data/app/views/casino/sessions/logout.html.erb +8 -0
- data/app/views/casino/sessions/new.html.erb +12 -0
- data/app/views/layouts/application.html.erb +18 -0
- data/casino.gemspec +29 -0
- data/config/.gitignore +3 -0
- data/config/initializers/inflections.rb +19 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/wrap_parameters.rb +9 -0
- data/config/initializers/yaml.rb +1 -0
- data/config/locales/en.yml +10 -0
- data/config/routes.rb +82 -0
- data/db/seeds.rb +7 -0
- data/doc/README_FOR_APP +2 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/casino.rb +6 -0
- data/lib/casino/engine.rb +7 -0
- data/lib/casino/listener.rb +25 -0
- data/lib/casino/listener/legacy_validator.rb +11 -0
- data/lib/casino/listener/login_credential_acceptor.rb +28 -0
- data/lib/casino/listener/login_credential_requestor.rb +16 -0
- data/lib/casino/listener/logout.rb +8 -0
- data/lib/casino/listener/proxy_ticket_provider.rb +11 -0
- data/lib/casino/listener/session_destroyer.rb +11 -0
- data/lib/casino/listener/session_overview.rb +11 -0
- data/lib/casino/listener/ticket_validator.rb +11 -0
- data/lib/casino/version.rb +3 -0
- data/lib/generators/casino/install_generator.rb +37 -0
- data/lib/generators/casino/templates/README +28 -0
- data/lib/generators/casino/templates/cas.yml +44 -0
- data/lib/generators/casino/templates/casino.css +3 -0
- data/lib/generators/casino/templates/casino.js +1 -0
- data/lib/generators/casino/templates/casino_core.rb +1 -0
- data/lib/generators/casino/templates/database.yml +25 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/login_tickets.rake +7 -0
- data/lib/tasks/service_tickets.rake +9 -0
- data/log/.gitkeep +0 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +25 -0
- data/public/favicon.ico +0 -0
- data/public/robots.txt +5 -0
- data/script/rails +8 -0
- data/spec/controllers/api/v1/tickets_controller_spec.rb +100 -0
- data/spec/controllers/listener/legacy_validator_spec.rb +22 -0
- data/spec/controllers/listener/login_credential_acceptor_spec.rb +62 -0
- data/spec/controllers/listener/login_credential_requestor_spec.rb +39 -0
- data/spec/controllers/listener/logout_spec.rb +21 -0
- data/spec/controllers/listener/proxy_ticket_provider_spec.rb +22 -0
- data/spec/controllers/listener/session_destroyer_spec.rb +25 -0
- data/spec/controllers/listener/session_overview_spec.rb +26 -0
- data/spec/controllers/listener/ticket_validator_spec.rb +22 -0
- data/spec/controllers/proxy_tickets_controller_spec.rb +25 -0
- data/spec/controllers/service_tickets_controller_spec.rb +25 -0
- data/spec/controllers/sessions_controller_spec.rb +52 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +14 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/cas.yml +29 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/casino_core.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/.gitkeep +0 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/.gitkeep +0 -0
- data/spec/support/sign_in.rb +11 -0
- data/vendor/assets/javascripts/.gitkeep +0 -0
- data/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +351 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'casino/listener'
|
2
|
+
|
3
|
+
class CASino::Listener::LoginCredentialRequestor < CASino::Listener
|
4
|
+
def user_not_logged_in(login_ticket)
|
5
|
+
assign(:login_ticket, login_ticket)
|
6
|
+
@controller.cookies.delete :tgt
|
7
|
+
end
|
8
|
+
|
9
|
+
def user_logged_in(url)
|
10
|
+
if url.nil?
|
11
|
+
@controller.redirect_to sessions_path
|
12
|
+
else
|
13
|
+
@controller.redirect_to url, status: :see_other
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'casino/listener'
|
2
|
+
|
3
|
+
class CASino::Listener::SessionOverview < CASino::Listener
|
4
|
+
def user_not_logged_in
|
5
|
+
@controller.redirect_to login_path
|
6
|
+
end
|
7
|
+
|
8
|
+
def ticket_granting_tickets_found(ticket_granting_tickets)
|
9
|
+
assign(:ticket_granting_tickets, ticket_granting_tickets)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'casino_core'
|
2
|
+
|
3
|
+
module Casino # CASino would lead to c_a_sino...
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def copy_initializer_file
|
8
|
+
copy_file 'casino_core.rb', 'config/initializers/casino_core.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_config_files
|
12
|
+
copy_file 'cas.yml', 'config/cas.yml'
|
13
|
+
copy_file 'database.yml', 'config/database.yml'
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert_assets_loader
|
17
|
+
insert_into_file 'app/assets/javascripts/application.js', :after => %r{//= require +['"]?jquery_ujs['"]?} do
|
18
|
+
"\n//= require casino"
|
19
|
+
end
|
20
|
+
insert_into_file "app/assets/stylesheets/application.css", :after => %r{\*= require_self} do
|
21
|
+
"\n *= require casino"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_engine_routes
|
26
|
+
route "mount CASino::Engine => '/', :as => 'CASino'"
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_index_html
|
30
|
+
remove_file 'public/index.html'
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_readme
|
34
|
+
readme 'README'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
The CASino Engine has been correctly installed in your Rails application.
|
4
|
+
|
5
|
+
1. Edit the configuration files:
|
6
|
+
|
7
|
+
- config/cas.yml
|
8
|
+
- config/database.yml
|
9
|
+
|
10
|
+
2. Edit or delete (to use the integrated) layout file:
|
11
|
+
|
12
|
+
- app/views/layouts/application.html.erb
|
13
|
+
|
14
|
+
3. Load the database schema
|
15
|
+
|
16
|
+
> bundle exec rake casino_core:db:schema:load
|
17
|
+
|
18
|
+
4. Launch the server
|
19
|
+
|
20
|
+
> bundle exec rails server
|
21
|
+
|
22
|
+
5. Open your browser
|
23
|
+
|
24
|
+
> open http://localhost:3000/
|
25
|
+
|
26
|
+
6. Enjoy!
|
27
|
+
|
28
|
+
===============================================================================
|
@@ -0,0 +1,44 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
login_ticket:
|
3
|
+
lifetime: 600
|
4
|
+
service_ticket:
|
5
|
+
lifetime_unconsumed: 300
|
6
|
+
lifetime_consumed: 86400
|
7
|
+
proxy_ticket:
|
8
|
+
lifetime_unconsumed: 300
|
9
|
+
lifetime_consumed: 86400
|
10
|
+
|
11
|
+
development:
|
12
|
+
<<: *defaults
|
13
|
+
authenticators:
|
14
|
+
static:
|
15
|
+
class: "CASinoCore::Authenticator::Static"
|
16
|
+
options:
|
17
|
+
users:
|
18
|
+
testuser:
|
19
|
+
password: "foobar123"
|
20
|
+
|
21
|
+
test:
|
22
|
+
<<: *defaults
|
23
|
+
authenticators:
|
24
|
+
static:
|
25
|
+
class: "CASinoCore::Authenticator::Static"
|
26
|
+
options:
|
27
|
+
users:
|
28
|
+
testuser:
|
29
|
+
password: "foobar123"
|
30
|
+
|
31
|
+
production:
|
32
|
+
<<: *defaults
|
33
|
+
authenticators:
|
34
|
+
my_company_ldap:
|
35
|
+
authenticator: "ldap"
|
36
|
+
options:
|
37
|
+
host: "localhost"
|
38
|
+
port: 12445
|
39
|
+
base: "dc=users,dc=example.com"
|
40
|
+
username_attribute: "uid"
|
41
|
+
encryption: "simple_tls"
|
42
|
+
extra_attributes:
|
43
|
+
email: "mail"
|
44
|
+
fullname: "displayname"
|
@@ -0,0 +1 @@
|
|
1
|
+
//=require casino
|
@@ -0,0 +1 @@
|
|
1
|
+
CASinoCore.setup Rails.env, application_root: Rails.root
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
data/lib/tasks/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :service_tickets do
|
2
|
+
desc 'Remove expired service tickets.'
|
3
|
+
task cleanup: :environment do
|
4
|
+
[:consumed, :unconsumed].each do |type|
|
5
|
+
rows_affected = ServiceTicket.send("cleanup_#{type}")
|
6
|
+
puts "Deleted #{rows_affected} #{type} service tickets."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/log/.gitkeep
ADDED
File without changes
|
data/public/404.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/public/422.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/public/500.html
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
data/public/favicon.ico
ADDED
File without changes
|
data/public/robots.txt
ADDED
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/casino/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CASino::API::V1::TicketsController do
|
4
|
+
|
5
|
+
describe "POST /cas/v1/tickets" do
|
6
|
+
context "with correct credentials" do
|
7
|
+
|
8
|
+
before do
|
9
|
+
CASinoCore::Processor::API::LoginCredentialAcceptor.any_instance.should_receive(:process) do
|
10
|
+
@controller.user_logged_in_via_api "TGT-long-string"
|
11
|
+
end
|
12
|
+
|
13
|
+
post :create, params: {username: 'valid', password: 'valid'}
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { response }
|
17
|
+
its(:response_code) { should eq 201 }
|
18
|
+
its(:location) { should eq 'http://test.host/cas/v1/tickets/TGT-long-string' }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with incorrect credentials" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
CASinoCore::Processor::API::LoginCredentialAcceptor.any_instance.should_receive(:process) do
|
25
|
+
@controller.invalid_login_credentials_via_api
|
26
|
+
end
|
27
|
+
|
28
|
+
post :create, params: {username: 'invalid', password: 'invalid'}
|
29
|
+
end
|
30
|
+
|
31
|
+
subject { response }
|
32
|
+
its(:response_code) { should eq 400 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "POST /cas/v1/tickets/{TGT id}" do
|
37
|
+
|
38
|
+
context "with a valid TGT" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
CASinoCore::Processor::API::ServiceTicketProvider.any_instance.should_receive(:process).with('TGT-valid', kind_of(Hash), request.user_agent) do |ticket, params|
|
42
|
+
params.should == controller.params
|
43
|
+
@controller.granted_service_ticket_via_api 'ST-1-VALIDSERVICETICKET'
|
44
|
+
end
|
45
|
+
post :update, id: 'TGT-valid', service: 'http://example.org/'
|
46
|
+
end
|
47
|
+
|
48
|
+
subject { response }
|
49
|
+
|
50
|
+
its(:response_code) { should eq 200 }
|
51
|
+
its(:body) { should eq 'ST-1-VALIDSERVICETICKET' }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with an invalid TGT" do
|
55
|
+
|
56
|
+
before do
|
57
|
+
CASinoCore::Processor::API::ServiceTicketProvider.any_instance.should_receive(:process).with('TGT-invalid', kind_of(Hash), request.user_agent) do |ticket, params|
|
58
|
+
params.should == controller.params
|
59
|
+
@controller.invalid_ticket_granting_ticket_via_api
|
60
|
+
end
|
61
|
+
post :update, id: 'TGT-invalid', service: 'http://example.org/'
|
62
|
+
end
|
63
|
+
|
64
|
+
subject { response }
|
65
|
+
|
66
|
+
its(:response_code) { should eq 400 }
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context "without a service" do
|
71
|
+
|
72
|
+
before do
|
73
|
+
CASinoCore::Processor::API::ServiceTicketProvider.any_instance.should_receive(:process).with('TGT-valid', kind_of(Hash), request.user_agent) do |ticket, params|
|
74
|
+
params.should == controller.params
|
75
|
+
@controller.no_service_provided_via_api
|
76
|
+
end
|
77
|
+
post :update, id: 'TGT-valid'
|
78
|
+
end
|
79
|
+
|
80
|
+
subject { response }
|
81
|
+
|
82
|
+
its(:response_code) { should eq 400 }
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "DELETE /cas/v1/tickets/TGT-fdsjfsdfjkalfewrihfdhfaie" do
|
88
|
+
before do
|
89
|
+
CASinoCore::Processor::API::Logout.any_instance.should_receive(:process).with('TGT-fdsjfsdfjkalfewrihfdhfaie', request.user_agent) do
|
90
|
+
@controller.user_logged_out_via_api
|
91
|
+
end
|
92
|
+
post :destroy, id: 'TGT-fdsjfsdfjkalfewrihfdhfaie'
|
93
|
+
end
|
94
|
+
|
95
|
+
subject { response }
|
96
|
+
|
97
|
+
its(:response_code) { should eq 200 }
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|