mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
6645b92826
[ruby-dev:25810] * eval.c (rb_exec_recursive): should not use NODE in disclosed context. [ruby-dev:25812] * io.c (rb_f_open): need not to check if to_open value is a T_FILE. [ruby-dev:25812] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
119 lines
2.5 KiB
Perl
119 lines
2.5 KiB
Perl
require 'pstore'
|
|
require 'soap/rpc/cgistub'
|
|
require 'soap/header/simplehandler'
|
|
|
|
|
|
class AuthHeaderPortServer < SOAP::RPC::CGIStub
|
|
PortName = 'http://tempuri.org/authHeaderPort'
|
|
SupportPortName = 'http://tempuri.org/authHeaderSupportPort'
|
|
MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth")
|
|
SessionDB = File.join(File.expand_path(File.dirname(__FILE__)), 'session.pstoredb')
|
|
|
|
class AuthHeaderService
|
|
def self.create
|
|
new
|
|
end
|
|
|
|
def deposit(amt)
|
|
"deposit #{amt} OK"
|
|
end
|
|
|
|
def withdrawal(amt)
|
|
"withdrawal #{amt} OK"
|
|
end
|
|
end
|
|
|
|
class AuthHeaderSupportService
|
|
def delete_sessiondb
|
|
File.unlink(SessionDB) if File.file?(SessionDB)
|
|
backup = SessionDB + "~"
|
|
File.unlink(backup) if File.file?(backup)
|
|
end
|
|
end
|
|
|
|
def initialize(*arg)
|
|
super
|
|
add_rpc_servant(AuthHeaderService.new, PortName)
|
|
add_rpc_servant(AuthHeaderSupportService.new, SupportPortName)
|
|
add_rpc_headerhandler(ServerAuthHeaderHandler.new)
|
|
end
|
|
|
|
class ServerAuthHeaderHandler < SOAP::Header::SimpleHandler
|
|
Users = {
|
|
'NaHi' => 'passwd',
|
|
'HiNa' => 'wspass'
|
|
}
|
|
|
|
def initialize
|
|
super(MyHeaderName)
|
|
@db = PStore.new(SessionDB)
|
|
@db.transaction do
|
|
@db["root"] = {} unless @db.root?("root")
|
|
end
|
|
@userid = @sessionid = nil
|
|
end
|
|
|
|
def login(userid, passwd)
|
|
userid and passwd and Users[userid] == passwd
|
|
end
|
|
|
|
def auth(sessionid)
|
|
in_sessiondb do |root|
|
|
root[sessionid][0]
|
|
end
|
|
end
|
|
|
|
def create_session(userid)
|
|
in_sessiondb do |root|
|
|
while true
|
|
key = create_sessionkey
|
|
break unless root[key]
|
|
end
|
|
root[key] = [userid]
|
|
key
|
|
end
|
|
end
|
|
|
|
def destroy_session(sessionkey)
|
|
in_sessiondb do |root|
|
|
root.delete(sessionkey)
|
|
end
|
|
end
|
|
|
|
def on_simple_outbound
|
|
{ "sessionid" => @sessionid }
|
|
end
|
|
|
|
def on_simple_inbound(my_header, mu)
|
|
auth_p = false
|
|
userid = my_header["userid"]
|
|
passwd = my_header["passwd"]
|
|
if login(userid, passwd)
|
|
auth_p = true
|
|
elsif sessionid = my_header["sessionid"]
|
|
if userid = auth(sessionid)
|
|
destroy_session(sessionid)
|
|
auth_p = true
|
|
end
|
|
end
|
|
raise RuntimeError.new("authentication failed") unless auth_p
|
|
@userid = userid
|
|
@sessionid = create_session(userid)
|
|
end
|
|
|
|
private
|
|
|
|
def create_sessionkey
|
|
Time.now.usec.to_s
|
|
end
|
|
|
|
def in_sessiondb
|
|
@db.transaction do
|
|
yield(@db["root"])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
status = AuthHeaderPortServer.new('AuthHeaderPortServer', nil).start
|