本文整理汇总了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();
}
示例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);
}
}
示例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);
}
示例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();
}
示例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"));
}