All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sirius.biz.web.BizInterceptor Maven / Gradle / Ivy

There is a newer version: 9.6
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.biz.web;

import sirius.kernel.di.std.Register;
import sirius.kernel.nls.NLS;
import sirius.web.controller.Controller;
import sirius.web.controller.Interceptor;
import sirius.web.http.WebContext;
import sirius.web.security.ScopeInfo;
import sirius.web.security.UserContext;

import java.lang.reflect.Method;

/**
 * Redirects unauthorized calls to the wondergem login page (for the default scope).
 */
@Register
public class BizInterceptor implements Interceptor {

    @Override
    public boolean before(WebContext ctx, boolean jsonCall, Controller controller, Method method) throws Exception {
        return false;
    }

    @Override
    public boolean beforePermissionError(String permission,
                                         WebContext ctx,
                                         boolean jsonCall,
                                         Controller controller,
                                         Method method) throws Exception {
        if (!ScopeInfo.DEFAULT_SCOPE.equals(UserContext.getCurrentScope())) {
            return false;
        }
        if (jsonCall) {
            return false;
        }
        if (!UserContext.getCurrentUser().isLoggedIn()) {
            ctx.respondWith().template("templates/biz/login.html.pasta", ctx.getRequest().uri());
        } else {
            ctx.respondWith()
               .template("templates/wondergem/error.html.pasta",
                         NLS.fmtr("BizInterceptor.missingPermission").set("permission", permission).format());
        }
        return true;
    }

    @Override
    public boolean shouldExecuteRoute(WebContext ctx, boolean jsonCall, Controller controller) {
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy