List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:org.tsm.concharto.web.login.LoginController.java
@SuppressWarnings("unchecked") @Override// w ww. j a va 2 s . c o m protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Cookie userCookie = WebUtils.getCookie(request, AuthHelper.COOKIE_REMEMBER_ME_USERNAME); if ((userCookie != null) && !StringUtils.isEmpty(userCookie.getValue())) { SignupForm signupForm = (SignupForm) command; signupForm.setUsername(userCookie.getValue()); signupForm.setRememberMe(true); } return super.referenceData(request, command, errors); }
From source file:com.jredrain.session.HttpSessionFilter.java
private Cookie getOrGenerateSessionId(HttpServletRequest request, HttpServletResponse response) { Map<String, Cookie> cookieMap = CookieUtils.cookieToMap(request.getCookies()); Cookie sessionIdCookie = cookieMap.get(sessionIdCookieName); if (sessionIdCookie == null || StringUtils.isEmpty(sessionIdCookie.getValue())) { sessionIdCookie = generateCookie(request, response); } else {/* ww w .j a v a2 s. co m*/ //sessionIdCookie.setMaxAge(request.getSession().getMaxInactiveInterval() * 60 * 60 * 1000); } return sessionIdCookie; }
From source file:com.netpace.cms.sso.filter.OpenSSOClientAdapter.java
/** * Tries to create an SSOToken based on the HTTP request * /* w w w . j ava 2 s . co m*/ * @param request * @return The token or null if session not valid */ public SSOToken createTokenFrom(HttpServletRequest request) { System.out.println("OpenSSOClientAdapter.createTokenFrom: Start"); if (logger.isDebugEnabled()) { logger.debug("OpenSSOClientAdapter.createTokenFrom: Start"); } SSOToken token = null; try { // token = tokenManager.createSSOToken(request); Cookie[] requestCookies = request.getCookies(); for (int i = 0; i < requestCookies.length; i++) { Cookie cookie = requestCookies[i]; String ssoTokenId = java.net.URLDecoder.decode(cookie.getValue(), "UTF-8"); if (cookie.getName().equals(AlfrescoFacade.OPENSSO_COOKIE_NAME)) { token = tokenManager.createSSOToken(ssoTokenId); if (logger.isDebugEnabled()) { logger.debug("token: " + token); } boolean sessionValid = tokenManager.isValidToken(token); if (sessionValid) { return token; } } } } catch (SSOException e) { logger.info("Request does not contain a valid session"); logger.error(e, e); } catch (UnsupportedEncodingException e) { logger.error(e, e); } if (logger.isDebugEnabled()) { logger.debug("OpenSSOClientAdapter.createTokenFrom: End"); } System.out.println("OpenSSOClientAdapter.createTokenFrom: End"); return token; }
From source file:net.buffalo.web.servlet.ApplicationServlet.java
protected Locale getLocaleFromRequest() throws ServletException { Cookie cookie = (Cookie) RequestContext.getContext().getCookie().get(LOCALE_COOKIE_NAME); if (cookie != null) return RequestUtils.getLocale(cookie.getValue()); return RequestContext.getContext().getHttpRequest().getLocale(); }
From source file:com.yahoo.yos.AccessToken.java
public AccessToken(Cookie cookie) throws UnsupportedEncodingException, JSONException { JSONObject json = new JSONObject( new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8")); setKey(json.optString("key", null)); setSecret(json.optString("secret", null)); setGuid(json.optString("guid", null)); setOwner(json.optString("owner", null)); setTokenExpires(json.optLong("tokenExpires", -1)); setHandleExpires(json.optLong("handleExpires", -1)); setSessionHandle(json.optString("sessionHandle", null)); setConsumer(json.optString("consumer", null)); }
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()); }/* ww w. j a v a 2 s.co m*/ } joinService.updateMember(model); return "modifySuccess"; }
From source file:com.jredrain.session.HttpSessionFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { String requestURL = request.getRequestURL().toString(); String requestName = requestURL.substring(requestURL.lastIndexOf("/") + 1); requestName = requestName.toLowerCase(); //???// ww w .ja v a 2s . c om if (requestName.matches(".*\\.js$") || requestName.matches(".*\\.css$") || requestName.matches(".*\\.swf$") || requestName.matches(".*\\.jpg$") || requestName.matches(".*\\.png$") || requestName.matches(".*\\.jpeg$") || requestName.matches(".*\\.html$") || requestName.matches(".*\\.htm$") || requestName.matches(".*\\.xml$") || requestName.matches(".*\\.txt$") || requestName.matches(".*\\.ico$")) { chain.doFilter(request, response); return; } response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); Cookie sessionIdCookie = getOrGenerateSessionId(request, response); String sessionId = sessionIdCookie.getValue(); HttpSession rawSession = request.getSession(); Map sessionData = loadSessionData(sessionId, rawSession); try { HttpSession sessionWrapper = new HttpSessionStoreWrapper(rawSession, sessionStore, sessionId, sessionData); chain.doFilter(new HttpServletRequestSessionWrapper(request, sessionWrapper), response); } finally { try { String token = (String) sessionData.get("token"); if (token != null) { //token sessionId = token; logger.info("login token=" + token); sessionData.remove("token"); } sessionStore.saveSession(sessionId, sessionData, rawSession.getMaxInactiveInterval()); } catch (Exception e) { logger.warn("save session data error,cause:" + e, e); } } }
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 ww .j a v a 2s . co m*/ 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:com.jnj.b2b.storefront.controllers.pages.LoginPageController.java
protected boolean doRedirect(final HttpServletRequest request, final HttpServletResponse response, final boolean isUserAnonymous, final String guid) { boolean redirect = true; if (!isUserAnonymous && guid != null && request.getCookies() != null) { final String guidCookieName = cookieGenerator.getCookieName(); if (guidCookieName != null) { for (final Cookie cookie : request.getCookies()) { if (guidCookieName.equals(cookie.getName())) { if (guid.equals(cookie.getValue())) { redirect = false; break; } else { cookieGenerator.removeCookie(response); }//from w ww.j a v a2s. c om } } } } return redirect; }
From source file:au.gov.dto.springframework.security.web.csrf.CookieCsrfTokenRepository.java
@Override public CsrfToken loadToken(HttpServletRequest request) { if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if (cookie != null && csrfCookieName.equals(cookie.getName())) { return new DefaultCsrfToken(csrfHeaderName, csrfParameterName, cookie.getValue()); }//w w w . j a v a 2 s . com } } return null; }