List of usage examples for javax.servlet.http HttpServletRequest getCookies
public Cookie[] getCookies();
Cookie
objects the client sent with this request. From source file:controllers.Parent_Controller.java
public int checkSetCookie(HttpServletRequest request) { cookies = request.getCookies(); int countcookies = 0; for (Cookie cookie1 : cookies) { switch (cookie1.getName()) { case "handle": System.out.println("Got Handle cookie"); handle = cookie1.getValue(); countcookies++;/*from w w w . j a va2 s . com*/ break; case "uid": System.out.println("Got uid cookie"); uid = Integer.parseInt(cookie1.getValue()); countcookies++; break; } } if (countcookies == 0) { return 0; } else { cookiesSet = true; return 2; } }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.facebook.FacebookLogoutHandler.java
/** * {@inheritDoc}/* w w w .j av a2 s .com*/ * @see org.springframework.security.ui.logout.LogoutHandler#logout( * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, * org.springframework.security.Authentication) */ public void logout(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) { Cookie[] cookies = request.getCookies(); if (cookies != null) { String path = StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/"; for (Cookie cookie : cookies) { if (cookie.getName().startsWith(_apiKey)) { cancelCookie(cookie.getName(), path, response); } } } }
From source file:controllers.AuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; Cookie[] cookies = httpRequest.getCookies(); String status = "No cookie"; // Check cookie with name auth if (cookies != null) { String token = null;/*w w w . j a v a 2 s . c om*/ for (Cookie cookie : cookies) { status = "No token cookie"; if (cookie.getName().equals("token")) { token = cookie.getValue(); break; } } // Check whether the auth token hasn't expired yet if (token != null) { status = "Token cookie exists"; JSONObject obj = ISConnector.validateToken(token); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; if (obj != null && obj.containsKey("error")) { //Authorization failed, expired access token status = "Authentication failed"; String uri = req.getRequestURI(); this.context.log("Requested Resource:: " + uri); // Get session and set session HttpSession session = req.getSession(false); this.context.log("Unauthorized access request"); res.sendRedirect(req.getContextPath() + "/login"); return; } else { status = "Authentication succeed"; if (obj != null && obj.containsKey("id")) { long id = (long) obj.get("id"); int u_id = (int) id; UserWS.UserWS_Service service = new UserWS.UserWS_Service(); UserWS.UserWS port = service.getUserWSPort(); User user = (User) port.getUser(u_id); if (user != null) { req.setAttribute("user", user); } } } } } request.setAttribute("status", status); // Pass the request along the filter chain chain.doFilter(request, response); }
From source file:marketDB.del_db.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Cookie[] cookies = request.getCookies(); String access_token = ""; for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals("access_token")) { access_token = cookies[i].getValue(); }/*w ww . j av a2s. c om*/ } String product_id = request.getParameter("product_id"); int status = 0; try { status = delProduct(access_token, product_id); } catch (IOException_Exception ex) { Logger.getLogger(del_db.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException_Exception ex) { Logger.getLogger(del_db.class.getName()).log(Level.SEVERE, null, ex); } if (status == 1) { JSONObject arrayObj = new JSONObject(); arrayObj.put("status", status); response.sendRedirect("your_product.jsp"); } else { response.sendRedirect("login.jsp"); } }
From source file:com.baron.bm.controller.MemberController.java
@RequestMapping("/modifySuccess") public String modifySuccess(@Valid MemberModel model, HttpServletRequest request) { for (Cookie cookie : request.getCookies()) { if (cookie.getName().equals("bm_id")) { model.setId(cookie.getValue()); }/*from ww w . j a v a2 s . c om*/ } joinService.updateMember(model); return "modifySuccess"; }
From source file:com.persistent.cloudninja.controller.LogoutFilter.java
private void removeCookie(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String authCookieName) {//from w w w .java 2s. c om Cookie[] cookies = httpServletRequest.getCookies(); Cookie currentCookie = null; if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { if (authCookieName.equals(c.getName())) { currentCookie = c; currentCookie.setMaxAge(0); currentCookie.setValue(""); currentCookie.setPath("/"); httpServletResponse.addCookie(currentCookie); } } } }
From source file:cn.vlabs.duckling.vwb.CPSFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { int advSiteId = Integer.parseInt(StringUtils.defaultIfEmpty(request.getParameter("as"), "-1")); if (advSiteId <= 0) { chain.doFilter(request, response); return;//from w w w . ja v a 2 s .co m } HttpServletResponse rep = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; request.setAttribute("cps", advSiteId); Cookie[] cookies = req.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (StringUtils.equals(CPS_ADV, cookie.getName())) { cookie.setPath(req.getContextPath()); cookie.setMaxAge(0); } } } Cookie myCookie = new Cookie(CPS_ADV, advSiteId + ""); myCookie.setMaxAge(60 * 60 * 24);// myCookie.setPath(req.getContextPath()); rep.addCookie(myCookie); chain.doFilter(request, response); }
From source file:org.chos.transaction.passport.HttpContextSessionManager.java
private javax.servlet.http.Cookie getCookie(HttpServletRequest request, String name) { javax.servlet.http.Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; }//from ww w. j a v a 2 s. c o m for (javax.servlet.http.Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie; } } return null; }
From source file:org.uaa.security.core.AuthenticationManager.java
public UsernamePasswordToken getToken(HttpServletRequest request) { UsernamePasswordToken token = null;//from w ww. j a va2 s .c o m 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.acc.storefront.filters.RequestLoggerFilter.java
protected void logCookies(final HttpServletRequest httpRequest) { if (LOG.isDebugEnabled()) { final Cookie[] cookies = httpRequest.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { if (LOG.isDebugEnabled()) { LOG.debug("COOKIE Name: [" + cookie.getName() + "] Path: [" + cookie.getPath() + "] Value: [" + cookie.getValue() + "]"); }/*from www . j a va 2 s . c o m*/ } } } }