SecurityPolicyTest.class.getResource("alice.properties").toString());
}
@Test
public void testPolicy() throws Exception {
DoubleItService service = new DoubleItService();
DoubleItPortType pt;
pt = service.getDoubleItPortXPath();
updateAddressPort(pt, PORT);
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
new KeystorePasswordCallback());
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
getClass().getResource("alice.properties"));
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
getClass().getResource("bob.properties"));
assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
pt = service.getDoubleItPortEncryptThenSign();
updateAddressPort(pt, PORT);
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
new KeystorePasswordCallback());
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
getClass().getResource("alice.properties"));
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
getClass().getResource("bob.properties"));
pt.doubleIt(BigInteger.valueOf(5));
pt = service.getDoubleItPortSign();
updateAddressPort(pt, PORT);
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
new KeystorePasswordCallback());
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
getClass().getResource("alice.properties"));
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
getClass().getResource("bob.properties"));
pt.doubleIt(BigInteger.valueOf(5));
pt = service.getDoubleItPortSignThenEncrypt();
updateAddressPort(pt, PORT);
((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
new KeystorePasswordCallback());
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
getClass().getResource("alice.properties"));
((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
getClass().getResource("bob.properties"));
pt.doubleIt(BigInteger.valueOf(5));
((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
POLICY_SIGNENC_PROVIDER_ADDRESS);
int x = pt.doubleIt(BigInteger.valueOf(5)).intValue();
assertEquals(10, x);
pt = service.getDoubleItPortHttps();
updateAddressPort(pt, SSL_PORT);
try {
pt.doubleIt(BigInteger.valueOf(25));
} catch (Exception ex) {
String msg = ex.getMessage();
if (!msg.contains("sername")) {
throw ex;
}
}
((BindingProvider)pt).getRequestContext().put(SecurityConstants.USERNAME, "bob");
((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");
((BindingProvider)pt).getRequestContext().put(SecurityConstants.PASSWORD, "pwd");
pt.doubleIt(BigInteger.valueOf(25));
try {
pt = service.getDoubleItPortHttp();
updateAddressPort(pt, PORT);
pt.doubleIt(BigInteger.valueOf(25));
fail("https policy should have triggered");
} catch (Exception ex) {
String msg = ex.getMessage();