List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.java
public static ModelAccess on(HttpSession session) { Object o = session.getAttribute(ATTRIBUTE_NAME); if (o instanceof ModelAccess) { return (ModelAccess) o; } else {//from ww w. j a va2s . c om ModelAccess parent = on(session.getServletContext()); ModelAccess ma = new ModelAccess(Scope.SESSION, parent); session.setAttribute(ATTRIBUTE_NAME, ma); return ma; } }
From source file:info.magnolia.cms.security.Authenticator.java
/** * @param request current HttpServletRequest * @return String , current logged in user *//*from w w w. java 2s. c o m*/ public static String getUserId(HttpServletRequest request) { String userId = null; HttpSession httpsession = request.getSession(false); if (httpsession != null) { userId = (String) httpsession.getAttribute(ATTRIBUTE_USER_ID); } if (userId == null) { String credentials = request.getHeader("Authorization"); if (credentials != null) { try { userId = getDecodedCredentials(credentials.substring(6).trim()); if (httpsession != null) { httpsession.setAttribute(ATTRIBUTE_USER_ID, userId); } } catch (Exception e) { log.debug(e.getMessage(), e); } } } return userId; }
From source file:com.adito.vfs.webdav.DAVServlet.java
/** * Get the {@link DAVProcessor} from the session. * // www . jav a 2s.co m * @param session sesison * @return processor * @throws CoreException on any error * @throws Exception on any error */ public static DAVProcessor getDAVProcessor(HttpSession session) throws Exception { DAVProcessor processor = (DAVProcessor) session.getAttribute(PROCESSOR_ATTR); if (processor == null) { VFSRepository repository = VFSRepository.getRepository(session); processor = new DAVProcessor(repository); processors.add(processor); session.setAttribute(PROCESSOR_ATTR, processor); session.setAttribute(SESSION_INVALIDATE_LISTENER_ATTR, new SessionInvalidateListener(processor)); if (log.isInfoEnabled()) log.info("Initialized repository"); } return processor; }
From source file:fr.paris.lutece.plugins.extend.modules.comment.web.CommentApp.java
/** * Gets the view comment page./*from w w w. j av a2 s. c om*/ * * @param request the request * @param strIdExtendableResource the str id extendable resource * @param strExtendableResourceType the str extendable resource type * @param strPostBackUrl The URL to use for post backs. * @return the view comment page */ public static String getViewCommentPageContent(HttpServletRequest request, String strIdExtendableResource, String strExtendableResourceType, String strPostBackUrl) { request.getSession().setAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.SESSION_COMMENT_POST_BACK_URL, strPostBackUrl); Integer nItemsPerPage = getDefaultItemsPerPage(); String strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER; Boolean bIsAscSort = false; Object object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_ITEMS_PER_PAGE); if (object != null) { nItemsPerPage = (Integer) object; } object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_CURRENT_PAGE_INDEX); if (object != null) { strCurrentPageIndex = (String) object; } object = request.getSession().getAttribute(CommentConstants.SESSION_COMMENT_IS_ASC_SORT); if (object != null) { bIsAscSort = (Boolean) object; } String strSort = request.getParameter(CommentConstants.MARK_ASC_SORT); if (!StringUtils.isEmpty(strSort)) { bIsAscSort = Boolean.parseBoolean(strSort); } String strFromUrl = request.getParameter(CommentConstants.PARAMETER_FROM_URL); if (FROM_SESSION.equals(strFromUrl)) { strFromUrl = (String) request.getSession() .getAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.PARAMETER_FROM_URL); } if (StringUtils.isEmpty(strFromUrl)) { strFromUrl = request.getHeader(CommentConstants.PARAMETER_REFERER); } if (strFromUrl != null) { strFromUrl = strFromUrl.replace(CONSTANT_AND, CONSTANT_AND_HTML); } request.getSession().setAttribute(ExtendPlugin.PLUGIN_NAME + CommentConstants.PARAMETER_FROM_URL, strFromUrl); strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndex); int nOldITemsPerPage = nItemsPerPage; nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, nItemsPerPage, getDefaultItemsPerPage()); if (nItemsPerPage <= 0) { nItemsPerPage = getDefaultItemsPerPage(); } // If we changed the number of items per page, we go back to the first page if (nItemsPerPage != nOldITemsPerPage) { strCurrentPageIndex = CommentConstants.CONSTANT_FIRST_PAGE_NUMBER; } UrlItem urlSort = new UrlItem(strPostBackUrl); urlSort.addParameter(CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource); urlSort.addParameter(CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType); urlSort.addParameter(CommentConstants.MARK_ASC_SORT, strSort); if (StringUtils.isNotEmpty(strFromUrl)) { urlSort.addParameter(CommentConstants.PARAMETER_FROM_URL, FROM_SESSION); } boolean bGetSubComments = false; boolean bUseBBCodeEditor = false; boolean bAllowSubComments = false; String strAdminBadge = StringUtils.EMPTY; CommentExtenderConfig config = getConfigService().find(CommentResourceExtender.EXTENDER_TYPE_COMMENT, strIdExtendableResource, strExtendableResourceType); if (config != null) { bGetSubComments = config.getAuthorizeSubComments(); bUseBBCodeEditor = config.getUseBBCodeEditor(); bAllowSubComments = config.getAuthorizeSubComments(); strAdminBadge = config.getAdminBadge(); } int nItemsOffset = nItemsPerPage * (Integer.parseInt(strCurrentPageIndex) - 1); List<Comment> listItems = getCommentService().findByResource(strIdExtendableResource, strExtendableResourceType, true, null, bIsAscSort, nItemsOffset, nItemsPerPage, bGetSubComments); int nItemsCount = getCommentService().getCommentNb(strIdExtendableResource, strExtendableResourceType, true, true); IPaginator<Comment> paginator = new LocalizedDelegatePaginator<Comment>(listItems, nItemsPerPage, urlSort.getUrl(), Paginator.PARAMETER_PAGE_INDEX, strCurrentPageIndex, nItemsCount, request.getLocale()); Map<String, Object> model = new HashMap<String, Object>(); model.put(CommentConstants.MARK_ID_EXTENDABLE_RESOURCE, strIdExtendableResource); model.put(CommentConstants.MARK_EXTENDABLE_RESOURCE_TYPE, strExtendableResourceType); model.put(CommentConstants.MARK_PAGINATOR, paginator); model.put(CommentConstants.MARK_ASC_SORT, strSort); model.put(CommentConstants.PARAMETER_FROM_URL, strFromUrl); model.put(CommentConstants.PARAMETER_ID_COMMENT, request.getParameter(CommentConstants.PARAMETER_ID_COMMENT)); model.put(CommentConstants.MARK_USE_BBCODE, bUseBBCodeEditor); model.put(CommentConstants.MARK_ALLOW_SUB_COMMENTS, bAllowSubComments); model.put(CommentConstants.MARK_ADMIN_BADGE, strAdminBadge); model.put(CommentConstants.PARAMETER_POST_BACK_URL, strPostBackUrl); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_XPAGE_VIEW_COMMENTS, request.getLocale(), model); HttpSession session = request.getSession(); session.setAttribute(CommentConstants.SESSION_COMMENT_ITEMS_PER_PAGE, nItemsPerPage); session.setAttribute(CommentConstants.SESSION_COMMENT_CURRENT_PAGE_INDEX, strCurrentPageIndex); session.setAttribute(CommentConstants.SESSION_COMMENT_IS_ASC_SORT, bIsAscSort); return template.getHtml(); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission.java
public static void putEditSubmissionInSession(HttpSession sess, EditSubmission editSub) { Map<String, EditSubmission> submissions = (Map<String, EditSubmission>) sess .getAttribute("EditSubmissions"); if (submissions == null) { submissions = new HashMap<String, EditSubmission>(); sess.setAttribute("EditSubmissions", submissions); }/* w w w . ja va2s .c o m*/ submissions.put(editSub.editKey, editSub); }
From source file:com.brienwheeler.web.spring.security.SecurityUtils.java
public static User getLoggedInUser(HttpSession session, IUserService userService) { ValidationUtils.assertNotNull(session, "session cannot be null"); ValidationUtils.assertNotNull(userService, "userService cannot be null"); long userId = ensureLoggedInUserId(); Object attribute = session.getAttribute(LOGGED_IN_USER); if ((attribute instanceof User) && (((User) attribute).getId() == userId)) return (User) attribute; User user = userService.findById(new DbId<User>(User.class, userId)); if (user == null) throw new IllegalStateException("logged in user id not found in database"); session.setAttribute(LOGGED_IN_USER, user); return user;//ww w .j a v a 2 s . c o m }
From source file:eionet.util.SecurityUtil.java
/** * Returns current user, or null, if the current session does not have user attached to it. *///from w w w. j a v a 2 s. c o m public static final DDUser getUser(HttpServletRequest request) { HttpSession session = request.getSession(); DDUser user = session == null ? null : (DDUser) session.getAttribute(REMOTEUSER); if (user == null) { String casUserName = session == null ? null : (String) session.getAttribute(CASFilter.CAS_FILTER_USER); if (casUserName != null) { user = DDCASUser.create(casUserName); session.setAttribute(REMOTEUSER, user); } } else if (user instanceof DDCASUser) { String casUserName = (String) session.getAttribute(CASFilter.CAS_FILTER_USER); if (casUserName == null) { user.invalidate(); user = null; session.removeAttribute(REMOTEUSER); } else if (!casUserName.equals(user.getUserName())) { user.invalidate(); user = DDCASUser.create(casUserName); session.setAttribute(REMOTEUSER, user); } } if (user != null) { return user.isAuthentic() ? user : null; } else { return null; } }
From source file:com.xpn.xwiki.stats.impl.StatsUtil.java
/** * Store the visit object in the session. * /*ww w . j a va2s .c om*/ * @param session the session. * @param visitStat the visit object. * @since 1.4M1 */ public static void setVisitInSession(HttpSession session, VisitStats visitStat) { session.setAttribute(SESSPROP_VISITOBJECT, visitStat); }
From source file:com.liferay.portlet.InvokerPortletImpl.java
public static Map<String, InvokerPortletResponse> getResponses(HttpSession session) { Map<String, InvokerPortletResponse> responses = (Map<String, InvokerPortletResponse>) session .getAttribute(WebKeys.CACHE_PORTLET_RESPONSES); if (responses == null) { responses = new ConcurrentHashMap<String, InvokerPortletResponse>(); session.setAttribute(WebKeys.CACHE_PORTLET_RESPONSES, responses); }/*w w w . ja v a 2 s . c om*/ return responses; }
From source file:in.mycp.utils.Commons.java
public static User getCurrentUser() { SecurityContext securityContext = SecurityContextHolder.getContext(); HttpSession session = null; Object obj = null;/*w w w . j a v a2 s.c o m*/ try { session = WebContextFactory.get().getSession(); setSessionAttribute("MYCP_SIGNUP_MSG", ""); obj = session.getAttribute("CurrentUser"); } catch (Exception e) { // e.printStackTrace(); } // if this is after the first call from DWR if (obj != null) { return (User) obj; // if this is teh first call from DWR } else if (obj == null && session != null) { User currentUser = User.findUsersByEmailEquals(securityContext.getAuthentication().getName()) .getSingleResult(); session.setAttribute("CurrentUser", currentUser); return currentUser; // for non DWR calls } else { //System.out.println("securityContext.getAuthentication().getName() = " + securityContext.getAuthentication().getName()); User currentUser = User.findUsersByEmailEquals(securityContext.getAuthentication().getName()) .getSingleResult(); return currentUser; } }