List of usage examples for javax.servlet.http HttpSession setAttribute
public void setAttribute(String name, Object value);
From source file:fr.paris.lutece.portal.web.PortalJspBean.java
/** * This method is called by Portal.jsp when it caught an * UserNotSignedException./*from w ww.j a va 2 s . c om*/ * It gives the login url and stores in the session the url asked * @param request The HTTP request * @return The login page URL * @since v1.1 */ public static String redirectLogin(HttpServletRequest request) { String strNextUrl = request.getRequestURI(); UrlItem url = new UrlItem(strNextUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_LOGIN_NEXT_URL, url.getUrl()); String strRedirect = SecurityService.getInstance().getLoginPageUrl(); return AppPathService.getAbsoluteUrl(request, strRedirect); }
From source file:mercury.BaseHandler.java
public static Properties getI18nProperties(final HttpSession session, String module) { String lang = (String) (session.getAttribute("I18N")); if (lang == null || lang.trim().equals("")) { lang = "pt_BR"; session.setAttribute("I18N", lang); }/*from w w w . j a v a2 s . c o m*/ String attrName = "I18N_" + module + "." + lang; ServletContext sc = session.getServletContext(); return (Properties) (sc.getAttribute(attrName)); }
From source file:edu.cornell.mannlib.vitro.webapp.filestorage.TempFileHolder.java
/** * Create a {@link TempFileHolder} holding the given {@link FileInfo}, and * attach it to the session with the given attribute name. * //from w w w . j av a2 s . co m * If an attribute with this name already exists, it is replaced. */ public static void attach(HttpSession session, String attributeName, FileInfo fileInfo) { if (session == null) { throw new NullPointerException("session may not be null."); } if (attributeName == null) { throw new NullPointerException("attributeName may not be null."); } if (fileInfo == null) { throw new NullPointerException("fileInfo may not be null."); } log.debug("attach this file: " + fileInfo); session.setAttribute(attributeName, new TempFileHolder(fileInfo)); }
From source file:org.appverse.web.framework.backend.api.helpers.security.SecurityHelper.java
public static String createXSRFToken(final HttpServletRequest request) throws IOException { // getSession(false) as this method never creates a new session HttpSession session = request.getSession(false); String xsrfSessionToken = (String) session.getAttribute(XSRF_TOKEN_NAME); if (xsrfSessionToken == null) { Random r = new Random(System.currentTimeMillis()); long value = System.currentTimeMillis() + r.nextLong(); char ids[] = session.getId().toCharArray(); for (int i = 0; i < ids.length; i++) { value += ids[i] * (i + 1);/* w w w . j av a 2 s . c o m*/ } xsrfSessionToken = Long.toString(value); session.setAttribute(XSRF_TOKEN_NAME, xsrfSessionToken); } return xsrfSessionToken; }
From source file:fll.web.DoLogin.java
/** * Does the work of login. Exists as a separate method so that it can be * called from {@link fll.web.admin.CreateUser} *///w w w . java2 s . c o m public static void doLogin(final HttpServletRequest request, final HttpServletResponse response, final ServletContext application, final HttpSession session) throws IOException, ServletException { final DataSource datasource = ApplicationAttributes.getDataSource(application); Connection connection = null; try { connection = datasource.getConnection(); // check for authentication table if (Queries.isAuthenticationEmpty(connection)) { LOGGER.warn("No authentication information in the database"); session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>No authentication information in the database - see administrator</p>"); response.sendRedirect(response.encodeRedirectURL("login.jsp")); return; } // compute hash final String user = request.getParameter("user"); final String pass = request.getParameter("pass"); if (null == user || user.isEmpty() || null == pass || pass.isEmpty()) { LOGGER.warn("Form fields missing"); session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>You must fill out all fields in the form.</p>"); response.sendRedirect(response.encodeRedirectURL("login.jsp")); return; } final String hashedPass = DigestUtils.md5Hex(pass); // compare login information if (LOGGER.isTraceEnabled()) { LOGGER.trace("Checking user: " + user + " hashedPass: " + hashedPass); } final Map<String, String> authInfo = Queries.getAuthInfo(connection); for (final Map.Entry<String, String> entry : authInfo.entrySet()) { if (user.equals(entry.getKey()) && hashedPass.equals(entry.getValue())) { // clear out old login cookies first CookieUtils.clearLoginCookies(application, request, response); final String magicKey = String.valueOf(System.currentTimeMillis()); Queries.addValidLogin(connection, user, magicKey); CookieUtils.setLoginCookie(response, magicKey); String redirect = SessionAttributes.getRedirectURL(session); if (null == redirect) { redirect = "index.jsp"; } response.sendRedirect(response.encodeRedirectURL(redirect)); return; } else { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Didn't match user: " + entry.getKey() + " pass: " + entry.getValue()); } } } LOGGER.warn("Incorrect login credentials user: " + user); session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>Incorrect login information provided</p>"); response.sendRedirect(response.encodeRedirectURL("login.jsp")); return; } catch (final SQLException e) { throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:com.lm.lic.manager.util.GenUtil.java
public static void addProductUnderManagement(HttpServletRequest request, String prodId) { HttpSession session = request.getSession(false); session.setAttribute("prodId", prodId); }
From source file:fr.paris.lutece.plugins.mylutece.web.MyLuteceApp.java
/** * Set the current url//from w ww . j av a 2s.c om * @param request The Http request * */ public static void setCurrentUrl(HttpServletRequest request) { String strCurrentUrl = request.getRequestURI(); UrlItem url = new UrlItem(strCurrentUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_CURRENT_URL, url.getUrl()); }
From source file:com.redhat.rhn.frontend.action.systems.monitoring.BaseProbeCreateAction.java
private static CommandGroup lookupCommandGroup(DynaActionForm form, HttpSession session) { CommandGroup result = null;//from w ww .j av a2 s . com String name = form.getString(COMMAND_GROUP); if (StringUtils.isBlank(name)) { name = (String) session.getAttribute(SELECTED_COMMAND_GROUP_SESSION); if (StringUtils.isBlank(name)) { name = ModifyProbeCommand.COMMAND_GROUP_DEFAULT; } } session.setAttribute(SELECTED_COMMAND_GROUP_SESSION, name); result = MonitoringManager.getInstance().lookupCommandGroup(name); assert result != null; return result; }
From source file:com.huateng.ebank.business.common.GlobalInfo.java
public static void setGlobalInfo2HttpSession(HttpSession httpSession, GlobalInfo globalInfo) { httpSession.setAttribute(GlobalInfo.KEY_GLOBAL_INFO, globalInfo); globalInfo.setSessionId(httpSession.getId()); }
From source file:com.adito.vfs.VFSRepository.java
/** * Create a {@link VFSRepository} repository for the given session. The * repository will be placed in the users session and used for all VFS * operations./* w w w . j ava2s . c om*/ * * @param session * @return VFS repository * @throws DAVBundleActionMessageException * @throws Exception */ public static VFSRepository getRepository(HttpSession session) throws DAVBundleActionMessageException, Exception { VFSRepository repository = (VFSRepository) session.getAttribute(REPOSITORY_ATTR); if (repository == null) { repository = new VFSRepository(session); session.setAttribute(REPOSITORY_ATTR, repository); if (log.isInfoEnabled()) log.info("Initialized repository"); } return repository; }