use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRCommandLineInterface method showSessionDuration.
private static void showSessionDuration() {
MCRSession session = MCRSessionMgr.getCurrentSession();
long duration = System.currentTimeMillis() - session.getLoginTime();
output("Session duration: " + duration + " ms");
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRFrontendUtil method putParamsToSession.
private static void putParamsToSession(HttpServletRequest request) {
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements(); ) {
String name = e.nextElement();
if (name.startsWith("XSL.") && name.endsWith(".SESSION")) {
String key = name.substring(0, name.length() - 8);
// parameter is not empty -> store
if (!request.getParameter(name).trim().equals("")) {
mcrSession.put(key, request.getParameter(name));
LOGGER.debug("Found HTTP-Req.-Parameter {}={} that should be saved in session, safed {}={}", name, request.getParameter(name), key, request.getParameter(name));
} else // paramter is empty -> do not store and if contained in
// session, remove from it
{
if (mcrSession.get(key) != null) {
mcrSession.deleteObject(key);
}
}
}
}
for (Enumeration<String> e = request.getAttributeNames(); e.hasMoreElements(); ) {
String name = e.nextElement();
if (name.startsWith("XSL.") && name.endsWith(".SESSION")) {
String key = name.substring(0, name.length() - 8);
// attribute is not empty -> store
if (!request.getAttribute(name).toString().trim().equals("")) {
mcrSession.put(key, request.getAttribute(name));
LOGGER.debug("Found HTTP-Req.-Attribute {}={} that should be saved in session, safed {}={}", name, request.getParameter(name), key, request.getParameter(name));
} else // attribute is empty -> do not store and if contained in
// session, remove from it
{
if (mcrSession.get(key) != null) {
mcrSession.deleteObject(key);
}
}
}
}
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRLanguageFactory method readLanguageClassification.
/**
* Reads in the language classification and builds language objects from its categories
*/
private void readLanguageClassification() {
MCRSession session = MCRSessionMgr.getCurrentSession();
if (!session.isTransactionActive()) {
session.beginTransaction();
buildLanguagesFromClassification();
session.commitTransaction();
} else {
buildLanguagesFromClassification();
}
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRUserManager method setPassword.
/**
* Sets password of 'user' to 'password'.
*
* Automatically updates the user in database.
*/
public static void setPassword(MCRUser user, String password) {
MCRSession session = MCRSessionMgr.getCurrentSession();
MCRUserInformation currentUser = session.getUserInformation();
// only update password
MCRUser myUser = getUser(user.getUserName(), user.getRealmID());
boolean allowed = MCRAccessManager.checkPermission(MCRUser2Constants.USER_ADMIN_PERMISSION) || currentUser.equals(myUser.getOwner()) || (currentUser.equals(user) && myUser.hasNoOwner() || !myUser.isLocked());
if (!allowed) {
throw new MCRException("You are not allowed to change password of user: " + user);
}
updatePasswordHashToSHA256(myUser, password);
updateUser(myUser);
}
use of org.mycore.common.MCRSession in project mycore by MyCoRe-Org.
the class MCRServlet3LoginServlet method think.
@Override
protected void think(MCRServletJob job) throws Exception {
HttpServletRequest req = job.getRequest();
HttpServletResponse res = job.getResponse();
if (LOCAL_LOGIN_SECURE_ONLY && !req.isSecure()) {
res.sendError(HttpServletResponse.SC_FORBIDDEN, getErrorI18N("component.user2.login", "httpsOnly"));
return;
}
String uid = getProperty(req, "uid");
String pwd = getProperty(req, "pwd");
String realm = getProperty(req, "realm");
if (uid != null && pwd != null) {
MCRSession session = MCRSessionMgr.getCurrentSession();
req.login(uid, pwd);
session.setUserInformation(new Servlet3ContainerUserInformation(session, realm));
req.getSession().setAttribute(MCRRequestAuthenticationFilter.SESSION_KEY, Boolean.TRUE);
LOGGER.info("Logged in: {}", session.getUserInformation().getUserID());
}
}
Aggregations