Search in sources :

Example 46 with MCRSession

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");
}
Also used : MCRSession(org.mycore.common.MCRSession)

Example 47 with MCRSession

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);
                }
            }
        }
    }
}
Also used : MCRSession(org.mycore.common.MCRSession)

Example 48 with MCRSession

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();
    }
}
Also used : MCRSession(org.mycore.common.MCRSession)

Example 49 with MCRSession

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);
}
Also used : MCRException(org.mycore.common.MCRException) MCRSession(org.mycore.common.MCRSession) MCRUserInformation(org.mycore.common.MCRUserInformation)

Example 50 with MCRSession

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MCRSession(org.mycore.common.MCRSession) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

MCRSession (org.mycore.common.MCRSession)63 IOException (java.io.IOException)15 MCRUserInformation (org.mycore.common.MCRUserInformation)10 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)10 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SignedJWT (com.nimbusds.jwt.SignedJWT)5 Date (java.util.Date)5 EntityManager (javax.persistence.EntityManager)5 Path (java.nio.file.Path)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)4 SAXException (org.xml.sax.SAXException)4 UnknownHostException (java.net.UnknownHostException)3 Document (org.jdom2.Document)3 MCRAccessException (org.mycore.access.MCRAccessException)3 MCRException (org.mycore.common.MCRException)3 MCRPersistenceException (org.mycore.common.MCRPersistenceException)3 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)3 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)3