use of org.wso2.carbon.identity.core.model.IdentityCookieConfig in project carbon-identity-framework by wso2.
the class FrameworkUtilsTest method testSetCookieExistCookieConfig.
@Test
public void testSetCookieExistCookieConfig() {
mockCookieTest();
IdentityCookieConfig cookieConfig = new IdentityCookieConfig(FrameworkConstants.COMMONAUTH_COOKIE);
IdentityUtil.getIdentityCookiesConfigurationHolder().put(FrameworkConstants.COMMONAUTH_COOKIE, cookieConfig);
int age = 3600;
FrameworkUtils.setCookie(request, response, FrameworkConstants.COMMONAUTH_COOKIE, "commonAuthIdValue", age);
verify(response, times(1)).addCookie(cookieCaptor.capture());
List<Cookie> capturedCookies = cookieCaptor.getAllValues();
Cookie storedCookie = capturedCookies.get(0);
assertEquals(storedCookie.getName(), FrameworkConstants.COMMONAUTH_COOKIE);
assertEquals(storedCookie.getPath(), ROOT_DOMAIN);
assertEquals(storedCookie.getMaxAge(), age);
}
use of org.wso2.carbon.identity.core.model.IdentityCookieConfig in project carbon-identity-framework by wso2.
the class FrameworkUtilsTest method testRemoveCookieExistCookieConfig.
@Test
public void testRemoveCookieExistCookieConfig() {
mockCookieTest();
IdentityCookieConfig cookieConfig = new IdentityCookieConfig(FrameworkConstants.COMMONAUTH_COOKIE);
IdentityUtil.getIdentityCookiesConfigurationHolder().put(FrameworkConstants.COMMONAUTH_COOKIE, cookieConfig);
FrameworkUtils.removeCookie(request, response, FrameworkConstants.COMMONAUTH_COOKIE, SameSiteCookie.STRICT, ROOT_DOMAIN);
verify(response, times(1)).addCookie(cookieCaptor.capture());
List<Cookie> capturedCookies = cookieCaptor.getAllValues();
Cookie removedCookie = capturedCookies.get(0);
assertEquals(removedCookie.getName(), FrameworkConstants.COMMONAUTH_COOKIE);
assertEquals(removedCookie.getPath(), ROOT_DOMAIN);
assertEquals(removedCookie.getMaxAge(), 0);
}
use of org.wso2.carbon.identity.core.model.IdentityCookieConfig 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;
}
}
}
}
use of org.wso2.carbon.identity.core.model.IdentityCookieConfig in project carbon-identity-framework by wso2.
the class FrameworkUtilsTest method testSetCookieWithSameSiteExistCookieConfig.
@Test
public void testSetCookieWithSameSiteExistCookieConfig() {
mockCookieTest();
IdentityCookieConfig cookieConfig = new IdentityCookieConfig(FrameworkConstants.COMMONAUTH_COOKIE);
IdentityUtil.getIdentityCookiesConfigurationHolder().put(FrameworkConstants.COMMONAUTH_COOKIE, cookieConfig);
int age = 3600;
FrameworkUtils.setCookie(request, response, FrameworkConstants.COMMONAUTH_COOKIE, "commonAuthIdValue", age, SameSiteCookie.STRICT, "Dummy-Path");
verify(response, times(1)).addCookie(cookieCaptor.capture());
List<Cookie> capturedCookies = cookieCaptor.getAllValues();
Cookie storedCookie = capturedCookies.get(0);
assertEquals(storedCookie.getName(), FrameworkConstants.COMMONAUTH_COOKIE);
assertEquals(storedCookie.getPath(), "Dummy-Path");
assertEquals(storedCookie.getMaxAge(), age);
}
use of org.wso2.carbon.identity.core.model.IdentityCookieConfig in project carbon-identity-framework by wso2.
the class IdentityUtilTest method testGetIdentityCookiesConfigurationHolder.
@Test
public void testGetIdentityCookiesConfigurationHolder() throws Exception {
Map<String, IdentityCookieConfig> mockIdentityCookiesConfigurationHolder = new HashMap<>();
mockIdentityCookiesConfigurationHolder.put("cookie", new IdentityCookieConfig("cookieName"));
Whitebox.setInternalState(IdentityUtil.class, "identityCookiesConfigurationHolder", mockIdentityCookiesConfigurationHolder);
assertEquals(IdentityUtil.getIdentityCookiesConfigurationHolder(), mockIdentityCookiesConfigurationHolder, "Returned cookie holder doesn't match the given.");
}
Aggregations