當前位置: 首頁>>代碼示例>>Java>>正文


Java Http.Cookie方法代碼示例

本文整理匯總了Java中play.mvc.Http.Cookie方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.Cookie方法的具體用法?Java Http.Cookie怎麽用?Java Http.Cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在play.mvc.Http的用法示例。


在下文中一共展示了Http.Cookie方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: login

import play.mvc.Http; //導入方法依賴的package包/類
public static void login() throws Throwable {
    Http.Cookie remember = request.cookies.get("rememberme");
    if(remember != null) {
        int firstIndex = remember.value.indexOf("-");
        int lastIndex = remember.value.lastIndexOf("-");
        if (lastIndex > firstIndex) {
            String sign = remember.value.substring(0, firstIndex);
            String restOfCookie = remember.value.substring(firstIndex + 1);
            String username = remember.value.substring(firstIndex + 1, lastIndex);
            String time = remember.value.substring(lastIndex + 1);
            Date expirationDate = new Date(Long.parseLong(time)); // surround with try/catch?
            Date now = new Date();
            if (expirationDate == null || expirationDate.before(now)) {
                logout();
            }
            if(Crypto.sign(restOfCookie).equals(sign)) {
                session.put("username", username);
                redirectToOriginalURL();
            }
        }
    }
    flash.keep("url");
    render();
}
 
開發者ID:xandradx,項目名稱:ovirt-engine-disaster-recovery,代碼行數:25,代碼來源:Secure.java

示例2: call

import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> call(Http.Context ctx) {
    Http.Cookie ltat = ctx.request().cookie("ltat");
    boolean valid = configuration.optional();
    if(ltat != null) {
        User user = jwtUtils.validateCookie(ltat.value());
        if(user != null) {
            if (user.isDisabled()) {
                flash("error", "Your account was disabled.");
                Http.Cookie ltatRemove = Http.Cookie.builder("ltat", "")
                        .withPath("/").withHttpOnly(true).withMaxAge(Duration.ZERO).build();
                return CompletableFuture.completedFuture(redirect(routes.LoginController.get(null)).withCookies(ltatRemove));
            }
            if(!configuration.requireAdmin() || user.isAdmin()){
                ctx = ctx.withRequest(ctx.request().addAttr(AuthorizationServerSecure.USER, user));
                valid = true;
            } else {
                return CompletableFuture.completedFuture(unauthorized(Json.newObject()
                        .put("message", "you are not authorized for this operation")
                ));
            }
        }
    }
    if(!valid) {
        return CompletableFuture.completedFuture(redirect(routes.LoginController.get(ctx.request().uri())));
    } else { // pass on
        return delegate.call(ctx);
    }
}
 
開發者ID:bekce,項目名稱:oauthly,代碼行數:30,代碼來源:AuthorizationServerAuthAction.java

示例3: prepareCookieThenRedirect

import play.mvc.Http; //導入方法依賴的package包/類
public Result prepareCookieThenRedirect(User user, String next){
    Http.Cookie ltat = prepareCookie(user);
    if(next != null && next.matches("^/.*$"))
        return redirect(next).withCookies(ltat);
    else
        return redirect(routes.ProfileController.get()).withCookies(ltat);
}
 
開發者ID:bekce,項目名稱:oauthly,代碼行數:8,代碼來源:JwtUtils.java

示例4: prepareCookie

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Cookie prepareCookie(User user){
    return Http.Cookie.builder("ltat", prepareCookieValue(user)).withPath("/").withHttpOnly(true).withMaxAge(expireCookie).withSecure(useSecureSessionCookie).build();
}
 
開發者ID:bekce,項目名稱:oauthly,代碼行數:4,代碼來源:JwtUtils.java

示例5: show4

import play.mvc.Http; //導入方法依賴的package包/類
public Result show4(final String name) {
    final Http.Cookie nameCookie = request().cookie("name");
    response().setCookie(Http.Cookie.builder("name", name).build());
    return ok("Hello " + name + "! Bye " + (nameCookie != null ? nameCookie.value() : "stranger"));
}
 
開發者ID:commercetools,項目名稱:commercetools-sunrise-java-training,代碼行數:6,代碼來源:MyController.java


注:本文中的play.mvc.Http.Cookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。