前后端分离模式下的权限设计方案
作者:_liuxx
前后端依然可行。
前端路由权限控制。用户登录时拿到用户拥有的权限标识集合,在前端存储。路由变化时,进行权限判断,通过则渲染对应页面组件,否则渲染403组件。示例代码:
let hasPermission = ();
<div className={}>
{hasPermission ? children : <Exception type={403}/>}
</div>
封装bird-button权限按钮组件,传入按钮所需权限名,内部进行权限判断,通过渲染按钮。
<BirdButton permissionName={'sys'} type='primary'>测试按钮</BirdButton>
服务端。服务端权限验证很好理解。使用拦截器验证当前请求的权限。代码示例:
public class SsoAuthorizeInterceptor extends HandlerInterceptorAdapter {
***@Autowired
private TicketHandler ticketHandler;
***@Autowired
private SsoAuthorizeManager authorizeManager;
***@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!(handler instanceof HandlerMethod)) return false;
HandlerMethod handlerMethod = (HandlerMethod) handler;
SsoAuthorize authorize = ();
if (authorize != null) {
TicketInfo ticketInfo = (request);
if (ticketInfo == null) {
throw new UnAuthorizedException("用户信息已失效.");
}
String[] requirePermissions = ();
if(requirePermissions.
前后端分离模式下的权限设计方案 来自淘豆网m.daumloan.com转载请标明出处.