public PlayWebContext(final Context context, final SessionStore sessionStore) { this.context = context; this.request = context.request(); this.response = context.response(); this.session = context.session(); if (sessionStore == null) { this.sessionStore = new PlayCacheStore(); } else { this.sessionStore = sessionStore; } }
/** * Build the action context from the Play {@link Context} and the {@link RequiresAuthentication} * annotation. * * @param ctx the Play context. * @param configuration the configuration. * @return */ public static ActionContext build(Context ctx, Object configuration) { JavaWebContext context = new JavaWebContext(ctx.request(), ctx.response(), ctx.session()); String clientName = null; String targetUrl = ""; Boolean isAjax = false; Boolean stateless = false; String requireAnyRole = ""; String requireAllRoles = ""; if (configuration != null) { try { final InvocationHandler invocationHandler = Proxy.getInvocationHandler(configuration); clientName = (String) invocationHandler.invoke(configuration, clientNameMethod, null); targetUrl = (String) invocationHandler.invoke(configuration, targetUrlMethod, null); logger.debug("targetUrl : {}", targetUrl); isAjax = (Boolean) invocationHandler.invoke(configuration, isAjaxMethod, null); logger.debug("isAjax : {}", isAjax); stateless = (Boolean) invocationHandler.invoke(configuration, statelessMethod, null); logger.debug("stateless : {}", stateless); requireAnyRole = (String) invocationHandler.invoke(configuration, requireAnyRoleMethod, null); logger.debug("requireAnyRole : {}", requireAnyRole); requireAllRoles = (String) invocationHandler.invoke(configuration, requireAllRolesMethod, null); logger.debug("requireAllRoles : {}", requireAllRoles); } catch (Throwable e) { logger.error("Error during configuration retrieval", e); throw new TechnicalException(e); } } clientName = (clientName != null) ? clientName : context.getRequestParameter(Config.getClients().getClientNameParameter()); logger.debug("clientName : {}", clientName); String sessionId = (stateless) ? null : StorageHelper.getOrCreationSessionId(ctx.session()); return new ActionContext( ctx, ctx.request(), sessionId, context, clientName, targetUrl, isAjax, stateless, requireAnyRole, requireAllRoles); }
/** * Update the SSO language so that it is aligned with the specified language.<br> * The SSO language is the one used for the login & logout page. * * @param ctx a Context (play meaning) * @param languageCode a language code (en, fr, de) */ public static void setSsoLanguage(Context ctx, String languageCode) { // For CAS, the language is stored in a cookie // To "update" this cookie we have to override it with a different value ctx.response().setCookie(CAS_SSO_LANGUAGE_COOKIE, languageCode); }
private Result sendAuthRequest(Context context) { context.response().setHeader(WWW_AUTHENTICATE, REALM); return unauthorized(); }