}
public void testSignatureRoundtrip() throws Exception {
SoapMarshaler marshaler = new SoapMarshaler(true, true);
SoapMessage msg = new SoapMessage();
Context ctx = new Context();
ctx.setInMessage(msg);
msg.setSource(new StringSource("<hello>world</hello>"));
SoapWriter writer = marshaler.createWriter(ctx.getInMessage());
W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter();
writer.writeSoapEnvelope(domWriter);
ctx.getInMessage().setDocument(domWriter.getDocument());
StandaloneCrypto crypto = new StandaloneCrypto();
crypto.setKeyStoreUrl(new ClassPathResource("privatestore.jks"));
crypto.setKeyStorePassword("keyStorePassword");
WSSecurityHandler handler = new WSSecurityHandler();
handler.setAuthenticationService(new JAASAuthenticationService());
handler.setCrypto(crypto);
handler.setUsername("myalias");
crypto.setKeyPassword("myAliasPassword");
handler.setSendAction(WSHandlerConstants.SIGNATURE);
handler.onSend(ctx);
Document doc = ctx.getInMessage().getDocument();
log.info(DOMUtil.asXML(doc));
handler.setReceiveAction(WSHandlerConstants.SIGNATURE);
handler.onReceive(ctx);
List l = (List) ctx.getProperty(WSHandlerConstants.RECV_RESULTS);
assertNotNull(l);
assertEquals(1, l.size());
WSHandlerResult result = (WSHandlerResult) l.get(0);
assertNotNull(result);
assertNotNull(result.getResults());
assertEquals(1, result.getResults().size());
WSSecurityEngineResult engResult = (WSSecurityEngineResult) result.getResults().get(0);
assertNotNull(engResult);
Principal principal = engResult.getPrincipal();
assertNotNull(principal);
assertEquals("CN=myAlias", principal.getName());
assertNotNull(ctx.getInMessage().getSubject());
assertNotNull(ctx.getInMessage().getSubject().getPrincipals());
assertTrue(ctx.getInMessage().getSubject().getPrincipals().size() > 0);
}