Class: Cassy::Authenticators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cassy/authenticators/base.rb

Direct Known Subclasses

Devise, Test

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.client_app_user_fieldObject

make this accessible so that we can pick up any transformations done within the authenticator



8
9
10
# File 'lib/cassy/authenticators/base.rb', line 8

def client_app_user_field
  @client_app_user_field
end

.optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/cassy/authenticators/base.rb', line 5

def options
  @options
end

.usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/cassy/authenticators/base.rb', line 6

def username
  @username
end

Class Method Details

.configure(options) ⇒ Object

This is called prior to #validate (i.e. each time the user tries to log in). Any per-instance initialization for the authenticator should be done here.

By default this makes the authenticator options hash available for #validate under @options and initializes @extra_attributes to an empty hash.

Raises:

  • (ArgumentError)


30
31
32
33
34
# File 'lib/cassy/authenticators/base.rb', line 30

def self.configure(options)
  raise ArgumentError, "options must be a HashWithIndifferentAccess" unless options.kind_of? HashWithIndifferentAccess
  @options = options.dup
  @extra_attributes = {}
end

.extra_attributesObject



36
37
38
# File 'lib/cassy/authenticators/base.rb', line 36

def self.extra_attributes
  @extra_attributes
end

.extra_attributes_to_extractObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cassy/authenticators/base.rb', line 40

def self.extra_attributes_to_extract
  if @options[:extra_attributes].kind_of? Array
    attrs = @options[:extra_attributes]
  elsif @options[:extra_attributes].kind_of? String
    attrs = @options[:extra_attributes].split(',').collect{|col| col.strip}
  else
    attrs = []
  end

  attrs
end

.find_user(credentials) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/cassy/authenticators/base.rb', line 18

def self.find_user(credentials)
  raise NotImplementedError
end

.find_user_from_ticket(ticket) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/cassy/authenticators/base.rb', line 22

def self.find_user_from_ticket(ticket)
  raise NotImplementedError
end

.setup(options) ⇒ Object

This is called at server startup. Any class-wide initializiation for the authenticator should be done here. (e.g. establish database connection). You can leave this empty if you don’t need to set up anything.



15
16
# File 'lib/cassy/authenticators/base.rb', line 15

def self.setup(options)
end

Instance Method Details

#validate(credentials) ⇒ Object

Override this to implement your authentication credential validation. This is called each time the user tries to log in. The credentials hash holds the credentials as entered by the user (generally under :username and :password keys; :service and :request are also included by default)

Note that the standard credentials can be read in to instance variables by calling #read_standard_credentials.

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/cassy/authenticators/base.rb', line 59

def validate(credentials)
  raise NotImplementedError, "This method must be implemented by a class extending #{self.class}"
end