首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CXF Webservice Server将请求凭据委托给内部Webservice调用

CXF Webservice Server将请求凭据委托给内部Webservice调用
EN

Stack Overflow用户
提问于 2014-02-26 15:30:14
回答 1查看 779关注 0票数 0

如何将凭据(basic auth)从一个获取请求传递到另一个Webservice的新请求?

我没有找到任何可以在一个请求中在拦截器之间共享数据的属性包。

为求澄清:

  • 具有基本auth cred >请求-> WS-1的客户端
  • ** WS-1 ->请求-> WS-2并从原始客户端传递凭据
  • ** WS-1 ->请求-> WS-3 (没有with)
  • WS-1 ->响应->客户端
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-28 15:57:39

希望通过这个解决方案,我不会一秒跑。麻烦?

我所做的:

添加inInterceptor、读出凭据和远程ip

代码语言:javascript
复制
    AuthorizationPolicy policy = message.get(AuthorizationPolicy.class);

    if (policy == null) {
        sendErrorResponse(message, HttpURLConnection.HTTP_UNAUTHORIZED);
        return;
    }


    message.put("request_usr", policy.getUserName());
    message.put("request_pwd", policy.getPassword());

操作CXF生成的WebServiceClient来更改构造器返回值,如

代码语言:javascript
复制
/**
 * 
 * @return returns WebServiceClass
 */
@WebEndpoint(name = "WebServiceClassSoap")
public WebServiceClassSoap getWebServiceClassSoap() {
    return dynamicAuthorisation(super.getPort(WebServiceClassSoap,
            WebServiceClassSoap.class));
} 

private WebServiceClassSoap  dynamicAuthorisation (WebServiceClassSoap  service) {
    return dynamicAuthorisation(service, 
                PhaseInterceptorChain.getCurrentMessage().get("request_usr").toString(),
                PhaseInterceptorChain.getCurrentMessage().get("request_pwd").toString());
}


private WebServiceClassSoap  dynamicAuthorisation (WebServiceClassSoap  service, String username, String password) {

    Client client = ClientProxy.getClient(service);
    HTTPConduit http = (HTTPConduit) client.getConduit();

    AuthorizationPolicy auth = http.getAuthorization();

    auth.setUserName(username);
    auth.setPassword(password);

    http.setAuthorization(auth);

    return service;
}

离开http-conf: beans.xml中的管道

代码语言:javascript
复制
    <http-conf:conduit name="{http://schemas.foobar.com/websvc/WebServiceClass/}WebServiceClassSoap.http-conduit">
        <http-conf:authorization>
                <!-- 
                <sec:UserName>${webservices.username}@${webservices.domain}</sec:UserName>
                <sec:Password>${webservices.password}</sec:Password>
                -->
                <sec:AuthorizationType>Basic</sec:AuthorizationType>
        </http-conf:authorization>
        <http-conf:client AllowChunking="false" ConnectionTimeout="30000" />            
</http-conf:conduit>

感谢Apache CXF: Forwarding an information from an interceptor to the actual webservice implementation =)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22045926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档