You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

50 lines
1.5 KiB

package com.fr.plugin.oauth.utils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieUtils {
public static final String COOKIE_LOGINPATH_NAME = "loginpath";
public static final String COOKIE_LOGINPATH_VALUE = "sso";
public static void setLoginCookie(HttpServletResponse res) {
Cookie cookie = new Cookie(COOKIE_LOGINPATH_NAME, COOKIE_LOGINPATH_VALUE);
cookie.setPath("/");
res.addCookie(cookie);
}
public static boolean isLoginFromSSO(HttpServletRequest req) {
Cookie[] cookies = req.getCookies();
for (Cookie cookie : cookies) {
if (COOKIE_LOGINPATH_NAME.equals(cookie.getName())) {
if (COOKIE_LOGINPATH_VALUE.equals(cookie.getValue())) {
return true;
}
}
}
return false;
}
public static Cookie getCookie(HttpServletRequest req, String name) {
Cookie[] cookies = req.getCookies();
for (Cookie cookie : cookies) {
if (name.equals(cookie.getName())) {
return cookie;
}
}
return null;
}
public static Cookie getLoginPathCookie(HttpServletRequest req) {
return getCookie(req, COOKIE_LOGINPATH_NAME);
}
public static void deleteCookie(HttpServletResponse res, Cookie cookie) {
if (cookie != null){
cookie.setMaxAge(0);
res.addCookie(cookie);
}
}
}