public static void handleLogin(HttpServletRequest req, HttpServletResponse resp, OAuthConsumer oauthConsumer) throws OAuthException, IOException {
if (oauthConsumer == null || OAuthUtils.isEmpty(oauthConsumer.getIdentifier())) {
throw new OAuthException("There is no Orion account associated with this Id. Please register or contact your system administrator for assistance.");
}
String redirect = oauthConsumer.getRedirect();
UserInfo userInfo = getUser(oauthConsumer);
if (userInfo == null) {
if (!FormAuthHelper.canAddUsers()) {
throw new OAuthException("There is no Orion account associated with this Id. Please register or contact your system administrator for assistance.");
}
String url = "/mixloginstatic/LoginWindow.html";
url += "?oauth=create&email=" + oauthConsumer.getEmail();
url += "&username=" + oauthConsumer.getUsername();
url += "&identifier=" + oauthConsumer.getIdentifier();
if (redirect != null)
url += "&redirect=" + redirect;
resp.sendRedirect(url);
return;
}
String login = userInfo.getUniqueId();
req.getSession().setAttribute("user", login); //$NON-NLS-1$
Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.login"); //$NON-NLS-1$
if (logger.isInfoEnabled()) {
logger.info("Login success: " + login + " oauth " + oauthConsumer.getIdentifier()); //$NON-NLS-1$
}
if (getEventService() != null) {
JSONObject message = new JSONObject();
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
Date date = new Date(System.currentTimeMillis());
message.put("event", "login");
message.put("published", format.format(date));
message.put("user", userInfo.getUniqueId());
} catch (JSONException e1) {
LogHelper.log(e1);
}
getEventService().publish("orion/login", message);
}
try {
// try to store the login timestamp in the user profile
userInfo.setProperty(UserConstants2.LAST_LOGIN_TIMESTAMP, new Long(System.currentTimeMillis()).toString());
OrionConfiguration.getMetaStore().updateUser(userInfo);
} catch (CoreException e) {
// just log that the login timestamp was not stored
LogHelper.log(e);
}