Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/trunk/sample/soapheader/authheader/server.rb

Revision 1843, 1.6 kB (checked in by nahi, 2 years ago)
  • reorganize sampless
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 #!/usr/bin/env ruby
2
3 require 'soap/rpc/standaloneServer'
4 require 'soap/header/simplehandler'
5 require 'authmgr'
6
7 class AuthHeaderPortServer < SOAP::RPC::StandaloneServer
8   class AuthHeaderService
9     def self.create
10       new
11     end
12
13     def deposit(amt)
14       "deposit #{amt} OK"
15     end
16
17     def withdrawal(amt)
18       "withdrawal #{amt} OK"
19     end
20   end
21
22   Name = 'http://tempuri.org/authHeaderPort'
23   def initialize(*arg)
24     super
25     add_rpc_servant(AuthHeaderService.new, Name)
26     # header handler must be a per request handler.
27     add_request_headerhandler(ServerAuthHeaderHandler)
28   end
29
30   class ServerAuthHeaderHandler < SOAP::Header::SimpleHandler
31     MyHeaderName = XSD::QName.new("http://tempuri.org/authHeader", "auth")
32
33     @authmgr = Authmgr.new
34     def self.create
35       new(@authmgr)
36     end
37
38     def initialize(authmgr)
39       super(MyHeaderName)
40       @authmgr = authmgr
41       @userid = @sessionid = nil
42     end
43
44     def on_simple_outbound
45       { "sessionid" => @sessionid }
46     end
47
48     def on_simple_inbound(my_header, mu)
49       auth = false
50       userid = my_header["userid"]
51       passwd = my_header["passwd"]
52       if @authmgr.login(userid, passwd)
53         auth = true
54       elsif sessionid = my_header["sessionid"]
55         if userid = @authmgr.auth(sessionid)
56           @authmgr.destroy_session(sessionid)
57           auth = true
58         end
59       end
60       raise RuntimeError.new("authentication failed") unless auth
61       @userid = userid
62       @sessionid = @authmgr.create_session(userid)
63     end
64   end
65 end
66
67 if $0 == __FILE__
68   svr = AuthHeaderPortServer.new('AuthHeaderPortServer', nil, '0.0.0.0', 7000)
69   trap(:INT) do
70     svr.shutdown
71   end
72   status = svr.start
73 end
Note: See TracBrowser for help on using the browser.