当前位置: 首页>>代码示例>>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;未经允许,请勿转载。