userPrincipal = new SimplePrincipal(connectionUser.getName());
} else {
throw new IllegalStateException("Token authentication requested but no user on connection found.");
}
ContextStateCache stateCache = null;
try {
if (userPrincipal != null && connectionUser != null && authToken != null) {
try {
// We have been requested to use an authentication token
// so now we attempt the switch.