protected void afterRequest(HttpServletRequest req, HttpServletResponse resp) { MCRSessionMgr.getCurrentSession().commitTransaction(); MCRSessionMgr.releaseCurrentSession(); }
private static MCRException reportParseException(String encoding, String text, ParseException ex) { String msg = "Unable to parse MODS date encoded " + encoding + " " + text; return new MCRException(msg, ex); } }
@Override public String getUserAttribute(String attribute) { return this.userInfo.getUserAttribute(attribute); }
private static boolean checkUserIsNotNull(HttpServletResponse res, MCRUser currentUser, String userID) throws IOException { if (currentUser == null) { String uid = userID == null ? MCRSessionMgr.getCurrentSession().getUserInformation().getUserID() : userID; String msg = MCRTranslation.translate("component.user2.UserServlet.currentUserUnknown", uid); res.sendError(HttpServletResponse.SC_FORBIDDEN, msg); return false; } return true; }
@Override protected void delete(MCRDNBURN identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException { if (!MCRSessionMgr.getCurrentSession().getUserInformation().getUserID() .equals(MCRSystemUserInformation.getSuperUserInstance().getUserID())) { throw new MCRPersistentIdentifierException("Not supported!"); } }
private static void addUserInfo(JsonObject jEvent) { if (!MCRSessionMgr.hasCurrentSession()) { return; } String userID = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID(); jEvent.addProperty("user", userID); }
private static boolean currentUserIsGuest() { return MCRSessionMgr.getCurrentSession().getUserInformation() .equals(MCRSystemUserInformation.getGuestInstance()); }
private static void doWithinTransaction(IOOperation op) throws IOException { MCRSession mcrSession = MCRSessionMgr.getCurrentSession(); try { mcrSession.beginTransaction(); op.run(); } finally { if (mcrSession.transactionRequiresRollback()) { mcrSession.rollbackTransaction(); } else { mcrSession.commitTransaction(); } } }
private static String getUserKey(MCRObjectID objectId) { return MCRSessionMgr.getCurrentSession().getUserInformation() .getUserAttribute(MIRAccessKeyManager.ACCESS_KEY_PREFIX + objectId.toString()); }
public static MCREditorSessionStore getSessionStore() { MCRSession session = MCRSessionMgr.getCurrentSession(); MCREditorSessionStore store = (MCREditorSessionStore) (session.get(XEDITORS_CACHE_KEY)); if (store == null) { store = new MCREditorSessionStore(); session.put(XEDITORS_CACHE_KEY, store); } return store; } }
/** * Returns instance of MCRUser if current user is present in this user system * @return MCRUser instance or null */ public static MCRUser getCurrentUser() { MCRUserInformation userInformation = MCRSessionMgr.getCurrentSession().getUserInformation(); if (userInformation instanceof MCRUser) { return (MCRUser) userInformation; } else { return new MCRTransientUser(userInformation); } }
private static void setContinueIfOneFails(boolean value) { Object sessionValue; synchronized (MCRSessionMgr.getCurrentSession()) { sessionValue = MCRSessionMgr.getCurrentSession().get("MCRWebCLI"); ((MCRWebCLIContainer) sessionValue).setContinueIfOneFails(value, true); } } }
/** * Returns the label in the current language. */ public MCRLabel getLabel() { String lang = MCRSessionMgr.getCurrentSession().getCurrentLanguage(); return labels.get(lang); }
@Override public String getAuthenticationScheme() { if (ui.getUserID().equals(MCRSystemUserInformation.getGuestInstance().getUserID())) { return null; } if (ui instanceof MCRUser) { return SecurityContext.BASIC_AUTH; } if (ui instanceof MCRJWTUserInformation) { return "BEARER"; } return null; } }
@Override public boolean isUserInRole(String role) { return ui.isUserInRole(role); }
public MCREditorSession getSession(String id) { return cachedSessions.get(id); } }
public static boolean isCurrentUserCreator(final MCRObjectID objectId) { try { final String creator = MCRCreatorCache.getCreator(objectId); return MCRSessionMgr.getCurrentSession().getUserInformation().getUserID().equals(creator); } catch (ExecutionException e) { LOGGER.error("Error while getting creator information.", e); return false; } } }
private static boolean forbidIfGuest(HttpServletResponse res) throws IOException { if (MCRSessionMgr.getCurrentSession().getUserInformation() .equals(MCRSystemUserInformation.getGuestInstance())) { String msg = MCRTranslation.translate("component.user2.UserServlet.noGuestAction"); res.sendError(HttpServletResponse.SC_FORBIDDEN, msg); return true; } return false; }
static boolean isAuthenticated(HttpServletRequest req) { final String genToken = getLoginToken(req); final String loginToken = (String) MCRSessionMgr.getCurrentSession().get(MIRWizardStartupHandler.LOGIN_TOKEN); if (loginToken == null || !genToken.equals(loginToken)) { return false; } return true; }
private MCRRuleMapping createRuleMap(String accessID, String accessPool, String rule) { String uid = MCRSessionMgr.getCurrentSession().getUserInformation().getUserID(); MCRRuleMapping accessRule = new MCRRuleMapping(); accessRule.setObjId(accessID); accessRule.setPool(accessPool); accessRule.setRuleId(rule); accessRule.setCreationdate(new Date()); accessRule.setCreator(uid); return accessRule; }