RBAC0
- 基本的权限角色绑定并为用户分配角色。
- 会话节点,存储一个用户当前会话所激活的权限信息。
RBAC1
- 基于RBAC0权限管理规范
- 基本:定义角色和角色之间可以存在继承关系,并且允许多继承。
- 扩展:角色和角色间的继承关系是一个树形结构。
RBAC2
- 基于RBAC0权限管理规范
- 静态职责隔离
- 角色之间存在互斥关系,一个用户不能被同时分配互斥的角色
- 一个角色可授予的用户数有限(逻辑取反亦有效)
- 授予角色可有先决条件限制
- 动态职责分离
- 动态决定一个会话该激活哪个角色。
RBAC3
- RBAC1 + RBAC2
eCommerce-RBAC
- 地址
- 特点
- 简单实现了RBAC3特性
-
数据结构清晰,见下方ER图
- 采用HTTP API,各个模块API功能比较单一且功能比较全面
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface RbacUsersManager {
/**
* Method used to obtain all currently defined users.
*
* @return
*/
@Path("/")
@GET
public Users loadAllUsers();
/**
* Method used to obtain a slice of users based on a given page size and a start record.
*
* @param pageSize This is the page size we want to use.
* @param startRecord This is the start record we want to use.
* @return
*/
@Path("/{startRecord}/{pageSize}/")
@GET
public Users loadAllUsers(
@PathParam("pageSize") int pageSize,
@PathParam("startRecord") int startRecord);
/**
* Method used to get an user from RBAC system by id.
*
* @param userId
* @return
*/
@Path("/{userId}")
@GET
public User loadUserById(@PathParam("userId") Integer userId);
/**
* Method used to load all user roles.
*
* @param userId User unique identifier.
* @return
*/
@Path("/{userId}/roles")
@GET
public Roles loadUserRoles(@PathParam("userId") Integer userId);
/**
* Method used to load all user permissions. Do not confuse it
* with activated permissions.
*
* @param userId User unique identifier.
* @return
*/
@Path("/{userId}/permissions")
@GET
public Permissions loadUserPermissions(@PathParam("userId") Integer userId);
/**
* Method used to load all operations a user is allowed to execute
* on a specified object.
*
* @param userId User unique identifier.
* @param objectId Object unique identifier.
* @return
*/
@Path("/{userId}/operations/{objectId}")
@GET
public Operations loadUserOperationsForObject(
@PathParam("userId") Integer userId,
@PathParam("objectId") Integer objectId);
/**
* Method used to create a new user.
*
* @param userId User unique identifier.
* @param user User object.
*/
@Path("/{userId}")
@POST
@Consumes("application/json")
public void createUser(@PathParam("userId") Integer userId, User user);
/**
* Method used to update an existing user.
*
* @param userId User unique identifier.
* @param user User instance that contains all new values that should be updated.
*/
@Path("/{userId}")
@PUT
@Consumes("application/json")
public void updateUser(@PathParam("userId") Integer userId, User user);
/**
* Method used to delete an existing user.
*
* @param userId User unique identifier.
*/
@Path("/{userId}")
@DELETE
public void deleteUser(@PathParam("userId") Integer userId);
/**
* Method used to remove user from all roles he is currently assigned to.
*
* @param userId User unique identifier.
*/
@Path("/{userId}/roles")
@DELETE
public void deleteUserFromAllRoles(@PathParam("userId") Integer userId);
/**
* Method used to stop all active sessions of an user.
*
* @param userId User unique identifier.
*/
@Path("/{userId}/sessions")
@DELETE
public void deleteUserSessions(@PathParam("userId") Integer userId);
}
- 不够完善的地方
- 没有完善的鉴权机制以及鉴权方案
- 仅有权限管理方案,没有权限分类方案。
可借鉴的点
- API接口功能单一
- 角色继承(自下而上继承)
- 简化配置,下级拥有的权限上级默认拥有
- session模块
- 隔离user和role之间的直接关系,使得user登录期间可以动态决定他所激活的角色。
- 角色互斥
- 互斥角色,我理解可以作为角色继承在实际应用场景的补充,因为角色继承不是绝对的。
- 举例:物流经理角色 –> 仓库管理员角色 –> 守门人角色,即
物流经理角色
拥有守门人角色
的权限。但实际生产中这是不必要的,所以可以将物流经理角色
和守门人角色
设置为互斥,从而让他无法继承。
- 举例:物流经理角色 –> 仓库管理员角色 –> 守门人角色,即
- 互斥角色,我理解可以作为角色继承在实际应用场景的补充,因为角色继承不是绝对的。