Java 类play.mvc.Http.Cookie 实例源码

项目:app-framework    文件:AbstractAuthenticator.java   
/**
 * Clear the user session and logout the user.<br/>
 * The user is then redirected to the login page.
 */
public Result customLogout() {
    if (log.isDebugEnabled()) {
        log.debug("Logout requested");
    }
    // Workaround
    // Clear redmine cookie
    Cookie redmineCookie = ctx().request().cookie("_redmine_session");
    if (redmineCookie != null) {
        ctx().response().discardCookie("_redmine_session");
    }
    if (getAuthenticationMode().equals(AuthenticationMode.FEDERATED)) {
        return getFederatedLogoutDisplay();
    }
    return logoutAndRedirect();
}
项目:restcommander    文件:ValidationPlugin.java   
static Validation restore() {
    try {
        Validation validation = new Validation();
        Http.Cookie cookie = Http.Request.current().cookies.get(Scope.COOKIE_PREFIX + "_ERRORS");
        if (cookie != null) {
            String errorsData = URLDecoder.decode(cookie.value, "utf-8");
            Matcher matcher = errorsParser.matcher(errorsData);
            while (matcher.find()) {
                String[] g2 = matcher.group(2).split("\u0001");
                String message = g2[0];
                String[] args = new String[g2.length - 1];
                System.arraycopy(g2, 1, args, 0, args.length);
                validation.errors.add(new Error(matcher.group(1), message, args));
            }
        }
        return validation;
    } catch (Exception e) {
        return new Validation();
    }
}
项目:vos_backend    文件:JavaApi.java   
public static Result readCookie(String name) {
    Cookie cookie = request().cookies().get(name);
    if (cookie != null) {
        return ok("Cookie " + name + " has value: " + cookie.value());
    } else {
        return ok();
    }
}
项目:app-framework    文件:AbstractAuthenticator.java   
/**
 * Get the previously set redirection URL.<br/>
 * WARNING: this is used with the STANDALONE authentication mode since it
 * seems the redirect is not working
 * 
 * @return
 */
public String getRedirectUrlInSession() {
    Cookie redirectUrlCookie = request().cookie(REDIRECT_URL_COOKIE_NAME);
    if (redirectUrlCookie != null && redirectUrlCookie.value() != null) {
        response().discardCookie(REDIRECT_URL_COOKIE_NAME);
        return redirectUrlCookie.value();
    }
    // If no redirect URL then redirect to the public URL
    return getPreferenceManagerPlugin().getPreferenceElseConfigurationValue(IFrameworkConstants.PUBLIC_URL_PREFERENCE, "maf.public.url");
}
项目:restcommander    文件:ValidationPlugin.java   
static void clear() {
    try {
        if (Http.Response.current() != null && Http.Response.current().cookies != null) {
            Cookie cookie = new Cookie();
            cookie.name = Scope.COOKIE_PREFIX + "_ERRORS";
            cookie.value = "";
            cookie.sendOnError = true;
            Http.Response.current().cookies.put(cookie.name, cookie);
        }
    } catch (Exception e) {
        throw new UnexpectedException("Errors serializationProblem", e);
    }
}
项目:play-oauth2    文件:SecurityContextFilter.java   
public SecurityContext loadSecurityContext(Context context) {
  if (context != null) {
    Cookie cookie = context.request().cookie(SECURITY_CONTEXT_COOKIE);
    if (cookie != null) {
      return (SecurityContext) Cache.get(cookie.value());
    }
  }
  return SecurityContextHolder.createEmptyContext();
}
项目:play-oauth2    文件:SecurityContextFilter.java   
public void saveSecurityContext(Context context, SecurityContext securityContext) {
  Cookie cookie = context.request().cookie(SECURITY_CONTEXT_COOKIE);
  if (cookie != null) {
    Cache.remove(cookie.value());
  }
  String randomUuid = UUID.randomUUID().toString();
  context.response().setCookie(SECURITY_CONTEXT_COOKIE, randomUuid, EXPIRATION_IN_SECONDS);
  Cache.set(randomUuid, securityContext, EXPIRATION_IN_SECONDS);
}
项目:play-plugins    文件:SecurityContextAction.java   
@Override
public Promise<Result> call(Context context) throws Throwable {
  SecurityPlugin securityPlugin = SecurityPlugin.getInstance();
  SecurityContextStore securityContextStore = securityPlugin.getSecurityContextStore();

  String cookieName = configuration.value().isEmpty() ? securityPlugin.getSecurityCookie()
      : configuration.value();
  Cookie cookie = context == null ? null : context.request().cookie(cookieName);
  String id = cookie == null ? null : cookie.value();

  if (id != null) {
    SecurityContextHolder.setContext(securityContextStore.load(id));
  }

  return delegate.call(context).map(result -> {
    org.springframework.security.core.context.SecurityContext currentContext =
        SecurityContextHolder.getContext();
    SecurityContextHolder.clearContext();
    org.springframework.security.core.context.SecurityContext emptyContext =
        SecurityContextHolder.getContext();
    boolean hasSecurityContext = !currentContext.equals(emptyContext);

    if (id != null) {
      securityContextStore.remove(id);
      if (!hasSecurityContext) {
        context.response().discardCookie(cookieName);
      }
    }

    if (hasSecurityContext) {
      int expirationInSeconds = configuration.expirationInSeconds();
      if (expirationInSeconds < 0) {
        expirationInSeconds = securityPlugin.getExpirationInSeconds();
      }

      String newId = UUID.randomUUID().toString();
      context.response().setCookie(cookieName, newId, expirationInSeconds);
      securityContextStore.save(newId, SecurityContextHolder.getContext(), expirationInSeconds);
    }

    return result;
  });
}