gpt4 book ai didi

java - Apache CXF - javax.xml.ws.soap.SOAPFaultException : No security action was defined

转载 作者:行者123 更新时间:2023-11-30 06:35:20 28 4
gpt4 key购买 nike

尽管我已经设置了用户名密码操作WS安全密码类型(即PasswordText),当我尝试调用 Web 服务的服务时出现此异常:未定义安全操作。我尝试通信的 Web 服务使用 Basic AuthenticationPasswordText WS 安全密码类型。

这是我尝试过的:

    Map<String, Object> ctx = ((BindingProvider) basicHttpBindingIDeneme).getRequestContext();
ctx.put("ws-security.username", USERNAME);
ctx.put("ws-security.password", PASSWORD);

Map<String,Object> inProps = new HashMap<String,Object>();
inProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
inProps.put(WSHandlerConstants.ACTION, "UsernameToken");
WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(basicHttpBindingIDeneme);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getInInterceptors().add(wssIn);

Map<String,Object> outProps = new HashMap<String,Object>();
// how to configure the properties is outlined below;

WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);

为了定义安全操作,我还需要配置什么?

附:使用 Apache CXF 3.1.12 这是最新的可用版本。

最佳答案

代码中的问题是您尝试调用 Web 服务,并且您添加的属性在 WSS4JInInterceptor 中设置,而不是在 WSS4JOutInterceptor 中设置。

属性的定义应与此类似。

 Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put("action", "UsernameToken");
outProps.put("user", "yourUser");
outProps.put("passwordCallbackClass","com.example.PasswordCallback");

您可以找到完整的代码示例 here .

关于java - Apache CXF - javax.xml.ws.soap.SOAPFaultException : No security action was defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45279055/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com