2014-11-06 2 views
0

Я создал два проекта Grails, один для серверной стороны CxF веб-службы и другие для CxF клиента для вызова веб-службы ..Как добавить безопасности (имя пользователя, пароль) Grails CxF веб-сервис

Все отлично работает.

Я могу вызвать веб-сервис из кода клиента и получить результат.

Теперь я хочу добавить безопасность, то каковы будут изменения в коде сервера и клиента grails?

Я попытался применить безопасность, как сказал Кристиан Острийх в своем посте.

http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/ (Grails CxF перехватчик Injection 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); 
Смежные вопросы