Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014 Thomas Feng Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
import  play.libs.F.Promise;
import  play.mvc.Action;
import  play.mvc.Http.Context;
import  play.mvc.Http.Cookie;
import  play.mvc.Result;

Thomas Feng (
public class SecurityContextAction extends Action<SecurityContext> {
  public Promise<Result> call(Context contextthrows 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) {
    return -> { currentContext =
      SecurityContextHolder.clearContext(); emptyContext =
      boolean hasSecurityContext = !currentContext.equals(emptyContext);
      if (id != null) {
        if (!hasSecurityContext) {
      if (hasSecurityContext) {
        int expirationInSeconds = configuration.expirationInSeconds();
        if (expirationInSeconds < 0) {
          expirationInSeconds = securityPlugin.getExpirationInSeconds();
        String newId = UUID.randomUUID().toString();
        context.response().setCookie(cookieName, newId, expirationInSeconds);, SecurityContextHolder.getContext(), expirationInSeconds);
      return result;
New to GrepCode? Check out our FAQ X