2014-11-06 60 views
0

我創建了兩個Grails項目,一個用於服務器端CXF Web服務等爲CXF客戶端調用Web服務..如何添加安全性(用戶名,密碼)的Grails

一切正常CXF Web服務。

我可以從客戶端代碼調用Web服務並獲得結果。

現在我想添加安全性,那麼服務器和客戶端grails代碼會發生什麼變化?

我試過應用安全性,如Christian Oestreich在他的帖子中所說的那樣。

http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/ (Grails的CXF攔截注射的2.4.x-2.5.X)應用安全是如下

ExampleService exampleService = new ExampleService() 
    def port = exampleService.exampleServicePort 
    Map ctx = ((BindingProvider)port).getRequestContext(); 
    ctx.put("ws-security.username", "pankaj"); 
    ctx.put("ws-security.password", "pankaj"); 
    println ".......... " + port.sayHello("pankaj") 

但我如下

Error | 
2014-11-06 18:33:15,411 [http-bio-8088-exec-4] ERROR errors.GrailsExceptionResolver - SoapFault occurred when processing request: [GET] /WSDLDemoClient/wsdldemo/index 
An error was discovered processing the <wsse:Security> header.. Stacktrace follows: 
Message: An error was discovered processing the <wsse:Security> header. 
Line | Method 
->> 75 | unmarshalFault   in org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor 
得到錯誤

和客戶端代碼

回答

0

而不是上面提到的客戶端代碼,使用下面的代碼來使它工作。

Map<String, Object> req_ctx = ((BindingProvider)hello).getRequestContext(); 
    req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL); 

    Map<String, List<String>> headers = new HashMap<String, List<String>>(); 
    headers.put("Username", Collections.singletonList("pankaj")); 
    headers.put("Password", Collections.singletonList("pankaj")); 
    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers); 
相關問題