user = ApplicationUtil.getUser(objectModel);
} else {
final Request req = ObjectModelHelper.getRequest(objectModel);
Session session = req.getSession(false);
final Application app = this.getApplication(appName);
LoginInfo info = null;
Map loginInfos = null;
if ( session != null ) {
// is the user already logged in on the security handler?
loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
if ( loginInfos != null
&& loginInfos.containsKey(app.getSecurityHandler().getId()) ) {
info = (LoginInfo)loginInfos.get(app.getSecurityHandler().getId());
user = info.user;
}
}
if ( user == null ) {
user = app.getSecurityHandler().login(loginContext);
if ( user != null ) {
// create new login info
session = req.getSession();
loginInfos = (Map)session.getAttribute(LOGIN_INFO_KEY);
if ( loginInfos == null ) {
loginInfos = new HashMap();
}
info = new LoginInfo(user);
loginInfos.put(app.getSecurityHandler().getId(), info);
}
}
// user can be null, if login failed
if ( user != null ) {
info.incUsageCounter(appName);
session.setAttribute(LOGIN_INFO_KEY, loginInfos);
// set the user in the session
session.setAttribute(USER + '-' + appName, user);
objectModel.put(ApplicationManager.USER, user);
// set the application in the object model
objectModel.put(ApplicationManager.APPLICATION, app);
// notify the application
app.userDidLogin(user, loginContext);
// set the application data in the session
Object data = ObjectUtils.NULL;
if ( app.getApplicationStore() != null ) {
data = app.getApplicationStore().loadApplicationData(user, app);
}
session.setAttribute(APPLICATION_KEY_PREFIX + appName, data);
objectModel.put(ApplicationManager.APPLICATION_DATA, data);
// notify application
app.userIsAccessing(user);
}
}
return user;
}