Class: Htpasswd::Auths::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/htpasswd/auths/base.rb

Direct Known Subclasses

Basic, Digest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



56
57
58
# File 'lib/htpasswd/auths/base.rb', line 56

def initialize(options = {})
  @options = options.with_indifferent_access
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



55
56
57
# File 'lib/htpasswd/auths/base.rb', line 55

def options
  @options
end

Class Method Details

.<=>(other) ⇒ Object



50
51
52
# File 'lib/htpasswd/auths/base.rb', line 50

def <=> (other)
  strength <=> other.strength
end

.parse(data) ⇒ Object

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/htpasswd/auths/base.rb', line 46

def parse(data)
  raise NotImplementedError, "subclass responsibility"
end

Instance Method Details

#authorize(entries) ⇒ Object

return authorized username or raise exception

Raises:



61
62
63
64
65
66
67
68
# File 'lib/htpasswd/auths/base.rb', line 61

def authorize(entries)
  entries.each do |entry|
    if user = entry.authorized?(self)
      return user
    end
  end
  raise UnknownUserAccount
end

#authorize_pass(pass) ⇒ Object



78
79
80
# File 'lib/htpasswd/auths/base.rb', line 78

def authorize_pass(pass)
  options[:pass] == pass or raise IncorrectPassword
end

#authorize_type(type) ⇒ Object



70
71
72
# File 'lib/htpasswd/auths/base.rb', line 70

def authorize_type(type)
  true
end

#authorize_user(user) ⇒ Object



74
75
76
# File 'lib/htpasswd/auths/base.rb', line 74

def authorize_user(user)
  options[:user] == user
end

#passObject



98
99
100
# File 'lib/htpasswd/auths/base.rb', line 98

def pass
  options[:pass]
end

#random(size = 16, array = nil) ⇒ Object



102
103
104
105
# File 'lib/htpasswd/auths/base.rb', line 102

def random(size = 16, array = nil)
  array ||= (0..9).to_a + ('a'..'f').to_a
  (0...size).map{array[rand(array.size)]}.join
end

#realmObject



86
87
88
# File 'lib/htpasswd/auths/base.rb', line 86

def realm
  options[:realm] || Auths.default_realm
end

#schemeObject



90
91
92
# File 'lib/htpasswd/auths/base.rb', line 90

def scheme
  self.class.name.demodulize
end

#set_controller(controller) ⇒ Object



82
83
84
# File 'lib/htpasswd/auths/base.rb', line 82

def set_controller(controller)
  # nop
end

#userObject



94
95
96
# File 'lib/htpasswd/auths/base.rb', line 94

def user
  options[:user]
end