Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 如何向grails cxf web服务添加安全性(用户名、密码)_Web Services_Security_Grails_Cxf - Fatal编程技术网

Web services 如何向grails cxf web服务添加安全性(用户名、密码)

Web services 如何向grails cxf web服务添加安全性(用户名、密码),web-services,security,grails,cxf,Web Services,Security,Grails,Cxf,我创建了两个grails项目,一个用于服务器端cxf web服务,另一个用于调用web服务的cxf客户端 一切正常 我可以从客户机代码调用web服务并得到结果 现在我想添加安全性,那么对服务器和客户端grails代码的更改是什么 我试着应用Christian Oestreich在他的帖子中所说的安全措施 (Grails Cxf拦截器注入2.4.x-2.5.x) 应用安全性的客户端代码如下 ExampleService exampleService = new ExampleServic

我创建了两个grails项目,一个用于服务器端cxf web服务,另一个用于调用web服务的cxf客户端

一切正常

我可以从客户机代码调用web服务并得到结果

现在我想添加安全性,那么对服务器和客户端grails代码的更改是什么

我试着应用Christian Oestreich在他的帖子中所说的安全措施

(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
但我得到的错误如下

    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
错误|
2014-11-06 18:33:15411[http-bio-8088-exec-4]错误。GrailExceptionResolver-处理请求[GET]/WSDLDemoClient/wsdldemo/index时发生SoapFault
处理标头时发现错误。。跟踪如下:
消息:处理标头时发现错误。
直线法
->>75 |在org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor中解组错误

使用以下代码使其工作,而不是上述客户机代码

    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);
Map req_ctx=((BindingProvider)hello).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_属性,WS_URL);
Map headers=newhashmap();
headers.put(“用户名”,Collections.singletonList(“pankaj”);
headers.put(“密码”、Collections.singletonList(“pankaj”);
req_ctx.put(MessageContext.HTTP_请求_头,头);