Session session = request.getSessionInternal(false);
if (session != null) {
if (changeSessionIdOnAuthentication) {
Manager manager = request.getContext().getManager();
manager.changeSessionId(session);
request.changeSessionId(session.getId());
}
} else if (alwaysUseSession) {
session = request.getSessionInternal(true);
}