Class: Aker::Configuration
- Inherits:
-
Object
- Object
- Aker::Configuration
- Defined in:
- lib/aker/configuration.rb
Overview
The representation of a configuration for Aker in a particular application, including authorities, customization parameters, and authentication modes.
Defined Under Namespace
Classes: Slice
Class Method Summary collapse
-
.add_default_slice(slice = nil, &block) ⇒ void
Appends a slice to the default set of slices.
-
.default_slices ⇒ Array<Slice>
The default set of slices.
Instance Method Summary collapse
-
#add_parameters_for(group, params) ⇒ void
Merges the given parameters into the specified group’s.
-
#alias_authority(name, authority) ⇒ void
Register an alias for an authority object.
-
#api_modes ⇒ Array<Symbol>
The names of the configured non-interactive authentication modes.
-
#api_modes=(*new_modes) ⇒ void
(also: #api_mode=)
Replaces the non-interactive authentication modes.
-
#authorities ⇒ Array<Object>
Returns the actual authority objects created based on the last call to #authorities=.
-
#authorities=(new_authorities) ⇒ void
Set the authorities for this configuration.
-
#authorities? ⇒ Boolean
True if there are any authorities configured.
-
#authority_aliases ⇒ Hash
The map of aliases to authority objects.
-
#central(filename) ⇒ void
Loads parameters from the given aker central parameters file.
-
#composite_authority ⇒ Aker::Authorities::Composite
Exposes a single object which aggregates all the authorities in this configuration.
-
#enhance(&additional_config) ⇒ Configuration
Updates the configuration via the DSL.
-
#initialize(options = {}, &config) ⇒ Configuration
constructor
Creates a new configuration.
-
#install_middleware(where, builder) ⇒ void
Installs the middleware configured under the given key in the given ‘Rack::Builder}.
-
#logger ⇒ Object
Retrieves the logger which aker will use for internal messages.
-
#logger=(logger) ⇒ Object
Specifies the logger aker will use for internal messages.
- #middleware_installers ⇒ Object
-
#parameters_for(group) ⇒ Hash
Returns the parameters for a particular group.
-
#portal ⇒ Symbol
The portal to which this application belongs.
-
#portal=(portal) ⇒ void
Set the portal to which this application belongs.
-
#portal? ⇒ Boolean
True if there is a portal set, else false.
-
#register_middleware_installer(where) {|#use| ... } ⇒ void
Register a middleware-building block that will be used to insert middleware either before or after the Aker authentication middleware.
-
#register_mode(mode_class) ⇒ void
Register a mode class to be used in this configuration.
-
#registered_modes ⇒ Array<Class>
The mode classes that have been registered for use in this configuration.
-
#ui_mode ⇒ Symbol
The name of the configured interactive authentication mode.
-
#ui_mode=(ui_mode) ⇒ void
Sets the interactive authentication mode.
Constructor Details
#initialize(options = {}, &config) ⇒ Configuration
Creates a new configuration. If a block is given, it will be evaluated using the DSL and appended to the new instance.
67 68 69 70 71 72 |
# File 'lib/aker/configuration.rb', line 67 def initialize(={}, &config) ([:slices] || self.class.default_slices).each do |slice| self.enhance(&slice.contents) end self.enhance(&config) if config end |
Class Method Details
.add_default_slice(slice = nil, &block) ⇒ void
This method returns an undefined value.
Appends a slice to the default set of slices. A slice may be specified either as a Slice instance or as a block provided directly to this method.
47 48 49 50 51 52 53 54 |
# File 'lib/aker/configuration.rb', line 47 def add_default_slice(slice=nil, &block) if slice default_slices << slice end if block default_slices << Slice.new(&block) end end |
Instance Method Details
#add_parameters_for(group, params) ⇒ void
This method returns an undefined value.
Merges the given parameters into the specified group’s.
213 214 215 |
# File 'lib/aker/configuration.rb', line 213 def add_parameters_for(group, params) nested_merge!(parameters_for(group), params) end |
#alias_authority(name, authority) ⇒ void
This method returns an undefined value.
Register an alias for an authority object. The alias is a symbol (or something that can be turned into one). The authority object is any single element that can be passed to #authorities=.
Aker does and Aker extensions may define shorter aliases for the authorities that they provide. In general, it’s not expected that applications, even if they provide their own authorities, will need to configure aliases.
244 245 246 |
# File 'lib/aker/configuration.rb', line 244 def (name, ) [name.to_sym] = end |
#api_modes ⇒ Array<Symbol>
102 103 104 |
# File 'lib/aker/configuration.rb', line 102 def api_modes @api_modes ||= [] end |
#api_modes=(*new_modes) ⇒ void Also known as: api_mode=
This method returns an undefined value.
Replaces the non-interactive authentication modes.
110 111 112 113 |
# File 'lib/aker/configuration.rb', line 110 def api_modes=(*new_modes) new_modes = new_modes.first if new_modes.size == 1 && Array === new_modes.first @api_modes = new_modes.compact.collect(&:to_sym) end |
#authorities ⇒ Array<Object>
Returns the actual authority objects created based on the last call to #authorities=. Note that “authority” is concept and a set of methods (all of them optional), not a base class; see Authorities::Composite for more details.
157 158 159 160 |
# File 'lib/aker/configuration.rb', line 157 def raise "No authorities configured" unless @authorities end |
#authorities=(new_authorities) ⇒ void
This method returns an undefined value.
Set the authorities for this configuration.
178 179 180 |
# File 'lib/aker/configuration.rb', line 178 def () @authorities = .collect { |a| (a) } end |
#authorities? ⇒ Boolean
184 185 186 |
# File 'lib/aker/configuration.rb', line 184 def @authorities && !@authorities.empty? end |
#authority_aliases ⇒ Hash
Returns the map of aliases to authority objects.
251 252 253 |
# File 'lib/aker/configuration.rb', line 251 def @authority_aliases ||= {} end |
#central(filename) ⇒ void
This method returns an undefined value.
Loads parameters from the given aker central parameters file.
224 225 226 227 228 |
# File 'lib/aker/configuration.rb', line 224 def central(filename) params = ::Aker::CentralParameters.new(filename) params.each { |k, v| add_parameters_for(k, v) } end |
#composite_authority ⇒ Aker::Authorities::Composite
Exposes a single object which aggregates all the authorities in this configuration.
193 194 195 |
# File 'lib/aker/configuration.rb', line 193 def @composite_authority ||= Aker::Authorities::Composite.new(self) end |
#enhance(&additional_config) ⇒ Configuration
Updates the configuration via the DSL.
78 79 80 81 |
# File 'lib/aker/configuration.rb', line 78 def enhance(&additional_config) Configurator.new(self, &additional_config) self end |
#install_middleware(where, builder) ⇒ void
This method returns an undefined value.
Installs the middleware configured under the given key in the given ‘Rack::Builder}. This method is primarily for internal library use.
338 339 340 341 342 343 |
# File 'lib/aker/configuration.rb', line 338 def install_middleware(where, builder) verify_middleware_location(where) (middleware_installers[where] || []).each do |installer| installer.call(builder) end end |
#logger ⇒ Object
Retrieves the logger which aker will use for internal messages.
The default instance logs to standard error.
359 360 361 |
# File 'lib/aker/configuration.rb', line 359 def logger @logger ||= Logger.new($stderr) end |
#logger=(logger) ⇒ Object
Specifies the logger aker will use for internal messages.
368 369 370 |
# File 'lib/aker/configuration.rb', line 368 def logger=(logger) @logger = logger end |
#middleware_installers ⇒ Object
323 324 325 |
# File 'lib/aker/configuration.rb', line 323 def middleware_installers @middleware_installers ||= {} end |
#parameters_for(group) ⇒ Hash
Returns the parameters for a particular group. Never returns ‘nil`.
202 203 204 205 |
# File 'lib/aker/configuration.rb', line 202 def parameters_for(group) @parameter_groups ||= { } @parameter_groups[group] ||= { } end |
#portal ⇒ Symbol
118 119 120 121 |
# File 'lib/aker/configuration.rb', line 118 def portal raise "No portal configured" unless portal? @portal end |
#portal=(portal) ⇒ void
This method returns an undefined value.
Set the portal to which this application belongs.
Portal is an optional authorization concept. If you have an authority which is based on an authorization store that provides group information for multiple groups of applications, Aker calls each group of applications a portal.
When an application declares that it is a part of a portal, authentication will fail for any user which is not a member of that portal. If you don’t have an authority that provides that information, don’t set a portal.
139 140 141 |
# File 'lib/aker/configuration.rb', line 139 def portal=(portal) @portal = nil_or_sym(portal) end |
#portal? ⇒ Boolean
145 146 147 |
# File 'lib/aker/configuration.rb', line 145 def portal? @portal end |
#register_middleware_installer(where) {|#use| ... } ⇒ void
This method returns an undefined value.
Register a middleware-building block that will be used to insert middleware either before or after the Aker authentication middleware. This method requires a block. When it is time to actually install the middleware, the block will be yielded an object which behaves like a ‘Rack::Builder`. The block should attach any middleware it wishes to install using `use`.
Unlike the middleware associated with modes, this middleware will be inserted in the stack in regardless of any other settings.
This method is primarily intended for Aker and Aker extensions. Applications have complete control over their middleware stacks and so may build them however is appropriate.
316 317 318 319 |
# File 'lib/aker/configuration.rb', line 316 def register_middleware_installer(where, &installer) verify_middleware_location(where) (middleware_installers[where] ||= []) << installer end |
#register_mode(mode_class) ⇒ void
This method returns an undefined value.
Register a mode class to be used in this configuration. A mode class is a Warden strategy with some additional Aker elements on top.
Aker and Aker extensions register the the modes that they provide (using slices), so an application only needs to invoke this method if it provides its own custom mode.
270 271 272 273 |
# File 'lib/aker/configuration.rb', line 270 def register_mode(mode_class) fail "#{mode_class.inspect} is not usable as a Aker mode" unless mode_class.respond_to?(:key) registered_modes << mode_class end |
#registered_modes ⇒ Array<Class>
The mode classes that have been registered for use in this configuration.
281 282 283 |
# File 'lib/aker/configuration.rb', line 281 def registered_modes @registered_modes ||= [] end |
#ui_mode ⇒ Symbol
86 87 88 |
# File 'lib/aker/configuration.rb', line 86 def ui_mode @ui_mode ||= :form end |
#ui_mode=(ui_mode) ⇒ void
This method returns an undefined value.
Sets the interactive authentication mode.
95 96 97 |
# File 'lib/aker/configuration.rb', line 95 def ui_mode=(ui_mode) @ui_mode = nil_or_sym(ui_mode) end |