class AuthenticationStrategies::BasicStrategy

Public Instance Methods

auth_request() click to toggle source
# File lib/authentication_strategies/basic_strategy.rb, line 3
def auth_request
  @auth_request ||= Rack::Auth::Basic::Request.new(env)
end
authenticate!() click to toggle source

@see AuthenticationStrategies::DummyStrategy

# File lib/authentication_strategies/basic_strategy.rb, line 22
def authenticate!
  Rails.logger.debug "[AuthN] [#{self.class}] Authenticating ..."

  unless valid_username_provided?(auth_request.username)
    fail! 'Provided username contains invalid characters!'
    return
  end

  user = Hashie::Mash.new
  user.auth!.type = 'basic'
  user.auth!.credentials!.username = auth_request.username
  user.auth!.credentials!.password = auth_request.credentials.last
  user.identity = auth_request.username

  Rails.logger.debug "[AuthN] [#{self.class}] Authenticated #{user.to_hash.inspect}"
  success! user.deep_freeze
end
store?() click to toggle source

@see AuthenticationStrategies::DummyStrategy

# File lib/authentication_strategies/basic_strategy.rb, line 8
def store?
  false
end
valid?() click to toggle source

@see AuthenticationStrategies::DummyStrategy

# File lib/authentication_strategies/basic_strategy.rb, line 13
def valid?
  Rails.logger.debug "[AuthN] [#{self.class}] Checking for applicability"
  result = auth_request.provided? && auth_request.basic?

  Rails.logger.debug "[AuthN] [#{self.class}] Strategy is #{result ? '' : 'not '}applicable!"
  result
end
valid_username_provided?(username) click to toggle source
# File lib/authentication_strategies/basic_strategy.rb, line 40
def valid_username_provided?(username)
  /^[[:print:]]+$/.match(username) && /^\S+$/.match(username)
end