2011-01-07 40 views

回答

13

不是直接。唯一的方法是創建一個身份驗證方法,在服務器上創建一個(臨時)密鑰,然後更改所有方法,以便第一個參數是該密鑰,並且它們還會引發未驗證的錯誤。例如:

exception NotAuthorisedException { 
    1: string errorMessage, 
} 

exception AuthTimeoutException { 
    1: string errorMessage, 
} 

service MyAuthService { 
    string authenticate(1:string user, 2:string pass) 
     throws (1:NotAuthorisedException e), 

    string mymethod(1:string authstring, 2:string otherargs, ...) 
     throws (1:AuthTimeoutException e, ...), 
} 

我們用這種方法和我們的鑰匙保存到一個安全的memcached實例與30分鐘超時鍵把一切都「活潑」。預計收到AuthTimeoutException的客戶將重新授權並重試,並且我們有一些防火牆規則來阻止強力攻擊。

+0

您以明文形式通過網絡發送的密碼生成的? – JensG 2013-08-25 13:15:50

1

類似自動化和權限的任務不被視爲Thrift的一部分,主要是因爲這些東西(通常)更多地與應用程序邏輯相關,而不是一般的RPC /序列化概念。 Thrift現在支持的唯一的東西是TSASLTransport。我自己也不能多說這個,只是因爲我從來沒有覺得需要使用它。

另一種選擇可能是利用THeaderTransport,不幸的是在編寫本文時只能用C++實現。因此,如果您打算使用其他語言,則可能需要投入一些額外的工作。不用說,我們接受貢獻......

0

有點晚(我想很晚),但幾年前我已經修改了Thrift源代碼。

剛剛爲此提交了一張帶有修補程序的票據https://issues.apache.org/jira/browse/THRIFT-4221

看看那個。基本上建議是添加一個「BeforeAction」鉤子來完成。

例Golang差異

+  // Called before any other action is called 
+  BeforeAction(serviceName string, actionName string, args map[string]interface{}) (err error) 
+  // Called if an action returned an error 
+  ProcessError(err error) error 
} 

type MyServiceClient struct { 
@@ -391,7 +395,12 @@ func (p *myServiceProcessorMyMethod) Process(seqId int32, iprot, oprot thrift.TP 
     result := MyServiceMyMethodResult{} 
     var retval string 
     var err2 error 
-  if retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_); err2 != nil { 
+  err2 = p.handler.BeforeAction("MyService", "MyMethod", map[string]interface{}{"AuthString": args.AuthString, "OtherArgs_": args.OtherArgs_}) 
+  if err2 == nil { 
+    retval, err2 = p.handler.MyMethod(args.AuthString, args.OtherArgs_) 
+  } 
+  if err2 != nil { 
+    err2 = p.handler.ProcessError(err2)