javaweb 项目的系统权限管理,怎么设计?shiro简单了解

来源:互联网 发布:网友知乎 编辑:程序博客网 时间:2024/06/05 10:49

java web 项目的系统权限管理设计方法有两种:

方法一、SpringMVC整合Shiro (Shiro是强大的权限管理框架)
方法二、基于角色的访问权限控制
基于角色的访问权限控制
首先基于角色的访问权限控制,所有的用户访问都会经过过滤,然后分析访问权限加以认证!权限中的重点,表的设计。
普遍三张表,表名自定义。用户表(User),角色表(Role),资源表(Resource)
基于角色进行权限进行设计是一种可行的方式,用户和资源不进行强耦合在一起,非常方便的处理,不过直接的这样处理比较的麻烦,非常的麻烦,很多的时候都想使用框架来简化我们的操作,所以笔者就想了解一下子shiro,学习一下子。上面的两种方法来至于百度知道!https://zhidao.baidu.com/question/513750344.html

Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE 环境,也可以用在 JavaEE 环境。Shiro可以帮助我们完成:认证、授权、加密、会话管理、与Web 集成、缓 存等。这不就是我们想要的嘛,而且Shiro 的API 也是非常简单;

这里写图片描述

Authentication:身份认证/登录,验证用户是不是拥有相应的身份;
Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限;即判断用户是否能做事情,常见的如:验证某个用户是否拥有某个角色。或者细粒度的验证某个用户对某个资源是否具有某个权限;访问控制的过程,即确定’谁’访问’什么’。
Session Manager:管理用户特定的会话,即使在非Web或EJB应用程序
Cryptography:加密,保护数据的安全性,如密码加密存储到数据库,而不是明文存储;
Web Support:Web 支持,可以非常容易的集成到Web 环境;
Caching: Caching is a first-tier citizen in Apache Shiro’s API to ensure that security operations remain fast and efficient.缓存,保证高效性
Concurrency: Apache Shiro supports multi-threaded applications with its concurrency features.
Testing:提供测试支持;
Run As: A feature that allows users to assume the identity of another user (if they are allowed), sometimes useful in administrative scenarios.
Remember Me: Remember users’ identities across sessions so they only need to log in when mandatory.

Shiro 不会去维护用户、维护权限;这些需要我们自己去设计/提供;然后通过相应的接口注入给Shiro即可。

http://shiro.apache.org/architecture.html
shiro的主要的结构 High-Level Overview:
At the highest conceptual level, Shiro’s architecture has 3 primary concepts:Subject,SecurityManager和Realms
这里写图片描述

Subject::Whereas the word ‘User’ often implies a human being, a can be a person, but it could also represent a 3rd-party service*(第三方服务), daemon account(守护进程账号), cron job, or anything similar - basically anything that is currently interacting with the software.,反正就好像呈现的视图。所有Subject 都绑定到SecurityManager,与Subject的所有交互都会委托给SecurityManager;可以把Subject认为是一个门面;SecurityManager才是实际的执行者;

SecurityManager::安全管理器;即所有与安全有关的操作都会与SecurityManager 交互;
且它管理着所有Subject;可以看出它是Shiro 的核心,它负责与后边介绍的其他组件进行
交互,如果学习过SpringMVC,你可以把它看成DispatcherServlet前端控制器。

Realm:域,Shiro从从Realm获取安全数据(如用户、角色、权限),就是说SecurityManager要验证用户身份,那么它需要从Realm获取相应的用户进行比较以确定用户身份是否合法。也需要从Realm得到用户相应的角色权限进行验证用户是否能进行操作;可以把Realm看成DataSource,即安全数据源。When configuring Shiro, you must specify at least one Realm to use for authentication(认证) and/or authorization(授权).The SecurityManager may be configured with multiple Realms, but at least one is required.
Shiro provides out-of-the-box Realms to connect to a number of security data sources (aka directories) such as LDAP, relational databases (JDBC), text configuration sources like INI and properties files, and more. You can plug-in your own Realm implementations to represent custom data sources if the default Realms do not meet your needs.(配置数据源可以是各种的类型的,JDBC或者文本数据源)

Detailed Architecture:
这里写图片描述

Subject instances are all bound to (and require) a SecurityManager.(必须要绑定到一个SecurityManager) When you interact with a Subject, those interactions translate to subject-specific interactions with the SecurityManager.(当我们产生交互的时候)
SecurityManager;它管理着所有Subject、且负责进行认证和授权、及会话、缓存的管理。
Authenticator:认证器,负责主体认证的,这是一个扩展点,如果用户觉得Shiro 默认的不好,可以自定义实现;其需要认证策略(Authentication Strategy),即什么情况下算用户认证通过了;
Authrizer:授权器,或者访问控制器,用来决定主体是否有权限进行相应的操作;即控制着用户能访问应用中的哪些功能;
SessionManager Shiro 就抽象了一个自己的Session来管理主体与应用之间交互的数据;这样的话,比如我们在Web 环境用,刚开始是一台Web 服务器;接着又上了台EJB 服务器;这时想把两台服务器的会话数据放到一个地方,这个时候就可以实现自己的分布式会话(如把数据放到Memcached服务器,Redis);
SessionDAO:DAO 大家都用过,数据访问对象,用于会话的CRUD,比如我们想把Session保存到数据库,那么可以实现自己的SessionDAO,通过如JDBC 写到数据库;比如想把Session 放到Memcached 中,可以实现自己的Memcached SessionDAO;另外SessionDAO中可以使用Cache进行缓存,以提高性能;
CacheManager:缓存控制器,来管理如用户、角色、权限等的缓存的;因为这些数据基本上很少去改变,放到缓存中后可以提高访问的性能。

根据上面的叙述,简单的了解了哈,可以自己去官网好好的看哈,可以利用谷歌的翻译,或者其他人写的博客啊,一共就三个基本的概念 Subject SecurityManager Realm 可以简单的归纳为一个用户 查看管理他的信息 数据存放的位置

1 0