Sha256: 69877855c7f2baf453d86411c03396b8e7cba8b650a17571fe40def0c5fd5f9e

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require 'webrick/config'
require 'webrick/httpstatus'
require 'webrick/httpauth/authenticator'
require 'base64'

module WEBrick
  module HTTPAuth
		class NotAuthentication
			
			include WEBrick::HTTPAuth::Authenticator
			
			AuthScheme = "Basic"
	
			def  initialize( realm = "editing" )
				config = { :UserDB => "nodb" , :Realm => realm }
		      check_init(config)
				@config = Config::BasicAuth.dup.update(config)
		   end

		   def authenticate(req, res)
		     unless basic_credentials = check_scheme(req)
		       challenge(req, res)
		     end
		     userid, password = decode64(basic_credentials).split(":", 2) 
		     if userid.empty?
		       error("user id was not given.")
		       challenge(req, res)
		     end
		     info("%s: authentication succeeded.", userid)
		     req.user = userid
		   end

		   def challenge(req, res)
		     res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\""
		     raise @auth_exception
		   end
		end
		
    class OnePasswordAuthentication
      include Authenticator

      AuthScheme = "Basic"

      attr_reader :realm, :userdb, :logger

      def initialize( password = "", realm = "editing" )
  			config = { :UserDB => "nodb" , :Realm => realm }
		   check_init(config)
			@config = Config::BasicAuth.dup.update(config)
			@password = password
      end

      def authenticate(req, res)
        unless basic_credentials = check_scheme(req)
          challenge(req, res)
        end
        userid, password = decode64(basic_credentials).split(":", 2) 
        password ||= ""
        if userid.empty?
          error("user id was not given.")
          challenge(req, res)
        end
 
        if password != @password
          error("%s: password unmatch.", userid)
          challenge(req, res)
        end
        info("%s: authentication succeeded.", userid)
        req.user = userid
      end

      def challenge(req, res)
        res[@response_field] = "#{@auth_scheme} realm=\"#{@realm}\""
        raise @auth_exception
      end
    end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Soks-0.0.2 lib/authenticators.rb