Search in sources :

Example 1 with ServletCookie

use of org.wso2.carbon.core.ServletCookie in project identity-inbound-auth-oauth by wso2-extensions.

the class CookieBasedTokenBinder method setTokenBindingValueForResponse.

@Override
public void setTokenBindingValueForResponse(HttpServletResponse response, String bindingValue) {
    ServletCookie cookie = new ServletCookie(COOKIE_NAME, bindingValue);
    cookie.setSecure(true);
    cookie.setHttpOnly(true);
    cookie.setPath("/");
    cookie.setSameSite(SameSiteCookie.NONE);
    response.addCookie(cookie);
}
Also used : ServletCookie(org.wso2.carbon.core.ServletCookie)

Example 2 with ServletCookie

use of org.wso2.carbon.core.ServletCookie in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCSessionManagementUtil method removeOPBrowserStateCookie.

/**
 * Invalidate the browser state cookie.
 *
 * @param request
 * @param response
 * @return invalidated cookie
 */
public static Cookie removeOPBrowserStateCookie(HttpServletRequest request, HttpServletResponse response) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(OIDCSessionConstants.OPBS_COOKIE_ID)) {
                ServletCookie servletCookie = new ServletCookie(cookie.getName(), cookie.getValue());
                servletCookie.setMaxAge(0);
                servletCookie.setSecure(true);
                if (IdentityTenantUtil.isTenantedSessionsEnabled()) {
                    // check whether the opbs cookie has a tenanted path.
                    if (cookie.getValue().endsWith(OIDCSessionConstants.TENANT_QUALIFIED_OPBS_COOKIE_SUFFIX)) {
                        String tenantDomain = resolveTenantDomain(request);
                        servletCookie.setPath(FrameworkConstants.TENANT_CONTEXT_PREFIX + tenantDomain + "/");
                    } else {
                        servletCookie.setPath("/");
                    }
                } else {
                    servletCookie.setPath("/");
                }
                servletCookie.setSameSite(SameSiteCookie.NONE);
                response.addCookie(servletCookie);
                return cookie;
            }
        }
    }
    return null;
}
Also used : Cookie(javax.servlet.http.Cookie) SameSiteCookie(org.wso2.carbon.core.SameSiteCookie) ServletCookie(org.wso2.carbon.core.ServletCookie) ServletCookie(org.wso2.carbon.core.ServletCookie)

Example 3 with ServletCookie

use of org.wso2.carbon.core.ServletCookie in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultOIDCSessionStateManager method addOPBrowserStateCookie.

/**
 * Adds the browser state cookie to the response.
 *
 * @param response
 * @return Cookie
 */
public Cookie addOPBrowserStateCookie(HttpServletResponse response) {
    ServletCookie cookie = new ServletCookie(OIDCSessionConstants.OPBS_COOKIE_ID, UUID.randomUUID().toString());
    cookie.setSecure(true);
    cookie.setPath("/");
    cookie.setSameSite(SameSiteCookie.NONE);
    response.addCookie(cookie);
    return cookie;
}
Also used : ServletCookie(org.wso2.carbon.core.ServletCookie)

Example 4 with ServletCookie

use of org.wso2.carbon.core.ServletCookie in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultOIDCSessionStateManager method addOPBrowserStateCookie.

/**
 * Adds the browser state cookie with tenant qualified path to the response.
 *
 * @param response
 * @param request
 * @param loginTenantDomain
 * @param opbsValue
 * @return Cookie
 */
@Override
public Cookie addOPBrowserStateCookie(HttpServletResponse response, HttpServletRequest request, String loginTenantDomain, String opbsValue) {
    ServletCookie cookie;
    if (IdentityTenantUtil.isTenantedSessionsEnabled() && loginTenantDomain != null) {
        // Invalidate the old opbs cookies which haven't tenanted paths.
        removeOPBrowserStateCookiesInRoot(request, response);
        cookie = new ServletCookie(OIDCSessionConstants.OPBS_COOKIE_ID, opbsValue);
        cookie.setPath(FrameworkConstants.TENANT_CONTEXT_PREFIX + loginTenantDomain + "/");
    } else {
        cookie = new ServletCookie(OIDCSessionConstants.OPBS_COOKIE_ID, opbsValue);
        cookie.setPath("/");
    }
    cookie.setSecure(true);
    cookie.setSameSite(SameSiteCookie.NONE);
    response.addCookie(cookie);
    return cookie;
}
Also used : ServletCookie(org.wso2.carbon.core.ServletCookie)

Example 5 with ServletCookie

use of org.wso2.carbon.core.ServletCookie in project identity-inbound-auth-oauth by wso2-extensions.

the class DefaultOIDCSessionStateManager method removeOPBrowserStateCookiesInRoot.

/**
 * Invalidate the old opbs cookies which haven't tenanted paths.
 *
 * @param request
 * @param response
 */
private static void removeOPBrowserStateCookiesInRoot(HttpServletRequest request, HttpServletResponse response) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return;
    }
    for (Cookie cookie : cookies) {
        if (cookie != null && cookie.getName().equals(OIDCSessionConstants.OPBS_COOKIE_ID)) {
            if (cookie.getValue().endsWith(OIDCSessionConstants.TENANT_QUALIFIED_OPBS_COOKIE_SUFFIX)) {
                continue;
            } else {
                ServletCookie oldCookie = new ServletCookie(cookie.getName(), cookie.getValue());
                oldCookie.setMaxAge(0);
                oldCookie.setSecure(true);
                oldCookie.setPath("/");
                oldCookie.setSameSite(SameSiteCookie.NONE);
                response.addCookie(oldCookie);
                if (log.isDebugEnabled()) {
                    log.debug("OPBS cookie was found with the root path and Invalidated it.");
                }
            }
        }
    }
}
Also used : SameSiteCookie(org.wso2.carbon.core.SameSiteCookie) ServletCookie(org.wso2.carbon.core.ServletCookie) Cookie(javax.servlet.http.Cookie) ServletCookie(org.wso2.carbon.core.ServletCookie)

Aggregations

ServletCookie (org.wso2.carbon.core.ServletCookie)5 Cookie (javax.servlet.http.Cookie)2 SameSiteCookie (org.wso2.carbon.core.SameSiteCookie)2