Ciò imposterà il nome utente e la password per l'autenticazione HTTP di base. Se lo hai testato in SoapUI, suppongo che il valore "PasswordText" di cui parli sia il "Tipo di password WSS" nel riquadro dei dettagli della richiesta. Questo imposta la sicurezza WSS, non la sicurezza HTTP.
Con JAX-WS in Java6 è necessario collegare un SOAPHandler per iniettare il token WSS-User nell'header SOAP. Ci sono un sacco di bit su questo giro della rete, ma non ho trovato un singolo link per postare, quindi ecco un po 'di codice invece di farti andare ...
Per aggiungere un gestore hai bisogno di qualcosa del tipo:
final Binding binding = ((BindingProvider) servicePort).getBinding();
List<Handler> handlerList = binding.getHandlerChain();
if (handlerList == null)
handlerList = new ArrayList<Handler>();
handlerList.add(new SecurityHandler());
binding.setHandlerChain(handlerList); // <- important!
Quindi la classe SecurityHandler farà l'atto. Gli handler sono cose generali e vengono richiamati sia per i messaggi di successo che per i guasti, ma forse più importante vengono chiamati in entrambe le direzioni del messaggio - per la richiesta in uscita e poi di nuovo per la risposta in arrivo. Vuoi solo gestire i messaggi in uscita. Quindi avrete bisogno di qualcosa di simile:
public final class SecurityHandler implements SOAPHandler<SOAPMessageContext> {
...
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
// Indicator telling us which direction this message is going in
final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
// Handler must only add security headers to outbound messages
if (outInd.booleanValue()) {
try {
// Get the SOAP Envelope
final SOAPEnvelope envelope = msgCtx.getMessage().getSOAPPart().getEnvelope();
// Header may or may not exist yet
SOAPHeader header = envelope.getHeader();
if (header == null)
header = envelope.addHeader();
// Add WSS Usertoken Element Tree
final SOAPElement security = header.addChildElement("Security", "wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
final SOAPElement userToken = security.addChildElement("UsernameToken", "wsse");
userToken.addChildElement("Username", "wsse").addTextNode("MyWSSUsername");
userToken.addChildElement("Password", "wsse").addTextNode("MyWSSPassword");
} catch (final Exception e) {
LOG.error(e);
return false;
}
}
return true;
}
...
// Other required methods on interface need no guts
}
che ho fatto un paio di ipotesi qui, ma si spera che ti farti andare!
Cordiali saluti.
Grazie. Questo ha funzionato perfettamente e la tua risposta è stata quasi impossibile da trovare su Google, quindi consentimi di aggiungere alcune parole chiave. JAX-WS WSSE – Jimmy2Times
Quando si utilizza questo codice ho ottenuto la seguente eccezione in log: 'com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl addChildElement SEVERE: SAAJ0101: Il padre di un SOAPBodyElement deve essere un SOAPBody'. – Vic