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)


307
308
309
# File 'lib/git/lighttp.rb', line 307

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

#authenticate(username, password) ⇒ Object



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

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

#authenticate!Object



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

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)


274
275
276
# File 'lib/git/lighttp.rb', line 274

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

#authenticationObject



270
271
272
# File 'lib/git/lighttp.rb', line 270

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

#bad_request!Object



295
296
297
# File 'lib/git/lighttp.rb', line 295

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

#htpasswdObject



266
267
268
# File 'lib/git/lighttp.rb', line 266

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

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



290
291
292
293
# File 'lib/git/lighttp.rb', line 290

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