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)
Appends a slice to the default set of slices.
-
+ (Array<Slice>) default_slices
The default set of slices.
Instance Method Summary (collapse)
-
- add_parameters_for(group, params)
Merges the given parameters into the specified group's.
-
- alias_authority(name, authority)
Register an alias for an authority object.
-
- (Array<Symbol>) api_modes
The names of the configured non-interactive authentication modes.
-
- api_modes=(*new_modes)
(also: #api_mode=)
Replaces the non-interactive authentication modes.
-
- (Array<Object>) authorities
Returns the actual authority objects created based on the last call to #authorities=.
-
- authorities=(new_authorities)
Set the authorities for this configuration.
-
- (Boolean) authorities?
True if there are any authorities configured.
-
- (Hash) authority_aliases
The map of aliases to authority objects.
-
- central(filename)
Loads parameters from the given aker central parameters file.
-
- (Aker::Authorities::Composite) composite_authority
Exposes a single object which aggregates all the authorities in this configuration.
-
- (Configuration) enhance(&additional_config)
Updates the configuration via the DSL.
-
- (Configuration) initialize(options = {}, &config)
constructor
Creates a new configuration.
-
- install_middleware(where, builder)
Installs the middleware configured under the given key in the given `Rack::Builder}. This method is primarily for internal library use..
-
- (Object) logger
Retrieves the logger which aker will use for internal messages.
-
- (Object) logger=(logger)
Specifies the logger aker will use for internal messages.
-
- (Hash) parameters_for(group)
Returns the parameters for a particular group.
-
- (Symbol) portal
The portal to which this application belongs.
-
- portal=(portal)
Set the portal to which this application belongs.
-
- (Boolean) portal?
True if there is a portal set, else false.
-
- register_middleware_installer(where) {|#use| ... }
Register a middleware-building block that will be used to insert middleware either before or after the Aker authentication middleware.
-
- register_mode(mode_class)
Register a mode class to be used in this configuration.
-
- (Array<Class>) registered_modes
The mode classes that have been registered for use in this configuration.
-
- (Symbol) ui_mode
The name of the configured interactive authentication mode.
-
- ui_mode=(ui_mode)
Sets the interactive authentication mode.
Constructor Details
- (Configuration) initialize(options = {}, &config)
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)
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)
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)
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 |
- (Array<Symbol>) api_modes
The names of the configured non-interactive authentication modes. Default is an empty list.
102 103 104 |
# File 'lib/aker/configuration.rb', line 102 def api_modes @api_modes ||= [] end |
- api_modes=(*new_modes) 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 |
- (Array<Object>) authorities
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)
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 |
- (Boolean) authorities?
True if there are any authorities configured
184 185 186 |
# File 'lib/aker/configuration.rb', line 184 def @authorities && !@authorities.empty? end |
- (Hash) authority_aliases
The map of aliases to authority objects.
251 252 253 |
# File 'lib/aker/configuration.rb', line 251 def @authority_aliases ||= {} end |
- central(filename)
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 |
- (Aker::Authorities::Composite) composite_authority
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 |
- (Configuration) enhance(&additional_config)
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)
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 |
- (Object) logger
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 |
- (Object) logger=(logger)
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 |
- (Hash) parameters_for(group)
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 |
- (Symbol) portal
The portal to which this application belongs
118 119 120 121 |
# File 'lib/aker/configuration.rb', line 118 def portal raise "No portal configured" unless portal? @portal end |
- portal=(portal)
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 |
- (Boolean) portal?
True if there is a portal set, else false
145 146 147 |
# File 'lib/aker/configuration.rb', line 145 def portal? @portal end |
- register_middleware_installer(where) {|#use| ... }
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)
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 |
- (Array<Class>) registered_modes
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 |
- (Symbol) ui_mode
The name of the configured interactive authentication
mode. Default is :form.
86 87 88 |
# File 'lib/aker/configuration.rb', line 86 def ui_mode @ui_mode ||= :form end |
- ui_mode=(ui_mode)
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 |