新增认证对象简化权限验证

pull/112/head
RuoYi 3 years ago
parent 9c5c6c6be7
commit d0a5c25b5d

@ -14,6 +14,7 @@ import com.ruoyi.system.api.model.LoginUser;
/** /**
* Header线便 * Header线便
*
* *
* @author ruoyi * @author ruoyi
*/ */

@ -59,7 +59,7 @@ public class AuthFilter implements GlobalFilter, Ordered
Claims claims = JwtUtils.parseToken(token); Claims claims = JwtUtils.parseToken(token);
if (claims == null) if (claims == null)
{ {
return unauthorizedResponse(exchange, "token已过期或验证不正确!"); return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
} }
String userkey = JwtUtils.getUserKey(claims); String userkey = JwtUtils.getUserKey(claims);
boolean islogin = redisService.hasKey(getTokenKey(userkey)); boolean islogin = redisService.hasKey(getTokenKey(userkey));

@ -0,0 +1,60 @@
import store from '@/store'
function authPermission(permission) {
const all_permission = "*:*:*";
const permissions = store.getters && store.getters.permissions
if (permission && permission.length > 0) {
return permissions.some(v => {
return all_permission === v || v === permission
})
} else {
return false
}
}
function authRole(role) {
const super_admin = "admin";
const roles = store.getters && store.getters.roles
if (role && role.length > 0) {
return roles.some(v => {
return super_admin === v || v === role
})
} else {
return false
}
}
export default {
// 验证用户是否具备某权限
hasPermi(permission) {
return authPermission(permission);
},
// 验证用户是否含有指定权限,只需包含其中一个
hasPermiOr(permissions) {
return permissions.some(item => {
return authPermission(item)
})
},
// 验证用户是否含有指定权限,必须全部拥有
hasPermiAnd(permissions) {
return permissions.every(item => {
return authPermission(item)
})
},
// 验证用户是否具备某角色
hasRole(role) {
return authRole(role);
},
// 验证用户是否含有指定角色,只需包含其中一个
hasRoleOr(roles) {
return roles.some(item => {
return authRole(item)
})
},
// 验证用户是否含有指定角色,必须全部拥有
hasRoleAnd(roles) {
return roles.every(item => {
return authRole(item)
})
}
}

@ -1,9 +1,12 @@
import auth from './auth'
import cache from './cache' import cache from './cache'
import modal from './modal' import modal from './modal'
import download from './download' import download from './download'
export default { export default {
install(Vue) { install(Vue) {
// 认证对象
Vue.prototype.$auth = auth
// 缓存对象 // 缓存对象
Vue.prototype.$cache = cache Vue.prototype.$cache = cache
// 模态框对象 // 模态框对象

Loading…
Cancel
Save