18 package org.turro.elephant.impl.util;
20 import java.io.IOException;
21 import javax.servlet.http.Cookie;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import org.apache.commons.codec.DecoderException;
25 import org.apache.commons.codec.binary.Base64;
26 import org.turro.elephant.context.ElephantContext;
36 public static Cookie
getCookie(HttpServletRequest request, String name) {
37 Cookie[] cookies = request.getCookies();
38 if(cookies ==
null)
return null;
39 for(
int i = 0; i < cookies.length; i++)
40 if(cookies[i].getName().equals(name))
45 public static void setCookie(HttpServletResponse response, String name, String value, String path,
int age) {
46 Cookie cookie =
new Cookie(name, value);
49 cookie.setMaxAge(age);
50 response.addCookie(cookie);
53 public static void deleteCookie(HttpServletResponse response, String name, String path) {
54 Cookie cookie =
new Cookie(name,
null);
57 response.addCookie(cookie);
60 public static void encryptCookie(HttpServletResponse response, String name,
byte[] value, String path,
int age) {
61 Cookie cookie =
new Cookie(name,
new String(
new Base64().encode(value)));
65 cookie.setMaxAge(age);
66 response.addCookie(cookie);
70 return cookie ==
null ? null :
new Base64().decode(cookie.getValue().getBytes());
static boolean getUseSSL()
static Cookie getCookie(HttpServletRequest request, String name)
static void setCookie(HttpServletResponse response, String name, String value, String path, int age)
static byte[] decryptCookieValue(Cookie cookie)
static void encryptCookie(HttpServletResponse response, String name, byte[] value, String path, int age)
static void deleteCookie(HttpServletResponse response, String name, String path)