Search in sources :

Example 1 with CookieSetting

use of org.restlet.data.CookieSetting in project OpenAM by OpenRock.

the class LoginHintHook method beforeAuthorizeHandling.

/**
     * Adds the login_hint value to cookie.
     * @param o2request The current OAuth2 request.
     * @param request The restlet request.
     * @param response The restlet response.
     */
@Override
public void beforeAuthorizeHandling(OAuth2Request o2request, Request request, Response response) {
    String loginHint = o2request.getParameter(LOGIN_HINT);
    if (loginHint != null && !loginHint.equals(request.getCookies().getFirstValue(LOGIN_HINT_COOKIE))) {
        CookieSetting cookie = new CookieSetting(0, LOGIN_HINT_COOKIE, loginHint);
        cookie.setPath("/");
        // set HttpOnly flag
        cookie.setAccessRestricted(true);
        response.getCookieSettings().add(cookie);
    }
}
Also used : CookieSetting(org.restlet.data.CookieSetting)

Example 2 with CookieSetting

use of org.restlet.data.CookieSetting in project OpenAM by OpenRock.

the class LoginHintHook method removeCookie.

private void removeCookie(Request request, Response response) {
    // Delete the login hint cookie if it exists
    if (request.getCookies().getFirst(LOGIN_HINT_COOKIE) != null) {
        CookieSetting cookie = new CookieSetting(0, LOGIN_HINT_COOKIE, "");
        cookie.setMaxAge(0);
        response.getCookieSettings().add(cookie);
    }
}
Also used : CookieSetting(org.restlet.data.CookieSetting)

Example 3 with CookieSetting

use of org.restlet.data.CookieSetting in project OpenAM by OpenRock.

the class LoginHintHook method afterAuthorizeSuccess.

/**
     * Once we're returning an auth code we can remove the login hint cookie.
     * @param o2request The current OAuth2 request.
     * @param request The restlet request.
     * @param response The restlet response.
     */
@Override
public void afterAuthorizeSuccess(OAuth2Request o2request, Request request, Response response) {
    // If we're still in the original authorize request, stop setting the cookie in the response
    Series<CookieSetting> cookiesSetInThisResponse = response.getCookieSettings();
    CookieSetting loginHintCookieSetting = cookiesSetInThisResponse.getFirst(LOGIN_HINT_COOKIE);
    if (loginHintCookieSetting != null && loginHintCookieSetting.getMaxAge() != 0) {
        cookiesSetInThisResponse.removeFirst(LOGIN_HINT_COOKIE);
    }
    removeCookie(request, response);
}
Also used : CookieSetting(org.restlet.data.CookieSetting)

Example 4 with CookieSetting

use of org.restlet.data.CookieSetting in project camel by apache.

the class RestletProducer method storeCookies.

private void storeCookies(Exchange exchange, URI uri, Response response) {
    RestletEndpoint endpoint = (RestletEndpoint) getEndpoint();
    if (endpoint.getCookieHandler() != null) {
        Series<CookieSetting> cookieSettings = response.getCookieSettings();
        CookieStore cookieJar = endpoint.getCookieHandler().getCookieStore(exchange);
        for (CookieSetting s : cookieSettings) {
            HttpCookie cookie = new HttpCookie(s.getName(), s.getValue());
            cookie.setComment(s.getComment());
            cookie.setDomain(s.getDomain());
            cookie.setMaxAge(s.getMaxAge());
            cookie.setPath(s.getPath());
            cookie.setSecure(s.isSecure());
            cookie.setVersion(s.getVersion());
            cookieJar.add(uri, cookie);
        }
    }
}
Also used : CookieSetting(org.restlet.data.CookieSetting) CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie)

Aggregations

CookieSetting (org.restlet.data.CookieSetting)4 CookieStore (java.net.CookieStore)1 HttpCookie (java.net.HttpCookie)1