List of usage examples for javax.servlet.http HttpServletRequest getSession
public HttpSession getSession(boolean create);
From source file:cz.incad.kramerius.client.AuthenticationServlet.java
public static CallUserController createCaller(HttpServletRequest req, String username, String password, String returned) throws JSONException, ConfigurationException { CallUserController contr = (CallUserController) req.getSession(true).getAttribute(CallUserController.KEY); if (contr == null) { contr = new CallUserControllerImpl(); req.getSession().setAttribute(CallUserController.KEY, contr); }/*from w w w . j a va2s .c o m*/ if (returned != null) { ((CallUserControllerImpl) contr).setUserJSONRepresentation(new JSONObject(returned)); } if (username != null && password != null) { contr.createCaller(username, password, ClientUser.class); contr.createCaller(username, password, ProfileDelegator.class); } if (contr.getAdminCaller() == null) { String admUserName = KConfiguration.getInstance().getConfiguration().getString("k4.admin.user"); String admPswd = KConfiguration.getInstance().getConfiguration().getString("k4.admin.pswd"); contr.createCaller(admUserName, admPswd, AdminUser.class); } return contr; }
From source file:elw.web.ControllerElw.java
protected static Auth auth(HttpServletRequest req) { return (Auth) req.getSession(true).getAttribute(SESSION_KEY); }
From source file:com.paladin.mvc.RequestContext.java
/** * ? /*w ww.ja v a2s . co m*/ * * @param ctx * @param req * @param res */ public static RequestContext begin(ServletContext ctx, HttpServletRequest req, HttpServletResponse res) { RequestContext rc = new RequestContext(); rc.context = ctx; rc.request = req;// _AutoUploadRequest(_AutoEncodingRequest(req)); rc.response = res; rc.response.setCharacterEncoding(UTF_8); rc.session = req.getSession(false); rc.cookies = new HashMap<String, Cookie>(); Cookie[] cookies = req.getCookies(); if (cookies != null) for (Cookie ck : cookies) { rc.cookies.put(ck.getName(), ck); } contexts.set(rc); return rc; }
From source file:com.evolveum.midpoint.security.api.SecurityUtil.java
/** * Returns current connection information, as derived from HTTP request stored in current thread. * May be null if the thread is not associated with any HTTP request (e.g. task threads, operations invoked from GUI but executing in background). *//*from www . j av a 2 s .c o m*/ public static HttpConnectionInformation getCurrentConnectionInformation() { RequestAttributes attr = RequestContextHolder.getRequestAttributes(); if (!(attr instanceof ServletRequestAttributes)) { return null; } ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) attr; HttpServletRequest request = servletRequestAttributes.getRequest(); if (request == null) { return null; } HttpConnectionInformation rv = new HttpConnectionInformation(); HttpSession session = request.getSession(false); if (session != null) { rv.setSessionId(session.getId()); } rv.setLocalHostName(request.getLocalName()); rv.setRemoteHostAddress(getRemoteHostAddress(request)); return rv; }
From source file:net.ontopia.topicmaps.classify.WebChew.java
/** * INTERNAL: Returns the plug-in class instance used by the ontopoly * plugin. Used by classify/plugin.jsp./*from w w w . ja v a2 s.c om*/ */ public static ClassifyPluginIF getPlugin(HttpServletRequest request) { // create plugin by dynamically intantiating plugin class HttpSession session = request.getSession(true); ServletContext scontext = session.getServletContext(); String pclass = scontext.getInitParameter("classify_plugin"); if (pclass == null) pclass = "net.ontopia.topicmaps.classify.DefaultPlugin"; ClassifyPluginIF cp = (ClassifyPluginIF) ObjectUtils.newInstance(pclass); if (cp instanceof HttpServletRequestAwareIF) ((HttpServletRequestAwareIF) cp).setRequest(request); return cp; }
From source file:com.liusoft.dlog4j.UserLoginManager.java
/** * Velocity?// w ww .ja va 2 s. c o m * * @param request * @param response * @param uuid * @param verify_host * @return * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#verify_login_cookie(String, * boolean) */ public static SessionUserObject getLoginUser(HttpServletRequest request, HttpServletResponse response, boolean verify_host) { // sessionsession? Cookie uuidCookie = null; HttpSession ssn = request.getSession(false); if (ssn != null) { SessionUserObject user = (SessionUserObject) ssn.getAttribute(SESSION_USER_KEY); if (user != null) { uuidCookie = getUuidCookie(request); //sessioncookie? //(?s1s2?) if (uuidCookie != null) return user; ssn.invalidate(); return null; } } String uuid = null; if (uuidCookie == null) uuidCookie = getUuidCookie(request); if (uuidCookie != null) uuid = uuidCookie.getValue(); if (StringUtils.isEmpty(uuid)) return null; // session? try { UUID oUUID = new UUID(uuid); String new_host = request.getRemoteAddr(); if (verify_host && !StringUtils.equals(new_host, oUUID.host)) return null; UserBean user = UserDAO.getUserByID(oUUID.uid); // ? if (user == null || user.getStatus() != UserBean.STATUS_NORMAL || user.getPassword().hashCode() != oUUID.pwdCode) { RequestUtils.setCookie(request, response, COOKIE_UUID_KEY, "", 0); RequestUtils.setCookie(request, response, COOKIE_LASTLOGIN_KEY, "", 0); return null; } int keep_days = user.getKeepDays(); if (keep_days < 1) keep_days = 365; return loginUser(request, response, user, keep_days); } catch (Exception e) { log.error("Exception occur when get current user.", e); } return null; }
From source file:com.lm.lic.manager.util.GenUtil.java
public static void removeProductUnderManagement(HttpServletRequest request) { HttpSession session = request.getSession(false); session.removeAttribute("prodId"); }
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:com.lm.lic.manager.util.GenUtil.java
/** * Get the logged in user/role S/* w w w . j a v a2 s . co m*/ * * @param request * @return */ public static User getLoggedinUser(ServletRequest request) { HttpServletRequest req = (HttpServletRequest) request; HttpSession session = req.getSession(true); User user = (User) session.getAttribute("user"); return user; }
From source file:com.liusoft.dlog4j.util.RequestUtils.java
/** * ?FCKUpload??ID// w ww. j av a 2 s .co m * @return */ public static String getDlogSessionId(HttpServletRequest req) { //Cookie?ssn_id String ssn_id = null; Cookie cok = RequestUtils.getCookie(req, Globals.SESSION_ID_KEY_IN_COOKIE); if (cok != null) { ssn_id = cok.getValue(); } if (StringUtils.isEmpty(ssn_id)) { //Cookie???? HttpSession ssn = req.getSession(false); if (ssn != null) ssn_id = ssn.getId(); } return ssn_id; }