1

尽管我设置了username, password, action, and WS Security Password Type (which is PasswordText),但当我尝试调用 Web 服务的服务时得到此异常:No security action was defined. 我尝试与之通信的 Web 服务Basic Authentication使用PasswordTextWS 安全密码类型。

这是我尝试过的:

    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);

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

ps 使用Apache CXF 3.1.12可用的最新版本。

4

2 回答 2

1

代码中的问题是您正在尝试调用 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");

您可以在此处找到完整的代码示例。

于 2018-03-22T01:07:26.520 回答
0

您是否将安全拦截器添加到 bean.xml?

<bean id="securityInterceptor" class="...BasicAuthAuthorizationInterceptor">
</bean>

    <jaxrs:server id="..." address="/">
        <jaxrs:serviceBeans>
            <ref bean="bean" />
        </jaxrs:serviceBeans>

        <jaxrs:inInterceptors>
            <ref bean="securityInterceptor" />
        </jaxrs:inInterceptors>

    </jaxrs:server>
于 2017-07-24T11:29:03.180 回答