use of org.wso2.carbon.identity.core.model.CookieBuilder in project carbon-identity-framework by wso2.
the class FrameworkUtils method setCookie.
public static void setCookie(HttpServletRequest req, HttpServletResponse resp, String cookieName, String id, Integer age, SameSiteCookie setSameSite, String path) {
CookieBuilder cookieBuilder = new CookieBuilder(cookieName, id);
IdentityCookieConfig cookieConfig = IdentityUtil.getIdentityCookieConfig(cookieName);
if (cookieConfig != null) {
updateCookieConfig(cookieBuilder, cookieConfig, age, path);
} else {
cookieBuilder.setSecure(true);
cookieBuilder.setHttpOnly(true);
cookieBuilder.setPath(StringUtils.isNotBlank(path) ? path : ROOT_DOMAIN);
cookieBuilder.setSameSite(setSameSite);
if (age != null) {
cookieBuilder.setMaxAge(age);
}
}
resp.addCookie(cookieBuilder.build());
}
use of org.wso2.carbon.identity.core.model.CookieBuilder in project carbon-identity-framework by wso2.
the class FrameworkUtils method setCookie.
/**
* Stores a cookie to the response taking configurations from identity.xml file.
*
* @param req Incoming HttpSerletRequest.
* @param resp Outgoing HttpServletResponse.
* @param cookieName Name of the cookie to be stored.
* @param id Cookie id.
* @param age Max age of the cookie.
*/
public static void setCookie(HttpServletRequest req, HttpServletResponse resp, String cookieName, String id, Integer age) {
CookieBuilder cookieBuilder = new CookieBuilder(cookieName, id);
IdentityCookieConfig cookieConfig = IdentityUtil.getIdentityCookieConfig(cookieName);
if (cookieConfig != null) {
updateCookieConfig(cookieBuilder, cookieConfig, age, null);
} else {
cookieBuilder.setSecure(true);
cookieBuilder.setHttpOnly(true);
cookieBuilder.setPath(ROOT_DOMAIN);
if (age != null) {
cookieBuilder.setMaxAge(age);
}
}
resp.addCookie(cookieBuilder.build());
}
use of org.wso2.carbon.identity.core.model.CookieBuilder in project carbon-identity-framework by wso2.
the class FrameworkUtils method removeCookie.
public static void removeCookie(HttpServletRequest req, HttpServletResponse resp, String cookieName, SameSiteCookie sameSiteCookie, String path) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookieName)) {
CookieBuilder cookieBuilder = new CookieBuilder(cookieName, cookie.getValue());
IdentityCookieConfig cookieConfig = IdentityUtil.getIdentityCookieConfig(cookieName);
if (cookieConfig != null) {
updateCookieConfig(cookieBuilder, cookieConfig, 0, path);
} else {
cookieBuilder.setHttpOnly(true);
cookieBuilder.setSecure(true);
cookieBuilder.setPath(StringUtils.isNotBlank(path) ? path : ROOT_DOMAIN);
cookieBuilder.setSameSite(sameSiteCookie);
}
cookieBuilder.setMaxAge(0);
resp.addCookie(cookieBuilder.build());
break;
}
}
}
}
use of org.wso2.carbon.identity.core.model.CookieBuilder in project carbon-identity-framework by wso2.
the class FrameworkUtils method removeCookie.
/**
* Removes a cookie which is already stored.
*
* @param req Incoming HttpServletRequest.
* @param resp HttpServletResponse which should be stored.
* @param cookieName Name of the cookie which should be removed.
*/
public static void removeCookie(HttpServletRequest req, HttpServletResponse resp, String cookieName) {
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookieName)) {
CookieBuilder cookieBuilder = new CookieBuilder(cookieName, cookie.getValue());
IdentityCookieConfig cookieConfig = IdentityUtil.getIdentityCookieConfig(cookieName);
if (cookieConfig != null) {
updateCookieConfig(cookieBuilder, cookieConfig, 0, ROOT_DOMAIN);
} else {
cookieBuilder.setHttpOnly(true);
cookieBuilder.setSecure(true);
cookieBuilder.setPath(ROOT_DOMAIN);
}
cookieBuilder.setMaxAge(0);
resp.addCookie(cookieBuilder.build());
break;
}
}
}
}
Aggregations