java - Клиент Apache CXF и ws-Security - SecurityTokenReference - PullRequest
0 голосов
/ 03 августа 2020

Я использую WSDL, но запрос soap неверен. Часть запроса soap, которую необходимо исправить, выглядит так:

<ds:KeyInfo Id="KI-XXXXXXXXX">
    <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STR-a7a2dbe9-9d34-4e2d-bbe6-b6ed265bd41d">
        <wsse:Reference URI="#X509-4e15d312-eab9-4738-84dd-4307afcde72f" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
</ds:KeyInfo>

Вместо:

<ds:KeyInfo Id="KI-XXXXXXXXX">
    <wsse:SecurityTokenReference wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" wsu:Id="STR-a7a2dbe9-9d34-4e2d-bbe6-b6ed265bd41d" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
        <wsse:Reference URI="#X509-4e15d312-eab9-4738-84dd-4307afcde72f" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
    </wsse:SecurityTokenReference>
</ds:KeyInfo>

используйте xmlns: wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" вместо xmlns: wsse11 = «http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd» и отсутствует атрибут wsse11: TokenType.

BaseWsService service = new BaseWsService();
BaseWsPortType port = service.getBaseWsPort();
Map<String, Object> rq = ((BindingProvider) port).getRequestContext();
rq.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, sEndPoint);
Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
rq.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE + " ");
rq.put(WSHandlerConstants.SIG_PROP_FILE, "properties/client_sec.properties");
rq.put(WSHandlerConstants.PW_CALLBACK_CLASS, UsernamePasswordCallback.class.getName());
rq.put(WSHandlerConstants.SIG_ALGO, "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
rq.put(WSHandlerConstants.USER, "myAlias");
rq.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
rq.put(WSHandlerConstants.SIGNATURE_PARTS, "{}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{}{http://schemas.xmlsoap.org/soap/envelope/}Body;{}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}BinarySecurityToken;");
rq.put(WSHandlerConstants.ENC_PROP_FILE, "properties/client_sec.properties");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(rq);
wssOut.getProperties().put(WSHandlerConstants.MUST_UNDERSTAND, "0");
cxfEndpoint.getOutInterceptors().add(wssOut);
             
CalculateInput calc = new  CalculateInput();
calc.setId(15);
CalculateResponse response = port.calculate(calc);

Как установить пространства имен для ссылочного токена?

...