class Patriot::Worker::Servlet::APIServletBase

Public Class Methods

configure(worker, config) click to toggle source

@param worker [Patriot::Wokrer::Base] @param config [Patriot::Util::Config::Base]

# File lib/patriot/worker/servlet/api_servlet_base.rb, line 27
def self.configure(worker, config)
  @@worker = worker
  @@config = config
  @@username  = config.get(Patriot::Util::Config::USERNAME_KEY, "")
  @@password  = config.get(Patriot::Util::Config::PASSWORD_KEY, "")
end

Public Instance Methods

authorized?() click to toggle source

authorize user (basic authentication)

# File lib/patriot/worker/servlet/api_servlet_base.rb, line 19
def authorized?
  @auth ||= Rack::Auth::Basic::Request.new(request.env)
  return @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [@@username, @@password]
end
protected!() click to toggle source

require authorization for updating

# File lib/patriot/worker/servlet/api_servlet_base.rb, line 12
def protected!
  return if authorized?
  headers['WWW-Authenticate'] = 'Basic Realm="Admin Only"'
  halt 401, "Not Authorized"
end