updateAddressPort(bearerPort, PORT);
if (standalone) {
TokenTestUtils.updateSTSPort((BindingProvider)bearerPort, STSPORT2);
}
TokenStore tokenStore = new MemoryTokenStore();
((BindingProvider)bearerPort).getRequestContext().put(
TokenStore.class.getName(), tokenStore
);
// Make a successful invocation
((BindingProvider)bearerPort).getRequestContext().put(
"ws-security.username", "alice"
);
doubleIt(bearerPort, 25);
// Change the STSClient so that it can no longer find the STS
STSClient stsClient = new STSClient(bus);
stsClient.setOnBehalfOf(new WSSUsernameCallbackHandler());
BindingProvider p = (BindingProvider)bearerPort;
p.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
// This invocation should be successful as the token is cached
doubleIt(bearerPort, 25);
//
// Proxy no. 2
//
DoubleItPortType bearerPort2 =
service.getPort(portQName, DoubleItPortType.class);
updateAddressPort(bearerPort2, PORT);
if (standalone) {
TokenTestUtils.updateSTSPort((BindingProvider)bearerPort2, STSPORT2);
}
// Change the STSClient so that it can no longer find the STS
stsClient = new STSClient(bus);
stsClient.setOnBehalfOf(new WSSUsernameCallbackHandler());
p = (BindingProvider)bearerPort2;
p.getRequestContext().put(SecurityConstants.STS_CLIENT, stsClient);
// This should fail as the cache is not being used
try {
doubleIt(bearerPort2, 40);
fail("Failure expected as the token is not stored in the cache");
} catch (Exception ex) {
// expected
}
// Set the cache correctly
p.getRequestContext().put(TokenStore.class.getName(), tokenStore);
// Make another invocation - this should succeed as the token is cached
p.getRequestContext().put("ws-security.username", "alice");
doubleIt(bearerPort2, 40);
// Reset the cache - this invocation should fail
p.getRequestContext().put(TokenStore.class.getName(), new MemoryTokenStore());
p.getRequestContext().put(SecurityConstants.TOKEN, new SecurityToken());
try {
doubleIt(bearerPort2, 40);
fail("Failure expected as the cache is reset");
} catch (Exception ex) {