List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:fr.xebia.springframework.security.cas.web.TransparentCasAuthenticationFilter.java
protected boolean isSsoSessionExists(HttpServletRequest request) { Cookie casPublicSessionCookie = WebUtils.getCookie(request, "CAS_ACTIVE"); return casPublicSessionCookie != null && "true".equalsIgnoreCase(casPublicSessionCookie.getValue()); }
From source file:co.id.app.sys.util.StringUtils.java
/** * Returns the value of the specified cookie as a String. If the cookie * does not exist, the method returns null. * <p/>/*from w w w.j ava 2s . com*/ * This method was derived from Atlassian <tt>CookieUtils</tt> method of * the same name, release under the Apache License. * * @param request the servlet request * @param name the name of the cookie * @return the value of the cookie, or null if the cookie does not exist. */ public static String getCookieValue(HttpServletRequest request, String name) { Cookie cookie = getCookie(request, name); if (cookie != null) { return cookie.getValue(); } return null; }
From source file:il.co.brandis.controller.ProductController.java
/** * Creating new product object and directing to JSP *//*from w w w. j av a 2 s .c om*/ @RequestMapping(value = "/addproductform") public String productsForm(HttpServletRequest req, ModelMap modelMap) { String METHOD = "registerForm()"; User user = (User) req.getSession().getAttribute("userPersist"); if (user == null) { Cookie cookie = CookiesUtil.getUserCookie(req); if (cookie != null) { return userService.performUserLogin(cookie.getValue(), modelMap, "productsPage"); } logger.warn(METHOD + "Anonymouse access attempt"); return "redirect:/user/index"; } modelMap.addAttribute("newProduct", new Product()); modelMap.addAttribute("userFullName", user.getFullName()); return "addproduct"; }
From source file:il.co.brandis.controller.ProductController.java
/** * Adding a new product received using model attribute *///from ww w . jav a 2s. com @RequestMapping(value = "/showproducts") public String showProducts(HttpServletRequest req, ModelMap modelMap) { String METHOD = "showProducts()"; User user = (User) req.getSession().getAttribute("userPersist"); if (user == null) { Cookie cookie = CookiesUtil.getUserCookie(req); if (cookie != null) { return userService.performUserLogin(cookie.getValue(), modelMap, "productsPage"); } logger.warn(METHOD + "Anonymouse access attempt"); return "redirect:/user/index"; } List<DBProduct> products = productService.getProducts(); modelMap.addAttribute("products", products); Cart cart = user.getCart(); modelMap.addAttribute("cartItems", cart); List<CartItem> cartItems = cart.getItems(); modelMap.addAttribute("cartItems", cartItems); modelMap.addAttribute("userFullName", user.getFullName()); return "productsPage"; }
From source file:com.ctc.storefront.security.evaluator.impl.RequireHardLoginEvaluator.java
protected boolean isGuidStoredinCookies(final HttpServletRequest request, final HttpServletResponse response, final String guid, final String guidCookieName) { for (final Cookie cookie : request.getCookies()) { if (guidCookieName.equals(cookie.getName())) { if (guid.equals(cookie.getValue())) { return true; } else { LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual [" + cookie.getValue() + "]. removing."); getCookieGenerator().removeCookie(response); }/*from ww w. ja va 2 s. c om*/ } } return false; }
From source file:com.ms.commons.summer.security.web.DefaultSecurityFormResolver.java
/** * ?token????InvalidTokenException/* w w w . ja v a 2 s .com*/ * * @param request * @param response * @throws InvalidTokenException */ public void validSessionToken(final HttpServletRequest request, final HttpServletResponse response) throws InvalidTokenException { Cookie[] cookies = request.getCookies(); String ctoken = null; if (cookies != null) { for (Cookie cookie : cookies) { if (FORM_RESUBMIT_TOKEN.equals(cookie.getName())) { ctoken = cookie.getValue(); break; } } } String rtoken = request.getParameter(FORM_RESUBMIT_TOKEN); if (rtoken == null || rtoken.length() == 0) { throw new InvalidTokenException("can't find token in request"); } if (ctoken == null || ctoken.length() == 0) { throw new InvalidTokenException("can't find token in cookie"); } if (!ctoken.equals(rtoken)) { throw new InvalidTokenException("failed to check for token in request"); } // cookietoken? Cookie c = new Cookie(FORM_RESUBMIT_TOKEN, ""); c.setPath("/"); response.addCookie(c); }
From source file:org.uaa.security.core.AuthenticationManager.java
public UsernamePasswordToken getToken(HttpServletRequest request) { UsernamePasswordToken token = null;//from ww w. j a v a2 s . c om Cookie[] cookies = request.getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(ConfigUtil.getValue("SESSION_ID"))) { String content = cookie.getValue(); String sessionInfo = Crypto.decrypt(content); try { JSONObject result = new JSONObject(sessionInfo); Integer uid = result.getInt("uid"); String username = result.getString("username"); String password = result.getString("password"); JSONArray array = result.getJSONArray("roles"); List<Integer> roles = new ArrayList<Integer>(); for (int i = 0; i < array.length(); i++) { roles.add(array.getInt(i)); } token = new UsernamePasswordToken(uid, username, password, roles); } catch (JSONException e) { e.printStackTrace(); } } } return token; }
From source file:com.sse.abtester.VariantSelectionFilterTest.java
/** * Test enrolls req if no cookie./*from w ww . jav a 2s. c o m*/ * * @throws IOException Signals that an I/O exception has occurred. * @throws ServletException the servlet exception */ @Test public void testEnrollsReqIfNoCookie() throws IOException, ServletException { IVariationStrategy forward = new Default(); VariantBean testvariant = mock(VariantBean.class); when(testvariant.getKey()).thenReturn(TESTKEY); when(testvariant.getKey()).thenReturn(TESTKEY); when(testvariant.getVariationStrategy()).thenReturn(forward); when(VM.enrollRequest(mockReq)).thenReturn(testvariant); vsf.doFilter(mockReq, mockRes, fc); Cookie attachedCookie = mockRes.getCookie(VSKEY); assertNotNull(attachedCookie); assertEquals("" + TESTKEY, attachedCookie.getValue()); verify(VM).publishVariationResponse(mockRes); }
From source file:fr.mby.portal.coreimpl.app.BasicAppSigner.java
@Override public String retrieveSignature(final HttpServletRequest request) { String signature = null;/* ww w . j a v a 2 s . co m*/ final Object attrObject = request.getAttribute(IPortal.SIGNATURE_PARAM_NAME); if (attrObject != null && attrObject instanceof String) { signature = (String) attrObject; } if (!StringUtils.hasText(signature)) { signature = request.getParameter(IPortal.SIGNATURE_PARAM_NAME); } if (!StringUtils.hasText(signature)) { final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { if (cookie != null && IPortal.SIGNATURE_PARAM_NAME.equals(cookie.getName())) { signature = cookie.getValue(); } } } } if (!StringUtils.hasText(signature)) { request.setAttribute(IPortal.SIGNATURE_PARAM_NAME, signature); } return signature; }
From source file:com.pureinfo.tgirls.sns.servlet.TestSNSEntryServlet.java
@Override protected void doPost(HttpServletRequest _req, HttpServletResponse _resp) throws ServletException, IOException { System.out.println("==================test entry=====POST=============="); try {//from w ww .j a v a 2 s . c o m String userId = _req.getParameter("id"); if (StringUtils.isEmpty(userId)) { userId = "1"; } System.out.println("----user id----" + userId); IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); User u = mgr.getUserByTaobaoId(userId); System.out.println("user:::;" + u); addCookie(u, _req, _resp); Cookie[] cookies = _req.getCookies(); if (cookies == null) { System.out.println("=====cookie is null======="); } else { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.out.println("cookie[" + i + "]:[" + cookie.getName() + ":" + cookie.getValue() + "(" + cookie.getMaxAge() + ")]"); } } int i = new Random().nextInt(); Cookie c = new Cookie("topsessionid", "abc" + i); _resp.addCookie(c); System.out.println("========================"); // Cookie[] cs = _req.getCookies(); // for (int ii = 0; ii < cs.length; ii++) { // Cookie cc = cs[ii]; // System.out.println("cookie[" + cc.getName() + "]:" + cc.getValue()); // } //_resp.sendRedirect(_req.getContextPath() + "/index.html"); RequestDispatcher rd = _req.getRequestDispatcher("/index.html"); rd.forward(_req, _resp); //_req.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, u); // _resp.sendRedirect(_req.getContextPath()); // _req.getCookies()[0]. } catch (PureException e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } }