List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:com.yahoo.yos.YahooFilter.java
private boolean cookieExists(Cookie[] cookies, String cookieName) { if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName() != null && cookie.getName().equals(cookieName)) { return true; }//ww w. ja v a 2s.c om } } return false; }
From source file:com.yahoo.yos.YahooFilter.java
private Cookie cookie(Cookie[] cookies, String cookieName) { if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName() != null && cookie.getName().equals(cookieName)) { return cookie; }//from w w w .ja v a 2 s . c om } } return null; }
From source file:info.jtrac.wicket.JtracApplication.java
private boolean attemptRememberMeAutoLogin() { logger.debug("checking cookies for remember-me auto login"); Cookie[] cookies = ((WebRequest) RequestCycle.get().getRequest()).getCookies(); if (cookies == null) { logger.debug("no cookies found"); return false; }/*w ww . j a v a 2 s . c o m*/ for (Cookie c : cookies) { if (logger.isDebugEnabled()) { logger.debug("examining cookie: " + WebUtils.getDebugStringForCookie(c)); } if (!c.getName().equals("jtrac")) { continue; } String value = c.getValue(); logger.debug("found jtrac cookie: " + value); if (value == null) { continue; } int index = value.indexOf(':'); if (index == -1) { continue; } String loginName = value.substring(0, index); String encodedPassword = value.substring(index + 1); logger.debug("valid cookie, attempting authentication"); User user = (User) getJtrac().loadUserByUsername(loginName); if (encodedPassword.equals(user.getPassword())) { ((JtracSession) Session.get()).setUser(user); logger.debug("remember me login success"); return true; } } // no valid cookies were found return false; }
From source file:org.slc.sli.dashboard.security.SLIAuthenticationEntryPoint.java
private boolean checkCookiesForToken(HttpServletRequest request, HttpSession session) { boolean cookieFound = false; // If there is no oauth credential, and the user has a dashboard cookie, add cookie value as // oauth session attribute. if (session.getAttribute(OAUTH_TOKEN) == null) { Cookie[] cookies = request.getCookies(); if (cookies != null) { // Loop through cookies to find dashboard cookie for (Cookie c : cookies) { if (c.getName().equals(DASHBOARD_COOKIE)) { // DE883. We need to decrypt the cookie value to authenticate the token. String decryptedCookie = null; try { String s = URLDecoder.decode(c.getValue(), "UTF-8"); decryptedCookie = propDecryptor.decrypt(s); } catch (Exception e) { LOG.error(e.getMessage()); }/* www . j a v a 2s .co m*/ JsonObject json = restClient.sessionCheck(decryptedCookie); // If user is not authenticated, expire the cookie, else set OAUTH_TOKEN to // cookie value and continue JsonElement authElement = json.get(Constants.ATTR_AUTHENTICATED); if ((authElement != null) && (!authElement.getAsBoolean())) { c.setMaxAge(0); LOG.info(LOG_MESSAGE_AUTH_EXPIRING_COOKIE, new Object[] { request.getRemoteAddr() }); } else { cookieFound = true; session.setAttribute(OAUTH_TOKEN, decryptedCookie); LOG.info(LOG_MESSAGE_AUTH_USING_COOKIE, new Object[] { request.getRemoteAddr() }); } } } } } return cookieFound; }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
public static String getValueFromCookies(HttpServletRequest request, String cookieName) { String cookieValue = ""; Cookie[] cookieArray = request.getCookies(); if (cookieArray != null) { for (int i = 0; i < cookieArray.length; i++) { Cookie aCookie = cookieArray[i]; if (cookieName.equals(aCookie.getName())) { cookieValue = aCookie.getValue(); }/*from ww w .ja v a 2s . c om*/ } } return cookieValue; }
From source file:org.apache.hadoop.security.authentication.server.AuthenticationFilter.java
/** * Returns the {@link AuthenticationToken} for the request. * <p/>//w ww .ja v a2 s. c o m * It looks at the received HTTP cookies and extracts the value of the {@link AuthenticatedURL#AUTH_COOKIE} * if present. It verifies the signature and if correct it creates the {@link AuthenticationToken} and returns * it. * <p/> * If this method returns <code>null</code> the filter will invoke the configured {@link AuthenticationHandler} * to perform user authentication. * * @param request request object. * * @return the Authentication token if the request is authenticated, <code>null</code> otherwise. * * @throws IOException thrown if an IO error occurred. * @throws AuthenticationException thrown if the token is invalid or if it has expired. */ protected AuthenticationToken getToken(HttpServletRequest request) throws IOException, AuthenticationException { AuthenticationToken token = null; String tokenStr = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(AuthenticatedURL.AUTH_COOKIE)) { tokenStr = cookie.getValue(); try { tokenStr = signer.verifyAndExtract(tokenStr); } catch (SignerException ex) { throw new AuthenticationException(ex); } break; } } } if (tokenStr != null) { token = AuthenticationToken.parse(tokenStr); if (!token.getType().equals(authHandler.getType())) { throw new AuthenticationException("Invalid AuthenticationToken type"); } if (token.isExpired()) { throw new AuthenticationException("AuthenticationToken expired"); } } return token; }
From source file:edu.jhu.pha.vospace.oauth.AuthorizationServlet.java
/** * @param request//w w w . j a v a 2 s. c o m * @param response * @param callbackUrl * @throws IOException * @throws Oops */ private void authorizeRequestToken(HttpServletRequest request, HttpServletResponse response, String username) throws Oops { String token = null, callbackUrl = null; Cookie[] cookies = request.getCookies(); String shareId = null; if (null != request.getParameter("oauth_token")) { token = request.getParameter("oauth_token"); callbackUrl = request.getParameter("oauth_callback"); } else if (cookies != null) { OauthCookie parsedCookie = null; for (Cookie cookie : cookies) { if (cookie.getName().equals(OauthCookie.COOKIE_NAME)) { // Remove the temporary 3rd party app cookie Cookie removeCookie = new Cookie(OauthCookie.COOKIE_NAME, ""); removeCookie.setMaxAge(0); response.addCookie(removeCookie); try { parsedCookie = OauthCookie.create(cookie); shareId = parsedCookie.getShareId(); if (isBlank(parsedCookie.getRequestToken())) throw new Oops( "No request token present in oauth cookie (\"" + cookie.getValue() + "\")."); logger.debug("Parsed oauth cookie \"" + cookie.getValue() + "\" as \"" + parsedCookie.toString() + "\"."); } catch (IOException e) { logger.debug("Error parsing cookie. Just removing it."); } } } if (null != parsedCookie) { token = parsedCookie.getRequestToken(); callbackUrl = parsedCookie.getCallbackUrl(); } } if (null == token) throw new Oops("No request token found in request."); try { Token reqToken = MySQLOAuthProvider2.getRequestToken(token); if (null == reqToken) throw new PermissionDeniedException("401 Unauthorized"); if (null != reqToken.getAttributes().getFirst("root_container")) { // pre-shared container accessor if (shareId != null) {//already created the share - user bound sharing List<String> groupUserLogins = MySQLOAuthProvider2.getShareUsers(shareId); if (!groupUserLogins.contains(username)) { // the username of the one authorized != user that share was created for throw new PermissionDeniedException("401 Unauthorized"); } } // else share is open for everyone } MySQLOAuthProvider2.markAsAuthorized(reqToken, username); if (null != callbackUrl && !callbackUrl.isEmpty()) { if (callbackUrl.indexOf('?') <= 0) callbackUrl += "?" + "oauth_token=" + reqToken.getToken(); else callbackUrl += "&" + "oauth_token=" + reqToken.getToken(); logger.debug("Redirecting user to " + callbackUrl); response.sendRedirect(callbackUrl); } else { response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("You have successfully authorized " + ".\nPlease close this browser window and click continue" + " in the client."); out.close(); } } catch (IOException e) { logger.error("Error performing the token authorization " + e.getMessage()); e.printStackTrace(); throw new Oops(e.getMessage()); } }
From source file:de.micromata.genome.tpsb.httpmockup.testbuilder.ServletContextTestBuilder.java
private void storeCookies() { if (storeCookies == false) { return;// w w w . j a va 2 s . co m } Cookie[] cooks = httpResponse.getCookies(); if (cooks == null) { return; } for (Cookie c : cooks) { cookies.put(c.getName(), c); } }
From source file:fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService.java
/** * Extract the value of the connection cookie * * @param request//from ww w . ja va 2 s . c o m * The HTTP request * @return The cookie's value */ public String getConnectionCookie(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); String strOpenamCookie = null; if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(COOKIE_OPENAM_NAME)) { strOpenamCookie = cookie.getValue(); OpenamAPI._logger.debug("getHttpAuthenticatedUser : cookie '" + COOKIE_OPENAM_NAME + "' found - value=" + strOpenamCookie); } } } return strOpenamCookie; }
From source file:ed.net.CookieJar.java
/** * Returns all applicable cookies for the given url. * @param requestingUrl/*from w w w. j a v a 2 s . c o m*/ * @return */ public Map<String, Cookie> getActiveCookies(URL requestingUrl) { Map<String, Cookie> cookiesToSend = new HashMap<String, Cookie>(); for (Cookie c : _cookies.values()) { if (match(requestingUrl, c)) cookiesToSend.put(c.getName(), c); } return cookiesToSend; }