aker-rails 2.0.3 → 3.0.1

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/CHANGELOG.md CHANGED
@@ -1,19 +1,7 @@
1
1
  Aker-Rails History
2
2
  ==================
3
3
 
4
- 2.0.3
5
- -----
6
-
7
- ### Fixes
8
-
9
- - CSRF token verification in Rails >= 2.3.11 is now properly handled (#4).
10
-
11
- ### Development
12
-
13
- - Added missing LICENSE. Aker-Rails is made available under the MIT
14
- license.
15
-
16
- 2.0.2
4
+ 3.0.1
17
5
  -----
18
6
 
19
7
  ### Development
@@ -23,23 +11,19 @@ Aker-Rails History
23
11
  renaming of the main project.
24
12
  - Switch integration test suite from Celerity to Mechanize. (#3931)
25
13
  This eliminates the JRuby dependency for integration testing.
14
+ - Fixed: non-form UI modes can have their middleware correctly applied
15
+ (#1). This requires a rearrangement of your application's
16
+ configuration code; see the README for details.
26
17
 
27
18
  Bcsec-Rails History
28
19
  ===================
29
20
 
30
- 2.0.1
21
+ 3.0.0
31
22
  -----
32
23
 
33
- ### Fixed
34
-
35
- - The bcsec middleware is no longer appended to the stack multiple
36
- times when class reloading is active. (#4486)
37
-
38
- ### Development
24
+ ### Features
39
25
 
40
- - Use bundler 1.0. (#3930)
41
- - CI builds use most-recent-available gems for all dependencies,
42
- including prerelease versions of bcsec. (#4422, #4427)
26
+ - Rails 3.0 support
43
27
 
44
28
  2.0.0
45
29
  -----
data/README.md CHANGED
@@ -1,19 +1,26 @@
1
1
  Aker-Rails
2
- ===========
2
+ ==========
3
3
 
4
4
  `aker-rails` is the Rails plugin for Aker 3.0 and later. It is a
5
5
  thin wrapper around Aker's rack support.
6
6
 
7
7
  There are separate plugins for Rails 3.x and Rails 2.3.x. You're
8
- looking at the version for **Rails 2.3.x**. The version for Rails 3.x
9
- has a version number with major version 3.
8
+ looking at the version for **Rails 3.x**. The version for Rails 2.3.x
9
+ has a version number with major version 2.
10
+
11
+ Reader's note: this README uses [YARD][] markup to provide links to
12
+ Aker-Rails' API documentation. If you aren't already, consider reading it
13
+ on [rubydoc.info][] so that the links will be followable.
14
+
15
+ [YARD]: http://yardoc.org/
16
+ [rubydoc.info]: http://rubydoc.info/github/NUBIC/aker-rails/rails3/file/README.md
10
17
 
11
18
  Setup
12
19
  -----
13
20
 
14
21
  ### Prerequisites
15
22
 
16
- `aker-rails` requires Rails ~> 2.3.5.
23
+ `aker-rails` requires Rails ~> 3.0.
17
24
 
18
25
  Since `aker-rails` is just a thin wrapper, you'll want to be familiar
19
26
  with [Aker][] before you get started.
@@ -22,40 +29,25 @@ with [Aker][] before you get started.
22
29
 
23
30
  ### Get the gem
24
31
 
25
- `aker-rails` is a gem plugin. In order to use it, either install the
26
- gem at the system level or (better) include it in your bundler-using
27
- application's Gemfile.
28
-
29
- #### Okay
30
-
31
- !!!plain
32
- $ gem install aker-rails
33
-
34
- #### Better
35
-
36
- # in your Gemfile
37
- gem 'aker-rails', '~> 2.0'
32
+ `aker-rails` is a gem plugin. In order to use it, include it in your
33
+ application's Gemfile:
38
34
 
39
- ### Add it to the application
35
+ gem 'aker-rails'
40
36
 
41
- Next, configure the gem into your Rails application's environment.
42
- (This is necessary for gem plugins even if you are using bundler.)
37
+ Between this and the `Bundler.require` that most Rails 3 applications do
38
+ as part of their initialization process, that's all you usually need to
39
+ do to get aker and aker-rails loaded in your Rails application.
43
40
 
44
- # In config/environment.rb's initializer block
45
- config.gem "aker-rails", :lib => 'aker/rails', :version => '~> 2.0'
41
+ ### Add a global configuration for Aker
46
42
 
47
- ### Add an initializer for aker
48
-
49
- Put your global configuration in an initializer. By _global
43
+ Put your global configuration `config/application.rb`. By _global
50
44
  configuration_ I mean the parts that are the same no matter which
51
- environment you are using, like the portal name and the modes. (N.b.:
52
- You have to put it in an initializer — if you just put it at the
53
- end of `config/environment.rb` it won't work.)
45
+ environment you are using, like the portal name and the modes.
54
46
 
55
- # In config/initializers/aker.rb
56
- Aker.configure do
47
+ # In config/application.rb, inside the Application subclass definition
48
+ config.aker do
57
49
  # The authentication protocol to use for interactive access.
58
- # `:form` is the default.
50
+ # :form is the default.
59
51
  ui_mode :form
60
52
 
61
53
  # The authentication protocol(s) to use for non-interactive
@@ -66,8 +58,12 @@ end of `config/environment.rb` it won't work.)
66
58
  portal :ENU
67
59
  end
68
60
 
61
+ (Migration note: this differs from the Rails 2.3 version of this
62
+ plugin. *Aker configuration should not happen in a Rails 3
63
+ initializer.*)
64
+
69
65
  For more information on the configuration syntax and options, see the
70
- aker API documentation for {Aker::Configuration}.
66
+ aker API documentation for `Aker::Configuration`.
71
67
 
72
68
  ### Add per-environment configurations
73
69
 
@@ -78,20 +74,23 @@ visible from your workstation. This means that the `authorities` line
78
74
  will be env-specific.
79
75
 
80
76
  # In config/environments/production.rb, for example
81
- config.after_initialize do
82
- Aker.configure do
83
- # The authorities to use. See the aker API documentation
84
- # for `Aker::Authorities` for options.
85
- authorities :ldap
86
-
87
- # The server-central parameters file for authority
88
- # and policy parameters (optional). See
89
- # `Aker::CentralParameters` for a discussion of why this is a
90
- # good idea.
91
- central '/etc/nubic/aker-prod.yml'
92
- end
77
+ config.aker do
78
+ # The authorities to use. See the aker API documentation
79
+ # for Aker::Authorities for options.
80
+ authorities :ldap
81
+
82
+ # The server-central parameters file for authority
83
+ # and policy parameters (optional). See
84
+ # Aker::CentralParameters for a discussion of why this is a
85
+ # good idea.
86
+ central '/etc/nubic/aker-prod.yml'
93
87
  end
94
88
 
89
+ (Migration note: this differs from the Rails 2.3 version of this
90
+ plugin. *Aker configuration should not happen in a Rails 3
91
+ after_initialize block.*)
92
+
93
+
95
94
  Integration into your app
96
95
  -------------------------
97
96
 
@@ -112,7 +111,7 @@ If you want to further require that all actions in a controller
112
111
  require that the user be a member of a certain group, you can use the
113
112
  {Aker::Rails::SecuredController::ClassMethods#permit permit} method:
114
113
 
115
- class ManuscriptController < ActionController::Base
114
+ class ManuscriptController < ApplicationController
116
115
  include Aker::Rails::SecuredController
117
116
  permit :editor
118
117
  end
@@ -124,7 +123,7 @@ particular group or groups. The helper for this is also called
124
123
  {Aker::Rails::Application#permit? permit}:
125
124
 
126
125
  # In a controller action
127
- class DashboardController < ActionController::Base
126
+ class DashboardController < ApplicationController
128
127
  # ...
129
128
  def index
130
129
  if permit?(:editor)
@@ -138,14 +137,15 @@ particular group or groups. The helper for this is also called
138
137
  @manuscripts.collect { |m| m.title }.join(', ')
139
138
  <% end %>
140
139
 
141
- This permit helper is available to all controllers and views, not just
142
- ones that mix in {Aker::Rails::SecuredController}. This means you
143
- can have a publically-accessible page which has additional/different
144
- content for a logged-in user.
140
+ This permit helper is available to all subclasses of
141
+ `ApplicationController`, not just ones that mix in
142
+ {Aker::Rails::SecuredController}. This means you can have a
143
+ publically-accessible page which has additional/different content for a
144
+ logged-in user.
145
145
 
146
146
  ### The current user
147
147
 
148
148
  Aker provides a method {Aker::Rails::Application#current_user
149
149
  current_user} to all controllers and views. It will return a
150
- {Aker::User} object for the current user, or `nil` if there isn't
150
+ `Aker::User` object for the current user, or `nil` if there isn't
151
151
  one.
@@ -22,16 +22,6 @@ module Aker::Rails
22
22
  end
23
23
  end
24
24
 
25
- ##
26
- # Sets up the aker global infrastructure that is not affected by
27
- # Rails' development-mode class reloading.
28
- #
29
- # @return [void]
30
- def self.one_time_setup
31
- Aker::Rack.use_in(ActionController::Dispatcher.middleware)
32
- Rack::Request.send(:include, Aker::Rack::RequestExt)
33
- end
34
-
35
25
  ##
36
26
  # Exposes the logged-in user (if any) to the application.
37
27
  #
@@ -0,0 +1,67 @@
1
+ require 'aker/rails'
2
+ require 'rails/application/configuration'
3
+
4
+ module Aker::Rails
5
+ ##
6
+ # Provides sugar for configuring Aker via a Rails application's
7
+ # configuration.
8
+ #
9
+ # The methods in this module operate on Aker's global configuration,
10
+ # so changes made here will be visible on `Aker.configuration` and
11
+ # vice versa.
12
+ #
13
+ # While everything here could be done with direct calls to methods
14
+ # on `Aker`, this integration emphasizes that Aker configuration
15
+ # **must be done during the configuration phase** of Rails boot
16
+ # (i.e., in `config/application.rb` and
17
+ # `config/environments/{env}.rb`). If Aker configuration is done in
18
+ # the initialization phase or later, some features will not work
19
+ # correctly.
20
+ module ConfigurationExt
21
+ ##
22
+ # Access or update the Aker configuration in the context of this
23
+ # Rails application.
24
+ #
25
+ # **N.b.:** While this method allows you to update the
26
+ # configuration at any time, some configuration options will only
27
+ # take full effect if they are set during the application's
28
+ # initial boot.
29
+ #
30
+ # @example Reading the configuration
31
+ # unless Rails.configuration.aker.api_modes.empty?
32
+ # # do something that should only happen if API access is enabled
33
+ # end
34
+ #
35
+ # @example Updating the configuration
36
+ # # in config/environments/{environment}.rb
37
+ # MyApp::Application.configure do
38
+ # # ...
39
+ # config.aker do
40
+ # authority MyEnvSpecificAuthority
41
+ # end
42
+ # # ...
43
+ # end
44
+ #
45
+ # @param [Proc] block a block of Aker's configuration DSL. If
46
+ # given, it will be applied to the global Aker configuration.
47
+ # @return [Aker::Configuration] the global Aker configuration.
48
+ def aker(&block)
49
+ if block
50
+ Aker.configure(&block)
51
+ end
52
+ Aker.configuration
53
+ end
54
+
55
+ ##
56
+ # Completely replace the Aker configuration. This should only
57
+ # rarely (if ever) be necessary.
58
+ #
59
+ # @param [Aker::Configuration] aker_configuration the replacement configuration.
60
+ # @return [void]
61
+ def aker=(aker_configuration)
62
+ Aker.configuration = aker_configuration
63
+ end
64
+ end
65
+ end
66
+
67
+ Rails::Application::Configuration.send(:include, Aker::Rails::ConfigurationExt)
@@ -0,0 +1,30 @@
1
+ require 'aker/rails'
2
+
3
+ require 'rails/railtie'
4
+
5
+ module Aker::Rails
6
+ class Railtie < ::Rails::Railtie
7
+ initializer 'Aker::Rails initialization' do |app|
8
+ Rails.logger.debug "Initializing Aker-Rails"
9
+
10
+ Aker.configure do
11
+ logger Rails.logger
12
+ end
13
+
14
+ Rack::Request.send(:include, Aker::Rack::RequestExt)
15
+ end
16
+
17
+ initializer 'Aker::Rails middleware installation' do |app|
18
+ Rails.logger.debug "Installing Aker rack middleware"
19
+ Rails.logger.debug "- UI mode: #{Aker.configuration.ui_mode.inspect}"
20
+ Rails.logger.debug "- API modes: #{Aker.configuration.api_modes.inspect}"
21
+ Aker::Rack.use_in(app.middleware)
22
+ end
23
+
24
+ initializer 'Aker::Rails development support' do |app|
25
+ app.config.to_prepare do
26
+ ApplicationController.send(:include, Aker::Rails::Application)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -35,14 +35,6 @@ module Aker::Rails
35
35
  request.env['aker.check'].authentication_required!
36
36
  end
37
37
 
38
- def handle_unverified_request
39
- super
40
-
41
- if request.env['aker.interactive']
42
- request.env['aker.check'].user = nil
43
- end
44
- end
45
-
46
38
  ##
47
39
  # Extensions for the rails controller DSL for
48
40
  # authentication-required controllers.
@@ -2,6 +2,6 @@ module Aker
2
2
  module Rails
3
3
  # VERSION is in a separate file with no external dependencies so it
4
4
  # can be sourced from the gemspec.
5
- VERSION = "2.0.3"
5
+ VERSION = "3.0.1"
6
6
  end
7
7
  end
data/lib/aker/rails.rb CHANGED
@@ -10,7 +10,12 @@ module Aker
10
10
  autoload :VERSION, 'aker/rails/version'
11
11
 
12
12
  autoload :Application, 'aker/rails/application'
13
+ autoload :Railtie, 'aker/rails/railtie'
13
14
  autoload :SecuredController, 'aker/rails/secured_controller'
14
15
  autoload :Test, 'aker/rails/test'
15
16
  end
16
17
  end
18
+
19
+ # This is directly required because the configuration extensions it
20
+ # defines need to be automatically available when the plugin is loaded.
21
+ require 'aker/rails/configuration_ext'
data/lib/aker-rails.rb ADDED
@@ -0,0 +1,12 @@
1
+ ##
2
+ # This file, being the same name as its parent gem, is required via
3
+ # `Bundler.require` by the stock `config/application.rb` in a Rails 3
4
+ # application.
5
+ #
6
+ # (Just a note as to why this file works: Railtie registration is implemented
7
+ # via a subclassing callback. See `Rails::Railtie.inherited`.)
8
+ #
9
+ # If you change the `Bundler.require` behavior in your application's
10
+ # `config/application.rb` such that `aker-rails` is not loaded, you will have
11
+ # to load `aker/rails/railtie` yourself.
12
+ require 'aker/rails/railtie'
@@ -68,20 +68,4 @@ module Aker::Rails
68
68
  end
69
69
  end
70
70
  end
71
-
72
- describe Application, ".one_time_setup" do
73
- before do
74
- Aker.configure { }
75
-
76
- Application.one_time_setup
77
- end
78
-
79
- after do
80
- Aker.configuration = nil
81
- end
82
-
83
- it "adds the aker middleware to the action controller middleware stack" do
84
- ActionController::Dispatcher.middleware.should include(Aker::Rack::Setup)
85
- end
86
- end
87
71
  end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ module Aker::Rails
4
+ describe ConfigurationExt do
5
+ it 'is automatically mixed into Rails::Application::Configuration' do
6
+ ::Rails::Application::Configuration.ancestors.should include(Aker::Rails::ConfigurationExt)
7
+ end
8
+
9
+ subject { ::Rails::Application::Configuration.new }
10
+
11
+ before do
12
+ Aker.configure { api_mode :http_basic }
13
+ end
14
+
15
+ after do
16
+ Aker.configuration = nil
17
+ end
18
+
19
+ describe '#aker' do
20
+ it 'returns the global Aker configuration' do
21
+ subject.aker.api_modes.should == [:http_basic]
22
+ end
23
+
24
+ describe 'with a block' do
25
+ before do
26
+ subject.aker {
27
+ portal :bar
28
+ }
29
+ end
30
+
31
+ it 'updates the global configuration' do
32
+ Aker.configuration.portal.should == :bar
33
+ end
34
+
35
+ it 'does not affect other settings' do
36
+ Aker.configuration.api_modes.should == [:http_basic]
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#aker=' do
42
+ it 'replaces the global Aker configuration' do
43
+ subject.aker = Aker::Configuration.new { portal :foo }
44
+
45
+ Aker.configuration.portal.should == :foo
46
+ Aker.configuration.api_modes.should == []
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path("../../../spec_helper", __FILE__)
2
+
3
+ module Aker::Rails
4
+ describe Railtie do
5
+ it "uses Rails' logger for Aker logging" do
6
+ pending "need to figure out a good way to test railties"
7
+ end
8
+
9
+ it "installs the Aker middleware exactly once" do
10
+ pending "need to figure out a good way to test railties"
11
+ end
12
+
13
+ it "sets up a to_prepare hook for Aker::Rails::Application" do
14
+ pending "need to figure out a good way to test railties"
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path("../../../../spec_helper", __FILE__)
2
2
  require 'action_controller'
3
- require 'action_controller/test_process'
3
+ require 'action_controller/test_case'
4
4
 
5
5
  module Aker::Rails::Test
6
6
  describe Helpers do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
1
5
  require "spec"
2
6
 
3
7
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
metadata CHANGED
@@ -1,90 +1,116 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: aker-rails
3
- version: !ruby/object:Gem::Version
4
- version: 2.0.3
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 1
10
+ version: 3.0.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - David Yip
9
14
  - Rhett Sutphin
10
15
  - Peter Nyberg
11
16
  autorequire:
12
17
  bindir: bin
13
18
  cert_chain: []
14
- date: 2012-01-04 00:00:00.000000000Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: rails
18
- requirement: &2152515780 !ruby/object:Gem::Requirement
19
+
20
+ date: 2011-07-20 00:00:00 -05:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
19
25
  none: false
20
- requirements:
26
+ requirements:
21
27
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 2.3.11
24
- type: :runtime
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ requirement: *id001
35
+ name: rails
25
36
  prerelease: false
26
- version_requirements: *2152515780
27
- - !ruby/object:Gem::Dependency
28
- name: aker
29
- requirement: &2152514380 !ruby/object:Gem::Requirement
37
+ type: :runtime
38
+ - !ruby/object:Gem::Dependency
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
30
40
  none: false
31
- requirements:
41
+ requirements:
32
42
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: '3.0'
35
- type: :runtime
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 3
47
+ - 0
48
+ version: "3.0"
49
+ requirement: *id002
50
+ name: aker
36
51
  prerelease: false
37
- version_requirements: *2152514380
52
+ type: :runtime
38
53
  description:
39
54
  email: r-sutphin@northwestern.edu
40
55
  executables: []
56
+
41
57
  extensions: []
58
+
42
59
  extra_rdoc_files: []
43
- files:
60
+
61
+ files:
44
62
  - CHANGELOG.md
45
63
  - README.md
46
64
  - lib/aker/rails/application.rb
65
+ - lib/aker/rails/configuration_ext.rb
66
+ - lib/aker/rails/railtie.rb
47
67
  - lib/aker/rails/secured_controller.rb
48
68
  - lib/aker/rails/test/helpers.rb
49
69
  - lib/aker/rails/test.rb
50
70
  - lib/aker/rails/version.rb
51
71
  - lib/aker/rails.rb
72
+ - lib/aker-rails.rb
52
73
  - spec/aker/rails/application_spec.rb
74
+ - spec/aker/rails/configuration_ext_spec.rb
75
+ - spec/aker/rails/railtie_spec.rb
53
76
  - spec/aker/rails/secured_controller_spec.rb
54
77
  - spec/aker/rails/test/helpers_spec.rb
55
78
  - spec/aker/rails_spec.rb
56
79
  - spec/deprecation_helper.rb
57
80
  - spec/spec_helper.rb
58
- - rails/init.rb
81
+ has_rdoc: true
59
82
  homepage: https://github.com/NUBIC/aker-rails
60
83
  licenses: []
84
+
61
85
  post_install_message:
62
86
  rdoc_options: []
63
- require_paths:
87
+
88
+ require_paths:
64
89
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
66
91
  none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- segments:
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
72
97
  - 0
73
- hash: 2362672654052909796
74
- required_rubygems_version: !ruby/object:Gem::Requirement
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
100
  none: false
76
- requirements:
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
- segments:
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
81
106
  - 0
82
- hash: 2362672654052909796
107
+ version: "0"
83
108
  requirements: []
109
+
84
110
  rubyforge_project:
85
- rubygems_version: 1.8.10
111
+ rubygems_version: 1.3.7
86
112
  signing_key:
87
113
  specification_version: 3
88
114
  summary: Easy Rails integration for the Aker security framework
89
115
  test_files: []
90
- has_rdoc:
116
+
data/rails/init.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'aker/rails'
2
-
3
- Rails.logger.debug "Initializing aker-rails"
4
- # We do this up here to allow the application to override if desired
5
- Aker.configure {
6
- logger Rails.logger
7
- }
8
- config.after_initialize do
9
- Aker::Rails::Application.one_time_setup
10
-
11
- if config.cache_classes
12
- ApplicationController.send(:include, Aker::Rails::Application)
13
- else
14
- config.to_prepare do
15
- ApplicationController.send(:include, Aker::Rails::Application)
16
- end
17
- end
18
- end