_timeStarted = new Timestamp(System.currentTimeMillis());
_timeCompleted = null;
setApplicationContext(ApplicationContext.getInstance());
ApplicationConfiguration config = getApplicationContext().getConfiguration();
setConnectionBroker(new ConnectionBroker(config.getDatabaseReferences()));
setUser(new User());
boolean bWasUserInSession = false;
if (request instanceof HttpServletRequest) {
HttpServletRequest httpReq = (HttpServletRequest)request;
HttpSession sn = httpReq.getSession(true);
User user = (User)sn.getAttribute(USERKEY);
if (user == null) {
sn.setAttribute(USERKEY,getUser());
} else {
bWasUserInSession = true;
setUser(user);
}
user = getUser();
// check for single sign-on
if (getIdentityConfiguration().getSingleSignOnMechanism().getActive()) {
if (Val.chkStr(user.getKey()).startsWith("urn:openid:")) return;
String sPrevious = user.getName();
String sUsername = getIdentityConfiguration().getSingleSignOnMechanism().determineUsername(httpReq);
if (!sPrevious.equals(sUsername)) {
if (bWasUserInSession) {
setUser(new User());
sn.setAttribute(USERKEY,getUser());
user = getUser();
}
if (sUsername.length() > 0) {
user.setCredentials(new UsernameCredential(sUsername));
try {
newIdentityAdapter().authenticate(user);
} catch (Exception e) {
String sMsg = "An error occured while evaluating single sign-on credentials for: "+sUsername;
setUser(new User());
sn.setAttribute(USERKEY,getUser());
getLogger().log(Level.SEVERE,sMsg,e);
} finally {
this.getConnectionBroker().closeAll();
}