List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:com.expressui.core.MainApplication.java
/** * Gets cookie associated with given name. * * @param name name of the cookie//w w w . java 2s . c o m * @return cookie */ public Cookie getCookie(String name) { Cookie[] cookies = getRequest().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie; } } return null; }
From source file:ELK.ELKController.java
private String getSessionCookie(final Request request) { if (request.raw().getCookies() == null) { return null; }//from w w w . j av a 2 s. c o m for (Cookie cookie : request.raw().getCookies()) { if (cookie.getName().equals("session")) { return cookie.getValue(); } } return null; }
From source file:ELK.ELKController.java
private Cookie getSessionCookieActual(final Request request) { if (request.raw().getCookies() == null) { return null; }/*www . j a va 2 s. co m*/ for (Cookie cookie : request.raw().getCookies()) { if (cookie.getName().equals("session")) { return cookie; } } return null; }
From source file:com.yaodu.framework.controller.product.ProductSearchController.java
private List<ProductBascInfo> getRecentlyViewedList(HttpServletRequest request) { List<ProductBascInfo> recentlyViewedList = null; if (null != request) { Cookie[] cookie = request.getCookies(); if (null == cookie) { return recentlyViewedList; }/* w w w . j a v a 2 s. c o m*/ for (int i = 0; i < cookie.length; i++) { Cookie cook = cookie[i]; if (cook.getName().equalsIgnoreCase("relatedProducts")) { // ? if (!"".equals(cook.getValue().toString())) { final String[] arrs = cook.getValue().split("\\|"); recentlyViewedList = productSolrjSearchService.findProductsByIds(arrs); Collections.sort(recentlyViewedList, new Comparator<ProductBascInfo>() { public int compare(ProductBascInfo p1, ProductBascInfo p2) { return Integer.valueOf(ArrayUtils.indexOf(arrs, p1.getnId())) .compareTo(ArrayUtils.indexOf(arrs, p2.getnId())); } }); } break; } } } return recentlyViewedList; }
From source file:org.eclipse.userstorage.tests.util.USSServer.java
private Session getSession(HttpServletRequest request) { String csrfToken = request.getHeader("X-CSRF-Token"); if (csrfToken != null) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if ("SESSION".equals(cookie.getName())) { String sessionID = cookie.getValue(); Session session = sessions.get(sessionID); if (session != null && session.getCSRFToken().equals(csrfToken)) { return session; }/*from ww w . java 2 s .c om*/ break; } } } } return null; }
From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java
private void serializeCookies() throws Exception { Cookie[] cookies = req.getCookies(); if (cookies != null && cookies.length > 0) { xsw.writeStartElement(URI, "cookies"); for (Cookie cookie : cookies) { xsw.writeStartElement(URI, "cookie"); dataElement(xsw, URI, "comment", cookie.getComment()); dataElement(xsw, URI, "domain", cookie.getDomain()); dataElement(xsw, URI, "max-age", Integer.toString(cookie.getMaxAge())); dataElement(xsw, URI, "name", cookie.getName()); dataElement(xsw, URI, "path", cookie.getPath()); dataElement(xsw, URI, "is-secure", Boolean.toString(cookie.getSecure())); dataElement(xsw, URI, "value", cookie.getValue()); dataElement(xsw, URI, "version", Integer.toString(cookie.getVersion())); xsw.writeEndElement();/*from w w w . j a v a 2 s . c o m*/ } xsw.writeEndElement(); } }
From source file:com.google.gsa.valve.modules.ldap.LDAPUniqueCreds.java
/** * Sets the LDAP authentication cookie/*from ww w.ja va 2 s .co m*/ * * @return the LDAP authentication cookie */ public Cookie settingCookie() { // Instantiate a new cookie Cookie extAuthCookie = new Cookie("gsa_ad_auth", "true"); String authCookieDomain = null; String authCookiePath = null; // Cache cookie properties authCookieDomain = valveConf.getAuthCookieDomain(); authCookiePath = valveConf.getAuthCookiePath(); // Set extra cookie parameters extAuthCookie.setDomain(authCookieDomain); extAuthCookie.setPath(authCookiePath); extAuthCookie.setMaxAge(authMaxAge); // Log info logger.debug("Adding cookie: " + extAuthCookie.getName() + ":" + extAuthCookie.getValue() + ":" + extAuthCookie.getPath() + ":" + extAuthCookie.getDomain() + ":" + extAuthCookie.getSecure()); return extAuthCookie; }
From source file:de.innovationgate.wgpublisher.filter.WGAFilter.java
private Cookie getCookie(HttpServletRequest request, String name) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie; }//from w w w.j av a 2s. c o m } } return null; }
From source file:org.kite9.diagram.server.AbstractKite9Controller.java
/** * Retrieves user info from cookie/*from w w w . j a v a2 s.com*/ */ public User getUser(HttpServletRequest req) { if (isLocal()) { return LOCAL_USER; } Cookie[] cookies = req.getCookies(); String wpCookieName = null; String wpCookieValue = null; if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().startsWith("wordpress_logged_in")) { wpCookieName = cookie.getName(); wpCookieValue = cookie.getValue(); } } } final String ip = req.getRemoteAddr(); final String host = req.getRemoteHost(); System.out.println("Session : " + wpCookieName + " " + wpCookieValue); if (wpCookieName == null) { return NO_USER; } try { URL u = new URL(URL_ROOT + "/kite9_user_info"); URLConnection conn = u.openConnection(); conn.setRequestProperty("Cookie", wpCookieName + "=" + wpCookieValue); conn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line = br.readLine(); br.close(); if (line.contains("<none>")) { return NO_USER; } else { String parts[] = line.split(","); int id = Integer.parseInt(parts[1]); return new User(id, parts[0], false, ip, host); } } catch (IOException e) { throw new Kite9ProcessingException("Couldn't handle user log-in", e); } }
From source file:neu.edu.lab08.HomeController.java
/** * Simply selects the home view to render by returning its name. * @throws Exception /*from ww w . j a va 2 s . c om*/ */ @RequestMapping(value = "/", method = RequestMethod.GET) public String initUserLoginForm(Model model, HttpServletRequest request) throws Exception { Cookie[] cookies = request.getCookies(); String usernameCookie = ""; String passwordCookie = ""; for (Cookie cookie : cookies) { if (cookie.getName().equals("usernameCookie")) { usernameCookie = cookie.getValue(); } if (cookie.getName().equals("passwordCookie")) { passwordCookie = cookie.getValue(); } } User u = userDao.queryUserByNameAndPassword(usernameCookie, passwordCookie); if (u != null) { try { if (u.getRole().equals("admin")) { model.addAttribute("user", u); HttpSession session = request.getSession(); session.setAttribute("username", u.getUsername()); return "createUser"; } else if (u.getRole().equals("CDC")) { HttpSession session = request.getSession(); session.setAttribute("username", u.getUsername()); model.addAttribute("user", u); ArrayList<Vaccine> vaccineList = vaccineDao.listVaccineByUsername(u.getUsername()); ArrayList<Request> requestList = requestDao.listRequest(); model.addAttribute("producedvaccineList", vaccineList); model.addAttribute("requestList", requestList); return "cdcMenu"; } else if (u.getRole().equals("Hospital")) { HttpSession session = request.getSession(); session.setAttribute("username", u.getUsername()); model.addAttribute("user", u); ArrayList<Vaccine> vaccineList = vaccineDao.listVaccine(); ArrayList<InsuredPatient> insuredPatientList = patientDao .listInsuredPatientByUsername(u.getUsername()); ArrayList<UninsuredPatient> uninsuredPatientList = patientDao .listUninsuredPatientByUsername(u.getUsername()); ArrayList<Inventory> inventoryList = inventoryDao.listInventoryByUser(u.getUsername()); model.addAttribute("insuredPatientList", insuredPatientList); model.addAttribute("uninsuredPatientList", uninsuredPatientList); model.addAttribute("vaccineList", vaccineList); model.addAttribute("inventoryList", inventoryList); HttpSession inventorysession = request.getSession(); inventorysession.setAttribute("inventoryList", inventoryList); ArrayList<UsedVaccine> usedvaccineList = vaccineDao.listUsedVaccineByUsername(u.getUsername()); model.addAttribute("usedvaccineList", usedvaccineList); return "hospitalMenu"; } } catch (Exception e) { e.printStackTrace(); } } else { User user = new User(); model.addAttribute("user", user); } return "home"; }