Module: Git::Lighttp::AuthenticationHelpers

Defined in:
lib/git/lighttp.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#access_granted?(username, password) ⇒ Boolean

Returns:

  • (Boolean)


305
306
307
# File 'lib/git/lighttp.rb', line 305

def access_granted?(username, password)
  authenticated? || authenticate(username, password)
end

#authenticate(username, password) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
# File 'lib/git/lighttp.rb', line 276

def authenticate(username, password)
  checked   = [ username, password ] == authentication.credentials
  validated = authentication.provided? && authentication.basic?
  granted   = htpasswd.authenticated? username, password
  if checked and validated and granted
    request.env["git.lighttp.authenticated"] = true
    request.env["REMOTE_USER"] = authentication.username
  else
    nil
  end
end

#authenticate!Object



297
298
299
300
301
302
303
# File 'lib/git/lighttp.rb', line 297

def authenticate!
  return if authenticated?
  unauthorized! unless authentication.provided?
  bad_request!  unless authentication.basic?
  unauthorized! unless authenticate(*authentication.credentials)
  request.env["REMOTE_USER"] = authentication.username
end

#authenticated?Boolean

Returns:

  • (Boolean)


272
273
274
# File 'lib/git/lighttp.rb', line 272

def authenticated?
  request.env["REMOTE_USER"] && request.env["git.lighttp.authenticated"]
end

#authenticationObject



268
269
270
# File 'lib/git/lighttp.rb', line 268

def authentication
  @authentication ||= Rack::Auth::Basic::Request.new request.env
end

#bad_request!Object



293
294
295
# File 'lib/git/lighttp.rb', line 293

def bad_request!
  throw :halt, [ 400, "Bad Request" ]
end

#htpasswdObject



264
265
266
# File 'lib/git/lighttp.rb', line 264

def htpasswd
  @htpasswd ||= Htpasswd.new(git.path_to("htpasswd"))
end

#unauthorized!(realm = Git::Lighttp::info) ⇒ Object



288
289
290
291
# File 'lib/git/lighttp.rb', line 288

def unauthorized!(realm = Git::Lighttp::info)
  headers "WWW-Authenticate" => %(Basic realm="#{realm}")
  throw :halt, [ 401, "Authorization Required" ]
end