Example #1
0
 public static void removeToken(
     HttpServletRequest request, HttpServletResponse response, String name) {
   Cookie cookie = CookieUtil.getCookie(request, name);
   cookie.setMaxAge(0);
   cookie.setValue(null);
   CookieUtil.addCookie(response, cookie);
 }
Example #2
0
 public static String getToken(
     HttpServletRequest request, HttpServletResponse response, String name) {
   String value = CookieUtil.getValue(request, name);
   try {
     if (StringUtil.isNotBlank(value)) {
       value = URLDecoder.decode(value, CharsetConstant.UTF_8);
       return AESUtil.decryptBase64(secKey, value);
     }
   } catch (Exception e) {
     logger.error("Read cookie failured!", e);
   }
   return null;
 }
Example #3
0
 public static void saveToken(
     HttpServletRequest request, HttpServletResponse response, String name, String token) {
   if (StringUtil.isBlank(token)) {
     return;
   }
   try {
     token = AESUtil.encryptBase64(secKey, token);
     token = URLEncoder.encode(token, CharsetConstant.UTF_8);
     Cookie secCookie = new Cookie(name, token);
     secCookie.setPath(SymbolConstant.SLASH);
     CookieUtil.addCookie(response, secCookie);
   } catch (Exception e) {
     logger.error("Save Cookie failure!", e);
   }
 }