aaf-gumboot 1.0.0.pre.alpha.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/Gemfile +4 -0
- data/Guardfile +18 -0
- data/LICENSE +202 -0
- data/README.md +1069 -0
- data/Rakefile +8 -0
- data/aaf-gumboot.gemspec +42 -0
- data/lib/aaf-gumboot.rb +1 -0
- data/lib/gumboot.rb +5 -0
- data/lib/gumboot/shared_examples/anonymous_controller.rb +17 -0
- data/lib/gumboot/shared_examples/api_constraints.rb +29 -0
- data/lib/gumboot/shared_examples/api_controller.rb +206 -0
- data/lib/gumboot/shared_examples/api_subjects.rb +44 -0
- data/lib/gumboot/shared_examples/application_controller.rb +223 -0
- data/lib/gumboot/shared_examples/database_schema.rb +45 -0
- data/lib/gumboot/shared_examples/foreign_keys.rb +65 -0
- data/lib/gumboot/shared_examples/permissions.rb +45 -0
- data/lib/gumboot/shared_examples/roles.rb +15 -0
- data/lib/gumboot/shared_examples/subjects.rb +29 -0
- data/lib/gumboot/strap.rb +121 -0
- data/lib/gumboot/version.rb +3 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +3 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/api/api_controller.rb +78 -0
- data/spec/dummy/app/controllers/application_controller.rb +64 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/api_subject.rb +23 -0
- data/spec/dummy/app/models/api_subject_role.rb +6 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/permission.rb +7 -0
- data/spec/dummy/app/models/role.rb +11 -0
- data/spec/dummy/app/models/subject.rb +20 -0
- data/spec/dummy/app/models/subject_role.rb +6 -0
- data/spec/dummy/app/views/dynamic_errors/forbidden.html.erb +0 -0
- data/spec/dummy/app/views/dynamic_errors/unauthorized.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +18 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +32 -0
- data/spec/dummy/config/environments/production.rb +37 -0
- data/spec/dummy/config/environments/test.rb +33 -0
- data/spec/dummy/config/initializers/assets.rb +4 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/schema.rb +51 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/api_constraints.rb +16 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/factories/api_subjects.rb +20 -0
- data/spec/factories/permissions.rb +6 -0
- data/spec/factories/roles.rb +5 -0
- data/spec/factories/subjects.rb +24 -0
- data/spec/gumboot/api_constraints_spec.rb +18 -0
- data/spec/gumboot/api_controller_spec.rb +7 -0
- data/spec/gumboot/api_subjects_spec.rb +7 -0
- data/spec/gumboot/application_controller_spec.rb +7 -0
- data/spec/gumboot/foreign_keys_spec.rb +7 -0
- data/spec/gumboot/permissions_spec.rb +7 -0
- data/spec/gumboot/roles_spec.rb +7 -0
- data/spec/gumboot/subjects_spec.rb +7 -0
- data/spec/lib/gumboot/strap_spec.rb +330 -0
- data/spec/spec_helper.rb +45 -0
- metadata +387 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
Forbidden = Class.new(StandardError)
|
3
|
+
private_constant :Forbidden
|
4
|
+
rescue_from Forbidden, with: :forbidden
|
5
|
+
|
6
|
+
Unauthorized = Class.new(StandardError)
|
7
|
+
private_constant :Unauthorized
|
8
|
+
rescue_from Unauthorized, with: :unauthorized
|
9
|
+
|
10
|
+
protect_from_forgery with: :exception
|
11
|
+
before_action :ensure_authenticated
|
12
|
+
after_action :ensure_access_checked
|
13
|
+
|
14
|
+
def subject
|
15
|
+
subject = session[:subject_id] && Subject.find_by_id(session[:subject_id])
|
16
|
+
return nil unless subject.try(:functioning?)
|
17
|
+
@subject = subject
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def ensure_authenticated
|
23
|
+
return force_authentication unless session[:subject_id]
|
24
|
+
|
25
|
+
@subject = Subject.find_by(id: session[:subject_id])
|
26
|
+
raise(Unauthorized, 'Subject invalid') unless @subject
|
27
|
+
raise(Unauthorized, 'Subject not functional') unless @subject.functioning?
|
28
|
+
end
|
29
|
+
|
30
|
+
def ensure_access_checked
|
31
|
+
return if @access_checked
|
32
|
+
|
33
|
+
method = "#{self.class.name}##{params[:action]}"
|
34
|
+
raise("No access control performed by #{method}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_access!(action)
|
38
|
+
raise(Forbidden) unless subject.permits?(action)
|
39
|
+
@access_checked = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def public_action
|
43
|
+
@access_checked = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def unauthorized
|
47
|
+
reset_session
|
48
|
+
render 'dynamic_errors/unauthorized',
|
49
|
+
status: :unauthorized,
|
50
|
+
layout: 'application'
|
51
|
+
end
|
52
|
+
|
53
|
+
def forbidden
|
54
|
+
render 'dynamic_errors/forbidden',
|
55
|
+
status: :forbidden,
|
56
|
+
layout: 'application'
|
57
|
+
end
|
58
|
+
|
59
|
+
def force_authentication
|
60
|
+
session[:return_url] = request.url if request.get?
|
61
|
+
|
62
|
+
redirect_to('/auth/login')
|
63
|
+
end
|
64
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'accession'
|
2
|
+
|
3
|
+
class APISubject < ActiveRecord::Base
|
4
|
+
include Accession::Principal
|
5
|
+
|
6
|
+
has_many :api_subject_roles
|
7
|
+
has_many :roles, through: :api_subject_roles
|
8
|
+
|
9
|
+
valhammer
|
10
|
+
validates :x509_cn, format: { with: /\A[\w-]+\z/ }
|
11
|
+
|
12
|
+
def permissions
|
13
|
+
# This could be extended to gather permissions from
|
14
|
+
# other data sources providing input to api_subject identity
|
15
|
+
roles.joins(:permissions).pluck('permissions.value')
|
16
|
+
end
|
17
|
+
|
18
|
+
def functioning?
|
19
|
+
# more than enabled? could inform functioning?
|
20
|
+
# such as an administrative or AAF lock
|
21
|
+
enabled?
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Subject < ActiveRecord::Base
|
2
|
+
include Accession::Principal
|
3
|
+
|
4
|
+
has_many :subject_roles
|
5
|
+
has_many :roles, through: :subject_roles
|
6
|
+
|
7
|
+
valhammer
|
8
|
+
|
9
|
+
def permissions
|
10
|
+
# This could be extended to gather permissions from
|
11
|
+
# other data sources providing input to subject identity
|
12
|
+
roles.joins(:permissions).pluck('permissions.value')
|
13
|
+
end
|
14
|
+
|
15
|
+
def functioning?
|
16
|
+
# more than enabled? could inform functioning?
|
17
|
+
# such as an administrative or AAF lock
|
18
|
+
enabled?
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require 'active_record/railtie'
|
5
|
+
require 'action_controller/railtie'
|
6
|
+
require 'action_mailer/railtie'
|
7
|
+
require 'action_view/railtie'
|
8
|
+
require 'sprockets/railtie'
|
9
|
+
# require "rails/test_unit/railtie"
|
10
|
+
|
11
|
+
require 'valhammer'
|
12
|
+
|
13
|
+
Bundler.require(*Rails.groups)
|
14
|
+
|
15
|
+
module Dummy
|
16
|
+
class Application < Rails::Application
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = false
|
3
|
+
|
4
|
+
# Do not eager load code on boot.
|
5
|
+
config.eager_load = false
|
6
|
+
|
7
|
+
# Show full error reports and disable caching.
|
8
|
+
config.consider_all_requests_local = true
|
9
|
+
config.action_controller.perform_caching = false
|
10
|
+
|
11
|
+
# Don't care if the mailer can't send.
|
12
|
+
config.action_mailer.raise_delivery_errors = false
|
13
|
+
|
14
|
+
# Print deprecation notices to the Rails logger.
|
15
|
+
config.active_support.deprecation = :log
|
16
|
+
|
17
|
+
# Raise an error on page load if there are pending migrations.
|
18
|
+
config.active_record.migration_error = :page_load
|
19
|
+
|
20
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
21
|
+
# This option may cause significant delays in view rendering with a large
|
22
|
+
# number of complex assets.
|
23
|
+
config.assets.debug = true
|
24
|
+
|
25
|
+
# Adds additional error checking when serving assets at runtime.
|
26
|
+
# Checks for improperly declared sprockets dependencies.
|
27
|
+
# Raises helpful error messages.
|
28
|
+
config.assets.raise_runtime_errors = true
|
29
|
+
|
30
|
+
# Raises error for missing translations
|
31
|
+
# config.action_view.raise_on_missing_translations = true
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
|
4
|
+
# Eager load code on boot. This eager loads most of Rails and
|
5
|
+
# your application in memory, allowing both threaded web servers
|
6
|
+
# and those relying on copy on write to perform better.
|
7
|
+
# Rake tasks automatically ignore this option for performance.
|
8
|
+
config.eager_load = true
|
9
|
+
|
10
|
+
# Full error reports are disabled and caching is turned on.
|
11
|
+
config.consider_all_requests_local = false
|
12
|
+
config.action_controller.perform_caching = true
|
13
|
+
|
14
|
+
config.serve_static_assets = false
|
15
|
+
|
16
|
+
# Compress JavaScripts and CSS.
|
17
|
+
config.assets.js_compressor = :uglifier
|
18
|
+
# config.assets.css_compressor = :sass
|
19
|
+
|
20
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
21
|
+
config.assets.compile = false
|
22
|
+
|
23
|
+
# Generate digests for assets URLs.
|
24
|
+
config.assets.digest = true
|
25
|
+
|
26
|
+
config.log_level = :info
|
27
|
+
|
28
|
+
config.i18n.fallbacks = true
|
29
|
+
|
30
|
+
# Send deprecation notices to registered listeners.
|
31
|
+
config.active_support.deprecation = :notify
|
32
|
+
|
33
|
+
config.log_formatter = ::Logger::Formatter.new
|
34
|
+
|
35
|
+
# Do not dump schema after migrations.
|
36
|
+
config.active_record.dump_schema_after_migration = false
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
|
4
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
5
|
+
# just for the purpose of running a single test. If you are using a tool that
|
6
|
+
# preloads Rails for running tests, you may have to set it to true.
|
7
|
+
config.eager_load = false
|
8
|
+
|
9
|
+
# Configure static asset server for tests with Cache-Control for performance.
|
10
|
+
config.serve_static_assets = true
|
11
|
+
config.static_cache_control = 'public, max-age=3600'
|
12
|
+
|
13
|
+
# Show full error reports and disable caching.
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates.
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment.
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Print deprecation notices to the stderr.
|
29
|
+
config.active_support.deprecation = :stderr
|
30
|
+
|
31
|
+
# Raises error for missing translations
|
32
|
+
# config.action_view.raise_on_missing_translations = true
|
33
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format. Inflections
|
4
|
+
# are locale specific, and you may define rules for as many different
|
5
|
+
# locales as you wish. All of these examples are active by default:
|
6
|
+
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
7
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
8
|
+
# inflect.singular /^(ox)en/i, '\1'
|
9
|
+
# inflect.irregular 'person', 'people'
|
10
|
+
# inflect.uncountable %w( fish sheep )
|
11
|
+
# end
|
12
|
+
|
13
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
14
|
+
inflect.acronym 'API'
|
15
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
ActiveSupport.on_load(:action_controller) do
|
3
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
4
|
+
end
|
5
|
+
|
6
|
+
# To enable root element in JSON for ActiveRecord objects.
|
7
|
+
# ActiveSupport.on_load(:active_record) do
|
8
|
+
# self.include_root_in_json = true
|
9
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|