这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
1.bi与可视化saca.dataviz:10集成:10.2项目权限过滤器参考实现 [2021/04/08 12:02] admin 创建 |
1.bi与可视化saca.dataviz:10集成:10.2项目权限过滤器参考实现 [2021/04/08 12:07] (当前版本) admin |
||
---|---|---|---|
行 1: | 行 1: | ||
< | < | ||
+ | # | ||
+ | 可以使用spring-security过滤器的方法实现对某个用户创建项目的权限控制。 | ||
+ | |||
+ | 创建实现类ProjectPermissonFilter如下: | ||
+ | ``` | ||
+ | package com.neusoft.saca.dataviz.common.security; | ||
+ | |||
+ | /** | ||
+ | * TODO 请添加该类的描述 | ||
+ | | ||
+ | */ | ||
+ | import java.io.IOException; | ||
+ | import javax.servlet.Filter; | ||
+ | import javax.servlet.FilterChain; | ||
+ | import javax.servlet.FilterConfig; | ||
+ | import javax.servlet.ServletException; | ||
+ | import javax.servlet.ServletRequest; | ||
+ | import javax.servlet.ServletResponse; | ||
+ | import javax.servlet.http.HttpServletResponse; | ||
+ | |||
+ | /** | ||
+ | * 项目权限过滤器。 | ||
+ | * <p> | ||
+ | * 根据用户id判断创建项目权限 | ||
+ | * </p> | ||
+ | | ||
+ | * @author l | ||
+ | * @since 2021-04-08 | ||
+ | */ | ||
+ | public class ProjectPermissonFilter implements Filter { | ||
+ | |||
+ | @Override | ||
+ | public void init(FilterConfig filterConfig) throws ServletException { | ||
+ | // Nothing. | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
+ | throws IOException, | ||
+ | boolean hasPermisson = true; | ||
+ | |||
+ | // | ||
+ | String currentUserId = SecurityUtil.getCurrentUserId(); | ||
+ | /** | ||
+ | * TODO 根据用户判断权限的实现逻辑, | ||
+ | | ||
+ | */ | ||
+ | |||
+ | // end | ||
+ | if (!hasPermisson) { | ||
+ | if (response instanceof HttpServletResponse) { | ||
+ | ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN, | ||
+ | } else { | ||
+ | response.getWriter().println(" | ||
+ | } | ||
+ | return; | ||
+ | |||
+ | } | ||
+ | |||
+ | chain.doFilter(request, | ||
+ | |||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void destroy() { | ||
+ | // Nothing. | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | ``` | ||
+ | |||
+ | dataviz-service/ | ||
+ | ``` | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | ``` | ||
+ | 可以在半小时内搭建一个dataviz开发环境,参考[二次开发环境搭建说明](http:// | ||
+ | |||
+ | |||
+ | </ | ||