Search in sources :

Example 1 with TurbineRunData

use of com.alibaba.citrus.turbine.TurbineRunData in project dubbo by alibaba.

the class ServicePrivilegeCheckValve method invokeCheckServicePrivilege.

private void invokeCheckServicePrivilege(User user) {
    TurbineRunData rundata = getTurbineRunData(request);
    HttpSession session = request.getSession();
    @SuppressWarnings("unchecked") Map<String, String[]> requestMapping = request.getParameterMap();
    //记录上次操作到请求中
    String returnURL = "";
    if (session.getAttribute("returnURL") == null) {
        returnURL = request.getContextPath();
    } else {
        returnURL = (String) session.getAttribute("returnURL");
    }
    if (requestMapping.get("service").length > 0) {
        String service = ((String[]) requestMapping.get("service"))[0];
        String method = "index";
        if (requestMapping.get("_method").length > 0) {
            method = requestMapping.get("_method")[0];
        }
        boolean exclude = "index".equals(method) || "show".equals(method);
        if (!exclude) {
            if (user != null && !user.hasServicePrivilege(service)) {
                request.setAttribute("returnURL", returnURL);
                redirectToNoRight(rundata);
            }
        }
    }
    String type = requestMapping.get("_type").length == 0 ? null : requestMapping.get("_type")[0];
    if (!"noServicePrivilege".equals(type)) {
        session.setAttribute("returnURL", request.getRequestURI());
    }
    return;
}
Also used : TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData) HttpSession(javax.servlet.http.HttpSession)

Example 2 with TurbineRunData

use of com.alibaba.citrus.turbine.TurbineRunData in project incubator-dubbo-ops by apache.

the class ServicePrivilegeCheckValve method invokeCheckServicePrivilege.

private void invokeCheckServicePrivilege(User user) {
    TurbineRunData rundata = getTurbineRunData(request);
    HttpSession session = request.getSession();
    @SuppressWarnings("unchecked") Map<String, String[]> requestMapping = request.getParameterMap();
    // record the last operation to request
    String returnURL = "";
    if (session.getAttribute("returnURL") == null) {
        returnURL = request.getContextPath();
    } else {
        returnURL = (String) session.getAttribute("returnURL");
    }
    if (requestMapping.get("service").length > 0) {
        String service = ((String[]) requestMapping.get("service"))[0];
        String method = "index";
        if (requestMapping.get("_method").length > 0) {
            method = requestMapping.get("_method")[0];
        }
        boolean exclude = "index".equals(method) || "show".equals(method);
        if (!exclude) {
            if (user != null && !user.hasServicePrivilege(service)) {
                request.setAttribute("returnURL", returnURL);
                redirectToNoRight(rundata);
            }
        }
    }
    String type = requestMapping.get("_type").length == 0 ? null : requestMapping.get("_type")[0];
    if (!"noServicePrivilege".equals(type)) {
        session.setAttribute("returnURL", request.getRequestURI());
    }
    return;
}
Also used : TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData) HttpSession(javax.servlet.http.HttpSession)

Example 3 with TurbineRunData

use of com.alibaba.citrus.turbine.TurbineRunData in project otter by alibaba.

the class AuthContextValve method invoke.

public void invoke(PipelineContext pipelineContext) throws Exception {
    TurbineRunData rundata = getTurbineRunData(request);
    // TODO 走 api 的验证
    if (isAPI(rundata)) {
        if (apiAuthService.auth(rundata)) {
            pipelineContext.invokeNext();
        } else {
            // TODO 需要转跳到 json 格式的 link
            redirect(pipelineContext, rundata, forbiddenLink);
        }
        return;
    }
    // 得到请求URL相对路径(不包含域名/端口信息)
    String requestUrl = rundata.getRequest().getRequestURI();
    List<AuthorizeType> result = urlAnalyze.check(requestUrl);
    String action = StringUtil.toCamelCase(trimToNull(rundata.getParameters().getString(actionParam)));
    String eventName = getEventName();
    // 首先判断是否登录
    User user = (User) rundata.getRequest().getSession().getAttribute(WebConstant.USER_SESSION_KEY);
    if (StringUtils.isNotEmpty(action)) {
        result.addAll(urlAnalyze.check(action, eventName));
    }
    if (result.isEmpty()) {
        // 访问的连接不符合权限匹配规则,跳转到登录页面
        redirect(pipelineContext, rundata, forbiddenLink);
    } else {
        if (null == user) {
            // 2.如果集合中只包含匿名权限,则通过。
            if (result.contains(AuthorizeType.OPERATOR) || result.contains(AuthorizeType.ADMIN)) {
                redirect(pipelineContext, rundata, loginLink);
            } else {
                pipelineContext.invokeNext();
            }
        } else {
            // 2.如果权限集合有高于用户权限,则跳转到登录页面。
            if (compareAuth(user.getAuthorizeType(), result)) {
                pipelineContext.invokeNext();
            } else {
                redirect(pipelineContext, rundata, forbiddenLink);
            }
        }
    }
}
Also used : AuthorizeType(com.alibaba.otter.shared.common.model.user.AuthorizeType) User(com.alibaba.otter.shared.common.model.user.User) TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)

Example 4 with TurbineRunData

use of com.alibaba.citrus.turbine.TurbineRunData in project dubbo by alibaba.

the class LocaleValve method invoke.

public void invoke(PipelineContext pipelineContext) throws Exception {
    TurbineRunData rundata = getTurbineRunData(request);
    if (ignoreTarget(rundata.getTarget())) {
        pipelineContext.invokeNext();
        return;
    }
    //默认是中文
    String[] temp = rundata.getCookies().getStrings("locale");
    String locale = null;
    if (temp != null) {
        if (temp.length > 1) {
            locale = temp[temp.length - 1];
        } else if (temp.length == 1) {
            locale = temp[0];
        }
    }
    if (locale == null || "".equals(locale)) {
        locale = "zh";
    }
    Locale newLocale = Locale.SIMPLIFIED_CHINESE;
    if ("en".equals(locale)) {
        newLocale = Locale.ENGLISH;
    } else if ("zh".equals(locale)) {
        newLocale = Locale.SIMPLIFIED_CHINESE;
    } else if ("zh_TW".equals(locale)) {
        newLocale = Locale.TRADITIONAL_CHINESE;
    }
    LocaleUtil.setLocale(newLocale);
    pipelineContext.invokeNext();
}
Also used : Locale(java.util.Locale) TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)

Example 5 with TurbineRunData

use of com.alibaba.citrus.turbine.TurbineRunData in project incubator-dubbo-ops by apache.

the class LocaleValve method invoke.

public void invoke(PipelineContext pipelineContext) throws Exception {
    TurbineRunData rundata = getTurbineRunData(request);
    if (ignoreTarget(rundata.getTarget())) {
        pipelineContext.invokeNext();
        return;
    }
    // default chinese
    String[] temp = rundata.getCookies().getStrings("locale");
    String locale = null;
    if (temp != null) {
        if (temp.length > 1) {
            locale = temp[temp.length - 1];
        } else if (temp.length == 1) {
            locale = temp[0];
        }
    }
    if (locale == null || "".equals(locale)) {
        locale = "en";
    }
    Locale newLocale = Locale.SIMPLIFIED_CHINESE;
    if ("en".equals(locale)) {
        newLocale = Locale.ENGLISH;
    } else if ("zh".equals(locale)) {
        newLocale = Locale.SIMPLIFIED_CHINESE;
    } else if ("zh_TW".equals(locale)) {
        newLocale = Locale.TRADITIONAL_CHINESE;
    }
    LocaleUtil.setLocale(newLocale);
    pipelineContext.invokeNext();
}
Also used : Locale(java.util.Locale) TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)

Aggregations

TurbineRunData (com.alibaba.citrus.turbine.TurbineRunData)5 TurbineUtil.getTurbineRunData (com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)5 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 AuthorizeType (com.alibaba.otter.shared.common.model.user.AuthorizeType)1 User (com.alibaba.otter.shared.common.model.user.User)1