@Override public void handle(Context context) { if (!SecurityUtils.getSubject().isAuthenticated()) { // unauthenticated session, save request & redirect to login url String requestUri = context.getRequest().getApplicationUriWithQuery(); context.setSession(DESTINATION_ATTRIBUTE, requestUri); context.redirect(loginUrl); log.info("Unauthenticated request for {}, redirecting to {}", context.getRequestUri(), loginUrl); } else { // session already authenticated context.next(); } } }
@Override public void handle(Context context) { if (context.getSession(AuthConstants.ACCOUNT_ATTRIBUTE) == null) { // unauthenticated session, save request & redirect to login url String requestUri = context.getRequest().getApplicationUriWithQuery(); context.setSession(AuthConstants.DESTINATION_ATTRIBUTE, requestUri); context.redirect(loginPath); log.info("Unauthenticated request for {}, redirecting to {}", context.getRequestUri(), loginPath); } else { // session already authenticated context.next(); } } }
@Override public void handle(Context context) { if (context.getSession(AuthConstants.ACCOUNT_ATTRIBUTE) == null) { // unauthenticated session, save request & redirect to login url String requestUri = context.getRequest().getApplicationUriWithQuery(); context.setSession(AuthConstants.DESTINATION_ATTRIBUTE, requestUri); context.redirect(loginPath); log.info("Unauthenticated request for {}, redirecting to {}", context.getRequestUri(), loginPath); } else { // session already authenticated context.next(); } } }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }
private void initializeApplication() { // hook-up the Metrics dispatch listener MetricsDispatchListener metricsDispatchListener = new MetricsDispatchListener(metricRegistry); application.getRoutePreDispatchListeners().add(metricsDispatchListener); application.getRoutePostDispatchListeners().add(metricsDispatchListener); // set the RedirectException handler application.getErrorHandler().setExceptionHandler(RedirectException.class, (exception, ctx) -> { RedirectException redirectException = (RedirectException) exception; if (!Strings.isNullOrEmpty(redirectException.getSessionUrlAttribute())) { String requestUri = ctx.getRequest().getApplicationUriWithQuery(); ctx.setSession(redirectException.getSessionUrlAttribute(), requestUri); } ctx.redirect(redirectException.getPath()); }); // set the StatusCodeException handler application.getErrorHandler().setExceptionHandler(StatusCodeException.class, (exception, ctx) -> { StatusCodeException statusCodeException = (StatusCodeException) exception; ctx.setLocal("message", statusCodeException.getMessage()); application.getErrorHandler().handle(statusCodeException.getStatusCode(), ctx); }); }