request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException uee) {
log.error("Unable to set UTF-8 character encoding!", uee);
}
final IPersonManager personManager = PersonManagerFactory.getPersonManagerInstance();
// Clear out the existing session for the user if they have one
String targetUid = null;
String originalUid = null;
boolean swap = false;
if (request.isRequestedSessionIdValid()) {
try {
HttpSession s = request.getSession(false);
//Check if this is a swapped user hitting the Login servlet
originalUid = (String)s.getAttribute(SWAP_ORIGINAL_UID);
//No original person in session so check for swap request
if (originalUid == null) {
targetUid = (String)s.getAttribute(SWAP_TARGET_UID);
if (targetUid != null) {
final IPerson person = personManager.getPerson(request);
originalUid = person.getName();
swap = true;
}
}
else {
final IPerson person = personManager.getPerson(request);
targetUid = person.getName();
}
s.invalidate();
} catch (IllegalStateException ise) {
// ISE indicates session was already invalidated.
// This is fine. This servlet trying to guarantee that the session has been invalidated;
// it doesn't have to insist that it is the one that invalidated it.
if (log.isTraceEnabled()) {
log.trace("LoginServlet attempted to invalidate an already invalid session.", ise);
}
}
}
// Create the user's session
HttpSession s = request.getSession(true);
IPerson person = null;
try {
final HashMap principals;
final HashMap credentials;
// Get the person object associated with the request
person = personManager.getPerson(request);
//If doing an identity swap
if (targetUid != null && originalUid != null) {
if (swap) {
swapperLog.warn("Swapping identity for '" + originalUid + "' to '" + targetUid + "'");