Class: Aurora::Server
- Inherits:
-
Halcyon::Server::Base
- Object
- Halcyon::Server::Base
- Aurora::Server
- Defined in:
- lib/aurora/server.rb
Overview
Aurora Server
The Aurora Server handles user authentication requests, token creation and management, and permissions querying and verification.
Usage
class Aurora::Server
def authenticate(username, password)
username == 'test' && password == 'secret'
end
end
This will define an authentication processor for verifying users’ authenticity. This method is only defaulted to when token authentication is not able to be used (such as for creating sessions), so its use should be minimized by token authentication.
Class Method Summary collapse
Instance Method Summary collapse
-
#expire_tokens ⇒ Object
Removes expired tokens.
-
#generate_expiration(lifetime = @config[:tokens][:lifetime]) ⇒ Object
Generates a new time to expire from the minutes given, defaulting to the number of minutes given as a token lifetime in the configuration file.
-
#initialize_permissions(username) ⇒ Object
Sets up a given user’s permissions.
-
#startup ⇒ Object
Makes sure the Database server connection is created, tables migrated, and other tasks.
-
#unauthorized(params = {}) ⇒ Object
The default unauthorized action which raises an Unauthorized exception.
Class Method Details
.version ⇒ Object
41 42 43 |
# File 'lib/aurora/server.rb', line 41 def self.version VERSION.join('.') end |
Instance Method Details
#expire_tokens ⇒ Object
Removes expired tokens.
254 255 256 |
# File 'lib/aurora/server.rb', line 254 def expire_tokens @db[:tokens].filter('expires_at < ?',Time.now).delete end |
#generate_expiration(lifetime = @config[:tokens][:lifetime]) ⇒ Object
Generates a new time to expire from the minutes given, defaulting to the number of minutes given as a token lifetime in the configuration file.
269 270 271 |
# File 'lib/aurora/server.rb', line 269 def generate_expiration(lifetime=@config[:tokens][:lifetime]) (Time.now + (lifetime.to_i*60)) end |
#initialize_permissions(username) ⇒ Object
Sets up a given user’s permissions. Overwrite this method to specify more specific or dynamic default permissions, for instance connecting to LDAP to determine department and granting permissions that way.
261 262 263 264 265 |
# File 'lib/aurora/server.rb', line 261 def (username) # by default, no permissions are setup # the returned value is JSON-ized {} end |
#startup ⇒ Object
Makes sure the Database server connection is created, tables migrated, and other tasks.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aurora/server.rb', line 72 def startup # TODO: setup startup tasks # connect to database host = credentials = '' host = "#{@config[:db][:host]}/" unless @config[:db][:host].nil? credentials = "#{@config[:db][:username]}:#{@config[:db][:password]}@" unless @config[:db][:username].nil? @db = Sequel("#{@config[:db][:adapter]}://#{credentials}#{host}#{@config[:db][:database]}") @db.logger = @logger if $debug @logger.info 'Connected to Database.' # run migrations if version is outdated current_version = Sequel::Migrator.get_current_migration_version(@db) latest_version = Sequel::Migrator.apply(@db, File.join(File.dirname(__FILE__),'migrations')) @logger.info 'Migrations loaded!' if current_version < latest_version # clean expired sessions/tokens expire_tokens @logger.info 'Expired sessions/tokens removed.' end |
#unauthorized(params = {}) ⇒ Object
The default unauthorized action which raises an Unauthorized exception
245 246 247 |
# File 'lib/aurora/server.rb', line 245 def (params={}) raise Exceptions::Unauthorized.new end |