File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 33from fastapi import Depends , Request
44
55from backend .common .enums import MethodType , StatusType
6+ from backend .common .exception import errors
67from backend .common .exception .errors import AuthorizationError , TokenError
8+ from backend .common .log import log
79from backend .common .security .jwt import DependsJwtAuth
810from backend .core .conf import settings
9- from backend .plugin . casbin . utils .rbac import casbin_verify
11+ from backend .utils .import_parse import import_module_cached
1012
1113
1214async def rbac_verify (request : Request , _token : str = DependsJwtAuth ) -> None :
@@ -67,6 +69,13 @@ async def rbac_verify(request: Request, _token: str = DependsJwtAuth) -> None:
6769 if path_auth_perm not in allow_perms :
6870 raise AuthorizationError
6971 else :
72+ try :
73+ casbin_rbac = import_module_cached ('backend.plugin.casbin.utils.rbac' )
74+ casbin_verify = getattr (casbin_rbac , 'casbin_verify' )
75+ except (ImportError , AttributeError ) as e :
76+ log .error (f'正在通过 casbin 执行 RBAC 权限校验,但此插件不存在: { e } ' )
77+ raise errors .ServerError (msg = '权限校验失败,请联系系统管理员' )
78+
7079 await casbin_verify (request )
7180
7281
You can’t perform that action at this time.
0 commit comments