casino 1.3.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/README.md +1 -8
- data/Rakefile +0 -2
- data/app/assets/javascripts/casino/application.js +1 -0
- data/app/assets/javascripts/casino/index.js +0 -2
- data/app/assets/javascripts/casino/sessions.js +32 -0
- data/app/authenticators/casino/static_authenticator.rb +23 -0
- data/app/builders/casino/ticket_validation_response_builder.rb +84 -0
- data/app/controllers/casino/api/v1/tickets_controller.rb +7 -4
- data/app/controllers/casino/application_controller.rb +2 -3
- data/{lib/casino/listener/legacy_validator.rb → app/listeners/casino/legacy_validator_listener.rb} +2 -2
- data/app/listeners/casino/listener.rb +16 -0
- data/{lib/casino/listener/login_credential_acceptor.rb → app/listeners/casino/login_credential_acceptor_listener.rb} +2 -2
- data/{lib/casino/listener/login_credential_requestor.rb → app/listeners/casino/login_credential_requestor_listener.rb} +2 -2
- data/{lib/casino/listener/logout.rb → app/listeners/casino/logout_listener.rb} +2 -2
- data/{lib/casino/listener/other_sessions_destroyer.rb → app/listeners/casino/other_sessions_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/proxy_ticket_provider.rb → app/listeners/casino/proxy_ticket_provider_listener.rb} +2 -2
- data/{lib/casino/listener/second_factor_authentication_acceptor.rb → app/listeners/casino/second_factor_authentication_acceptor_listener.rb} +2 -2
- data/{lib/casino/listener/session_destroyer.rb → app/listeners/casino/session_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/session_overview.rb → app/listeners/casino/session_overview_listener.rb} +2 -2
- data/{lib/casino/listener/ticket_validator.rb → app/listeners/casino/ticket_validator_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_activator.rb → app/listeners/casino/two_factor_authenticator_activator_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_destroyer.rb → app/listeners/casino/two_factor_authenticator_destroyer_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_overview.rb → app/listeners/casino/two_factor_authenticator_overview_listener.rb} +2 -2
- data/{lib/casino/listener/two_factor_authenticator_registrator.rb → app/listeners/casino/two_factor_authenticator_registrator_listener.rb} +2 -2
- data/app/models/casino/login_ticket.rb +12 -0
- data/app/models/casino/proxy_granting_ticket.rb +8 -0
- data/app/models/casino/proxy_ticket.rb +25 -0
- data/app/models/casino/service_rule.rb +27 -0
- data/app/models/casino/service_ticket.rb +43 -0
- data/app/models/casino/service_ticket/single_sign_out_notifier.rb +44 -0
- data/app/models/casino/ticket_granting_ticket.rb +57 -0
- data/app/models/casino/two_factor_authenticator.rb +18 -0
- data/app/models/casino/user.rb +12 -0
- data/app/models/casino/validation_result.rb +5 -0
- data/app/processors/casino/api/login_credential_acceptor_processor.rb +46 -0
- data/app/processors/casino/api/logout_processor.rb +17 -0
- data/app/processors/casino/api/service_ticket_provider_processor.rb +69 -0
- data/app/processors/casino/legacy_validator_processor.rb +19 -0
- data/app/processors/casino/login_credential_acceptor_processor.rb +63 -0
- data/app/processors/casino/login_credential_requestor_processor.rb +66 -0
- data/app/processors/casino/logout_processor.rb +23 -0
- data/app/processors/casino/other_sessions_destroyer_processor.rb +26 -0
- data/app/processors/casino/processor.rb +5 -0
- data/app/processors/casino/processor_concern/authentication.rb +87 -0
- data/app/processors/casino/processor_concern/browser.rb +14 -0
- data/app/processors/casino/processor_concern/login_tickets.rb +28 -0
- data/app/processors/casino/processor_concern/proxy_granting_tickets.rb +43 -0
- data/app/processors/casino/processor_concern/proxy_tickets.rb +56 -0
- data/app/processors/casino/processor_concern/service_tickets.rb +50 -0
- data/app/processors/casino/processor_concern/ticket_granting_tickets.rb +65 -0
- data/app/processors/casino/processor_concern/tickets.rb +17 -0
- data/app/processors/casino/processor_concern/two_factor_authenticators.rb +22 -0
- data/app/processors/casino/proxy_ticket_provider_processor.rb +41 -0
- data/app/processors/casino/proxy_ticket_validator_processor.rb +22 -0
- data/app/processors/casino/second_factor_authentication_acceptor_processor.rb +45 -0
- data/app/processors/casino/service_ticket_validator_processor.rb +46 -0
- data/app/processors/casino/session_destroyer_processor.rb +25 -0
- data/app/processors/casino/session_overview_processor.rb +21 -0
- data/app/processors/casino/two_factor_authenticator_activator_processor.rb +41 -0
- data/app/processors/casino/two_factor_authenticator_destroyer_processor.rb +33 -0
- data/app/processors/casino/two_factor_authenticator_overview_processor.rb +20 -0
- data/app/processors/casino/two_factor_authenticator_registrator_processor.rb +24 -0
- data/app/views/casino/application/_footer.html.erb +1 -1
- data/app/views/casino/sessions/new.html.erb +2 -1
- data/app/views/casino/sessions/validate_otp.html.erb +1 -1
- data/app/views/casino/two_factor_authenticators/new.html.erb +2 -2
- data/app/views/layouts/application.html.erb +1 -1
- data/casino.gemspec +9 -4
- data/db/migrate/20130809135400_create_core_schema.rb +117 -0
- data/db/migrate/20130809135401_rename_base_models.rb +101 -0
- data/db/migrate/20131022110146_cleanup_indexes.rb +27 -0
- data/db/migrate/20131022110246_fix_long_index_names.rb +12 -0
- data/db/migrate/20131022110346_change_service_to_text.rb +6 -0
- data/lib/casino.rb +47 -3
- data/lib/casino/authenticator.rb +9 -0
- data/lib/casino/engine.rb +26 -0
- data/lib/casino/inflections.rb +7 -0
- data/lib/casino/tasks.rb +1 -0
- data/lib/casino/tasks/cleanup.rake +59 -0
- data/lib/casino/tasks/service_rule.rake +49 -0
- data/lib/casino/version.rb +1 -1
- data/lib/generators/casino/install/USAGE +13 -0
- data/lib/generators/casino/install/install_generator.rb +47 -0
- data/lib/generators/casino/{templates → install/templates}/README +3 -4
- data/lib/generators/casino/{templates → install/templates}/cas.yml +2 -2
- data/lib/generators/casino/{templates → install/templates}/casino_and_overrides.scss +0 -0
- data/lib/generators/casino/templates/casino_core.rb +1 -1
- data/spec/authenticator/base_spec.rb +13 -0
- data/spec/authenticator/static_spec.rb +42 -0
- data/spec/controllers/api/v1/tickets_controller_spec.rb +15 -15
- data/spec/controllers/listener/legacy_validator_spec.rb +1 -1
- data/spec/controllers/listener/login_credential_acceptor_spec.rb +1 -1
- data/spec/controllers/listener/login_credential_requestor_spec.rb +1 -1
- data/spec/controllers/listener/logout_spec.rb +1 -1
- data/spec/controllers/listener/other_sessions_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/proxy_ticket_provider_spec.rb +1 -1
- data/spec/controllers/listener/second_factor_authentication_acceptor_spec.rb +1 -1
- data/spec/controllers/listener/session_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/session_overview_spec.rb +1 -1
- data/spec/controllers/listener/ticket_validator_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_activator_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_destroyer_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_overview_spec.rb +1 -1
- data/spec/controllers/listener/two_factor_authenticator_registrator_spec.rb +1 -1
- data/spec/controllers/proxy_tickets_controller_spec.rb +4 -4
- data/spec/controllers/service_tickets_controller_spec.rb +4 -4
- data/spec/controllers/sessions_controller_spec.rb +15 -15
- data/spec/controllers/two_factor_authenticators_controller_spec.rb +6 -6
- data/spec/dummy/app/assets/stylesheets/casino_and_overrides.scss +13 -0
- data/spec/dummy/config/cas.yml +11 -11
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/db/migrate/20130910094259_create_base_models.casino.rb +95 -0
- data/spec/dummy/db/schema.rb +107 -0
- data/spec/model/login_ticket_spec.rb +23 -0
- data/spec/model/proxy_ticket_spec.rb +63 -0
- data/spec/model/service_rule_spec.rb +65 -0
- data/spec/model/service_ticket/single_sign_out_notifier_spec.rb +61 -0
- data/spec/model/service_ticket_spec.rb +124 -0
- data/spec/model/ticket_granting_ticket_spec.rb +204 -0
- data/spec/model/two_factor_authenticator_spec.rb +31 -0
- data/spec/processor/api/login_credential_acceptor_spec.rb +52 -0
- data/spec/processor/api/logout_spec.rb +34 -0
- data/spec/processor/api/service_ticket_provider_spec.rb +61 -0
- data/spec/processor/legacy_validator_spec.rb +78 -0
- data/spec/processor/login_credential_acceptor_spec.rb +164 -0
- data/spec/processor/login_credential_requestor_spec.rb +135 -0
- data/spec/processor/logout_other_sessions_spec.rb +53 -0
- data/spec/processor/logout_spec.rb +72 -0
- data/spec/processor/processor_concern/service_tickets_spec.rb +49 -0
- data/spec/processor/proxy_ticket_provider_spec.rb +66 -0
- data/spec/processor/proxy_ticket_validator_spec.rb +65 -0
- data/spec/processor/second_factor_authenticaton_acceptor_spec.rb +94 -0
- data/spec/processor/session_destroyer_spec.rb +75 -0
- data/spec/processor/session_overview_spec.rb +49 -0
- data/spec/processor/ticket_validator_spec.rb +199 -0
- data/spec/processor/two_factor_authenticator_activator_spec.rb +122 -0
- data/spec/processor/two_factor_authenticator_destroyer_spec.rb +71 -0
- data/spec/processor/two_factor_authenticator_overview_spec.rb +56 -0
- data/spec/processor/two_factor_authenticator_registrator_spec.rb +48 -0
- data/spec/spec_helper.rb +8 -19
- data/spec/support/casino.rb +12 -0
- data/spec/support/factories/login_ticket_factory.rb +16 -0
- data/spec/support/factories/proxy_granting_ticket_factory.rb +16 -0
- data/spec/support/factories/proxy_ticket_factory.rb +17 -0
- data/spec/support/factories/service_rule_factory.rb +16 -0
- data/spec/support/factories/service_ticket_factory.rb +17 -0
- data/spec/support/factories/ticket_granting_ticket_factory.rb +15 -0
- data/spec/support/factories/two_factor_authenticator_factory.rb +16 -0
- data/spec/support/factories/user_factory.rb +11 -0
- data/spec/support/rspec.rb +8 -0
- data/spec/support/sqlite3.rb +4 -0
- metadata +284 -48
- metadata.gz.sig +2 -0
- data/.powrc +0 -4
- data/Gemfile.lock +0 -149
- data/app/assets/javascripts/casino/application.js.coffee +0 -5
- data/app/assets/javascripts/casino/sessions.js.coffee +0 -15
- data/config/initializers/frontend_config.rb +0 -9
- data/config/initializers/inflections.rb +0 -19
- data/config/initializers/yaml.rb +0 -1
- data/lib/casino/listener.rb +0 -31
- data/lib/generators/casino/install_generator.rb +0 -35
- data/spec/dummy/config/initializers/casino_core.rb +0 -1
@@ -0,0 +1,101 @@
|
|
1
|
+
class RenameBaseModels < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
# Login Tickets
|
4
|
+
rename_table :login_tickets, :casino_login_tickets
|
5
|
+
unless index_exists?(:casino_login_tickets, :ticket)
|
6
|
+
add_index :casino_login_tickets, :ticket, :unique => true
|
7
|
+
end
|
8
|
+
|
9
|
+
# Proxy Granting Tickets
|
10
|
+
rename_table :proxy_granting_tickets, :casino_proxy_granting_tickets
|
11
|
+
unless index_exists?(:casino_proxy_granting_tickets, :ticket)
|
12
|
+
add_index :casino_proxy_granting_tickets, :ticket, :unique => true
|
13
|
+
end
|
14
|
+
unless index_exists?(:casino_proxy_granting_tickets, :iou)
|
15
|
+
add_index :casino_proxy_granting_tickets, :iou, :unique => true
|
16
|
+
end
|
17
|
+
unless index_exists?(:casino_proxy_granting_tickets, :name => "index_casino_proxy_granting_tickets_on_granter")
|
18
|
+
# Uses a custom index name because the generated one exceeds the size limit
|
19
|
+
add_index :casino_proxy_granting_tickets, [:granter_type, :granter_id], :name => "index_casino_proxy_granting_tickets_on_granter", :unique => true
|
20
|
+
end
|
21
|
+
|
22
|
+
# Proxy Tickets
|
23
|
+
rename_table :proxy_tickets, :casino_proxy_tickets
|
24
|
+
unless index_exists?(:casino_proxy_tickets, :ticket)
|
25
|
+
add_index :casino_proxy_tickets, :ticket, :unique => true
|
26
|
+
end
|
27
|
+
unless index_exists?(:casino_proxy_tickets, :proxy_granting_ticket_id)
|
28
|
+
add_index :casino_proxy_tickets, :proxy_granting_ticket_id
|
29
|
+
end
|
30
|
+
|
31
|
+
# Service Rules
|
32
|
+
rename_table :service_rules, :casino_service_rules
|
33
|
+
unless index_exists?(:casino_service_rules, :url)
|
34
|
+
add_index :casino_service_rules, :url, :unique => true
|
35
|
+
end
|
36
|
+
|
37
|
+
# Service Tickets
|
38
|
+
rename_table :service_tickets, :casino_service_tickets
|
39
|
+
unless index_exists?(:casino_service_tickets, :ticket)
|
40
|
+
add_index :casino_service_tickets, :ticket, :unique => true
|
41
|
+
end
|
42
|
+
unless index_exists?(:casino_service_tickets, :ticket_granting_ticket_id)
|
43
|
+
add_index :casino_service_tickets, :ticket_granting_ticket_id
|
44
|
+
end
|
45
|
+
|
46
|
+
# Ticket Granting Tickets
|
47
|
+
rename_table :ticket_granting_tickets, :casino_ticket_granting_tickets
|
48
|
+
unless index_exists?(:casino_ticket_granting_tickets, :ticket)
|
49
|
+
add_index :casino_ticket_granting_tickets, :ticket, :unique => true
|
50
|
+
end
|
51
|
+
|
52
|
+
# Two-Factor Authenticators
|
53
|
+
rename_table :two_factor_authenticators, :casino_two_factor_authenticators
|
54
|
+
unless index_exists?(:casino_two_factor_authenticators, :user_id)
|
55
|
+
add_index :casino_two_factor_authenticators, :user_id
|
56
|
+
end
|
57
|
+
|
58
|
+
# Users
|
59
|
+
rename_table :users, :casino_users
|
60
|
+
unless index_exists?(:casino_users, [:authenticator, :username])
|
61
|
+
add_index :casino_users, [:authenticator, :username], :unique => true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def down
|
66
|
+
remove_index :casino_login_tickets, :ticket
|
67
|
+
drop_table :casino_login_tickets
|
68
|
+
|
69
|
+
# Proxy Granting Tickets
|
70
|
+
remove_index :casino_proxy_granting_tickets, :ticket, :unique => true
|
71
|
+
remove_index :casino_proxy_granting_tickets, :iou, :unique => true
|
72
|
+
remove_index :casino_proxy_granting_tickets, [:granter_type, :granter_id], :name => "index_casino_proxy_granting_tickets_on_granter", :unique => true
|
73
|
+
drop_table :casino_proxy_granting_tickets
|
74
|
+
|
75
|
+
# Proxy Tickets
|
76
|
+
remove_index :casino_proxy_tickets, :ticket, :unique => true
|
77
|
+
remove_index :casino_proxy_tickets, :proxy_granting_ticket_id
|
78
|
+
drop_table :casino_proxy_tickets
|
79
|
+
|
80
|
+
# Service Rules
|
81
|
+
remove_index :casino_service_rules, :url, :unique => true
|
82
|
+
drop_table :casino_service_rules
|
83
|
+
|
84
|
+
# Service Tickets
|
85
|
+
remove_index :casino_service_tickets, :ticket, :unique => true
|
86
|
+
remove_index :casino_service_tickets, :ticket_granting_ticket_id
|
87
|
+
drop_table :casino_service_tickets
|
88
|
+
|
89
|
+
# Ticket Granting Tickets
|
90
|
+
remove_index :casino_ticket_granting_tickets, :ticket, :unique => true
|
91
|
+
drop_table :casino_ticket_granting_tickets
|
92
|
+
|
93
|
+
# Two-Factor Authenticators
|
94
|
+
remove_index :casino_two_factor_authenticators, :user_id
|
95
|
+
drop_table :casino_two_factor_authenticators
|
96
|
+
|
97
|
+
# Users
|
98
|
+
remove_index :casino_users, [:authenticator, :username], :unique => true
|
99
|
+
drop_table :casino_users
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CleanupIndexes < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
# delete some leftovers in migrated CASino 1.x installations
|
4
|
+
remove_deprecated_index_if_exists :login_tickets, [:ticket]
|
5
|
+
remove_deprecated_index_if_exists :proxy_granting_tickets, [:granter_type, :granter_id]
|
6
|
+
remove_deprecated_index_if_exists :proxy_granting_tickets, [:iou]
|
7
|
+
remove_deprecated_index_if_exists :proxy_tickets, [:proxy_granting_ticket_id]
|
8
|
+
remove_deprecated_index_if_exists :proxy_tickets, [:ticket]
|
9
|
+
remove_deprecated_index_if_exists :service_rules, [:url]
|
10
|
+
remove_deprecated_index_if_exists :service_tickets, [:ticket]
|
11
|
+
remove_deprecated_index_if_exists :service_tickets, [:ticket_granting_ticket_id]
|
12
|
+
remove_deprecated_index_if_exists :ticket_granting_tickets, [:ticket]
|
13
|
+
remove_deprecated_index_if_exists :two_factor_authenticators, [:user_id]
|
14
|
+
remove_deprecated_index_if_exists :users, [:authenticator, :username]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def remove_deprecated_index_if_exists(old_table_name, column_names)
|
19
|
+
table_name = :"casino_#{old_table_name}"
|
20
|
+
index_name = :"index_#{old_table_name}_on_#{column_names.join('_and_')}"
|
21
|
+
if index_name_exists?(table_name, index_name, false)
|
22
|
+
remove_index table_name, name: index_name
|
23
|
+
else
|
24
|
+
puts "index #{index_name} on #{table_name} not found"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class FixLongIndexNames < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
# Long names prevent us from doing some migrations, because the resulting
|
4
|
+
# temporary index names would be longer than 64 characters:
|
5
|
+
# Index name 'temp_index_altered_casino_proxy_tickets_on_proxy_granting_ticket_id' on table
|
6
|
+
# 'altered_casino_proxy_tickets' is too long; the limit is 64 characters
|
7
|
+
remove_index :casino_service_tickets, :ticket_granting_ticket_id
|
8
|
+
remove_index :casino_proxy_tickets, :proxy_granting_ticket_id
|
9
|
+
add_index :casino_service_tickets, :ticket_granting_ticket_id, name: 'casino_service_tickets_on_tgt_id'
|
10
|
+
add_index :casino_proxy_tickets, :proxy_granting_ticket_id, name: 'casino_proxy_tickets_on_pgt_id'
|
11
|
+
end
|
12
|
+
end
|
data/lib/casino.rb
CHANGED
@@ -1,6 +1,50 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/configurable'
|
2
2
|
require 'casino/engine'
|
3
3
|
|
4
4
|
module CASino
|
5
|
-
|
6
|
-
|
5
|
+
include ActiveSupport::Configurable
|
6
|
+
|
7
|
+
defaults = {
|
8
|
+
authenticators: HashWithIndifferentAccess.new,
|
9
|
+
logger: Rails.logger,
|
10
|
+
frontend: HashWithIndifferentAccess.new(
|
11
|
+
sso_name: 'CASino',
|
12
|
+
footer_text: 'Powered by <a href="http://rbcas.com/">CASino</a>'
|
13
|
+
),
|
14
|
+
implementors: HashWithIndifferentAccess.new(
|
15
|
+
login_ticket: nil,
|
16
|
+
proxy_granting_ticket: nil,
|
17
|
+
proxy_ticket: nil,
|
18
|
+
service_rule: nil,
|
19
|
+
service_ticket: nil,
|
20
|
+
ticket_granting_ticket: nil,
|
21
|
+
two_factor_authenticator: nil,
|
22
|
+
user: nil
|
23
|
+
),
|
24
|
+
login_ticket: {
|
25
|
+
lifetime: 600
|
26
|
+
},
|
27
|
+
ticket_granting_ticket: {
|
28
|
+
lifetime: 86400,
|
29
|
+
lifetime_long_term: 864000
|
30
|
+
},
|
31
|
+
service_ticket: {
|
32
|
+
lifetime_unconsumed: 300,
|
33
|
+
lifetime_consumed: 86400,
|
34
|
+
single_sign_out_notification: {
|
35
|
+
timeout: 5
|
36
|
+
}
|
37
|
+
},
|
38
|
+
proxy_ticket: {
|
39
|
+
lifetime_unconsumed: 300,
|
40
|
+
lifetime_consumed: 86400
|
41
|
+
},
|
42
|
+
two_factor_authenticator: {
|
43
|
+
timeout: 180,
|
44
|
+
lifetime_inactive: 300,
|
45
|
+
drift: 30
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
self.config.merge! defaults.deep_dup
|
50
|
+
end
|
data/lib/casino/engine.rb
CHANGED
@@ -1,7 +1,33 @@
|
|
1
1
|
require 'casino'
|
2
|
+
require 'casino/inflections'
|
2
3
|
|
3
4
|
module CASino
|
4
5
|
class Engine < Rails::Engine
|
5
6
|
isolate_namespace CASino
|
7
|
+
|
8
|
+
rake_tasks { require 'casino/tasks' }
|
9
|
+
|
10
|
+
initializer :yaml_configuration do |app|
|
11
|
+
apply_yaml_config load_file('config/cas.yml')
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def apply_yaml_config(yaml)
|
16
|
+
cfg = (YAML.load(ERB.new(yaml).result)||{}).fetch(Rails.env, {})
|
17
|
+
cfg.each do |k,v|
|
18
|
+
value = if v.is_a? Hash
|
19
|
+
CASino.config.fetch(k.to_sym,{}).merge(v.symbolize_keys)
|
20
|
+
else
|
21
|
+
v
|
22
|
+
end
|
23
|
+
CASino.config.send("#{k}=", value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_file(filename)
|
28
|
+
fullpath = File.join(Rails.root, filename)
|
29
|
+
IO.read(fullpath) rescue ''
|
30
|
+
end
|
31
|
+
|
6
32
|
end
|
7
33
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# This inflector acronym definition needs to happen as soon as possible because
|
2
|
+
# the Railtie is going to declare a table_name_suffix based upon the name of the
|
3
|
+
# Railtie. Without this definition, the Railtie would use 'ca_s_ino'
|
4
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
5
|
+
inflect.acronym 'CAS'
|
6
|
+
inflect.acronym 'CASino'
|
7
|
+
end
|
data/lib/casino/tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'logger'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
namespace :casino do
|
6
|
+
namespace :cleanup do
|
7
|
+
desc 'Remove expired service tickets.'
|
8
|
+
task service_tickets: :environment do
|
9
|
+
[:consumed, :unconsumed].each do |type|
|
10
|
+
rows_affected = CASino::ServiceTicket.send("cleanup_#{type}")
|
11
|
+
if rows_affected.respond_to? :length
|
12
|
+
rows_affected = rows_affected.length
|
13
|
+
end
|
14
|
+
puts "Deleted #{rows_affected} #{type} service tickets."
|
15
|
+
end
|
16
|
+
rows_affected = CASino::ServiceTicket.cleanup_consumed_hard
|
17
|
+
puts "Force deleted #{rows_affected} consumed service tickets."
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Remove expired proxy tickets.'
|
21
|
+
task proxy_tickets: :environment do
|
22
|
+
[:consumed, :unconsumed].each do |type|
|
23
|
+
rows_affected = CASino::ProxyTicket.send("cleanup_#{type}").length
|
24
|
+
puts "Deleted #{rows_affected} #{type} proxy tickets."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Remove expired login tickets.'
|
29
|
+
task login_tickets: :environment do
|
30
|
+
rows_affected = CASino::LoginTicket.cleanup
|
31
|
+
puts "Deleted #{rows_affected} login tickets."
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Remove expired inactive two-factor authenticators.'
|
35
|
+
task two_factor_authenticators: :environment do
|
36
|
+
rows_affected = CASino::TwoFactorAuthenticator.cleanup
|
37
|
+
puts "Deleted #{rows_affected} inactive two-factor authenticators."
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Remove expired ticket-granting tickets.'
|
41
|
+
task ticket_granting_tickets: :environment do
|
42
|
+
rows_affected = CASino::TicketGrantingTicket.cleanup.length
|
43
|
+
puts "Deleted #{rows_affected} ticket-granting tickets."
|
44
|
+
end
|
45
|
+
|
46
|
+
task :acquire_lock do
|
47
|
+
$cleanup_lock = File.open('tmp/cleanup.lock', File::RDWR | File::CREAT, 0644)
|
48
|
+
lock_aquired = $cleanup_lock.flock(File::LOCK_NB | File::LOCK_EX)
|
49
|
+
if lock_aquired === false
|
50
|
+
$stderr.puts 'Could not acquire lock, other cleanup task already running?'
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'Perform all cleanup tasks.'
|
56
|
+
task all: [:acquire_lock, :ticket_granting_tickets, :service_tickets, :proxy_tickets, :login_tickets, :two_factor_authenticators] do
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
|
3
|
+
namespace :casino do
|
4
|
+
namespace :service_rule do
|
5
|
+
|
6
|
+
desc 'Add a service rule (prefix the url parameter with "regex:" to add a regular expression)'
|
7
|
+
task :add, [:name, :url] => :environment do |task, args|
|
8
|
+
service_rule = CASino::ServiceRule.new name: args[:name]
|
9
|
+
match = /^regex:(.*)/.match(args[:url])
|
10
|
+
if match.nil?
|
11
|
+
service_rule.url = clean_service_url(args[:url])
|
12
|
+
else
|
13
|
+
service_rule.url = match[1]
|
14
|
+
service_rule.regex = true
|
15
|
+
end
|
16
|
+
if !service_rule.save
|
17
|
+
fail service_rule.errors.full_messages.join("\n")
|
18
|
+
elsif service_rule.regex && service_rule.url[0] != '^'
|
19
|
+
puts 'Warning: Potentially unsafe regex! Use ^ to match the beginning of the URL. Example: ^https://'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Remove a servcice rule.'
|
24
|
+
task :delete, [:id] => :environment do |task, args|
|
25
|
+
CASino::ServiceRule.find(args[:id]).delete
|
26
|
+
puts "Successfully deleted service rule ##{args[:id]}."
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Delete all servcice rules.'
|
30
|
+
task :flush => :environment do |task, args|
|
31
|
+
CASino::ServiceRule.delete_all
|
32
|
+
puts 'Successfully deleted all service rules.'
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'List all service rules.'
|
36
|
+
task list: :environment do
|
37
|
+
table = Terminal::Table.new :headings => ['Enabled', 'ID', 'Name', 'URL'] do |t|
|
38
|
+
CASino::ServiceRule.all.each do |service_rule|
|
39
|
+
url = service_rule.url
|
40
|
+
if service_rule.regex?
|
41
|
+
url += " (Regex)"
|
42
|
+
end
|
43
|
+
t.add_row [service_rule.enabled, service_rule.id, service_rule.name, url]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
puts table
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/casino/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
CASino installation generator
|
2
|
+
|
3
|
+
Description:
|
4
|
+
The 'casino:install' command installs the CASino Rails Engine into your
|
5
|
+
Rails application.
|
6
|
+
|
7
|
+
Example:
|
8
|
+
rails g casino:install
|
9
|
+
|
10
|
+
This generates a few files inside your application that are required for
|
11
|
+
CASino to work properly.
|
12
|
+
|
13
|
+
See http://casino.rbcas.com for more information.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CASino
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
# Explicit namespace needed for proper inflection.
|
6
|
+
# Thor::Group does not use ActiveSupport's Inflector when programmatically
|
7
|
+
# generating the namespace, so this would be to "c_a_sino" otherwise.
|
8
|
+
namespace 'casino:install'
|
9
|
+
|
10
|
+
class_option :migration,
|
11
|
+
desc: 'Skip generating migrations',
|
12
|
+
type: :boolean,
|
13
|
+
default: true
|
14
|
+
|
15
|
+
class_option :config_files,
|
16
|
+
desc: 'Install default config files',
|
17
|
+
type: :boolean,
|
18
|
+
default: true
|
19
|
+
|
20
|
+
def install_migrations
|
21
|
+
return unless options['migration']
|
22
|
+
|
23
|
+
rake 'casino:install:migrations'
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_config_files
|
27
|
+
return unless options['config_files']
|
28
|
+
|
29
|
+
copy_file 'cas.yml', 'config/cas.yml'
|
30
|
+
copy_file 'casino_and_overrides.scss', 'app/assets/stylesheets/casino_and_overrides.scss'
|
31
|
+
end
|
32
|
+
|
33
|
+
def insert_assets_loader
|
34
|
+
insert_into_file 'app/assets/javascripts/application.js', :after => %r{//= require +['"]?jquery_ujs['"]?} do
|
35
|
+
"\n//= require casino"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def insert_engine_routes
|
40
|
+
route "mount CASino::Engine => '/', :as => 'casino'"
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_readme
|
44
|
+
readme 'README'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|