Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码生成器生成了代码, 页面没有显示新增、修改、删除等按钮? 而且一致提示“执行方法xx需要xx权限” #35

Closed
zuihou opened this issue Nov 2, 2020 · 1 comment

Comments

@zuihou
Copy link
Collaborator

zuihou commented Nov 2, 2020

版本信息:

JDK 版本(必填) : 1.8.0
源码版本(必填):2.6.0
MySQL(必填): 5.7.9
Nacos(必填):1.2.1

问题描述:

代码生成器生成了代码, 页面没有显示新增、修改、删除等按钮? 而且一致提示“执行方法xx需要xx权限”

报错截图

image

重现步骤

  1. 代码生成器生成的代码,或者手写的代码都报错
@zuihou
Copy link
Collaborator Author

zuihou commented Nov 3, 2020

报错原因:

  1. 提示的执行方法[page]需要[hasPermit('station123:view')]权限是由于后端UriSecurityPreAuthAspect类检测到page方法需要station123:view权限, 而当前用户没有该权限.
  2. 没有显示新增、修改等按钮是由于前端自定义指令v-has-permission 检测到当前用户没有station123:add 等权限.

解决方案:

  1. 前往 “菜单管理” 页面, 选择对应的菜单, 然后在该菜单下配置资源权限.
    image
    ps: 为了演示我把StationController类的注解改成了@PreAuth(replace = "station123:"), 所以提示没有station123:view 权限. 上图中,我这里配置的都是 station:* 权限, 所以会提示没有权限

  2. 点击上图的新增,编码输入station123:view , 名称输入查询.

  3. 前往“角色管理”, 将新建的权限编码station123:view分配给超管.

  4. 切换回 “岗位管理” 刷新页面, 可能访问后端数据

  5. 但此时页面上还是没有 新增、修改等按钮, 是因为前端将用户等权限缓存到了LocalStorage,所以需要用户退出后,重新登录.

后端URI权限原理

通过 @PreAuth 注解拦截Controller 类方法, 判断当前请求头token中封装的用户,是否拥有权限.
代码参考:

  1. UriSecurityPreAuthAspect //拦截PreAuth注解,并解析注解上标记的资源编码
  2. VerifyAuthFunction //远程调用接口,获取当前用户的权限, 并判断返回是否拥有指定权限
  3. OauthUserController#getById // 被调用方, 执行具体的查询逻辑, 查询指定用户拥有的全部权限等数据

前端按钮权限原理

通过按钮上加自定义指令v-has-permissionv-has-any-permissionv-has-no-permission 控制按钮的权限.
代码参考:

  1. permissionDirect.js

@zuihou zuihou closed this as completed Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant