你的位置:首页 > 软件开发 > Java > Java 权限框架 Shiro 实战(一)

Java 权限框架 Shiro 实战(一)

发布时间:2015-07-02 23:00:42
Apache Shiro 官网地址:http://shiro.apache.org/Apache Shiro is a powerful and easy-to-use Java security framework that performs authentication, a ...

Apache Shiro 官网地址:http://shiro.apache.org/

Apache Shiro is a powerful and easy-to-use Java security framework that performs authentication, authorization, cryptography, and session management. With Shiro’s easy-to-understand API, you can quickly and easily secure any application – from the smallest mobile applications to the largest web and enterprise applications.

shiro是一个强大而且简单易用的Java安全框架,主要功能有认证(就是登陆验证),授权(就是权限管理),加密(就是密码加密),session管理。适用于各种大型或者小型企业应用。和Spring Security比较而言,确实更加简单而且灵活易懂。

1. shiro中的重要概念

要理解shiro,先要理解框架的几个概念:

1) Subject: 代表当前登陆或者访问的用户;

2)Principals:一般指用户名等,唯一表明Subject身份也就是当前用户身份的东西;

3)Credentials:凭证,一般指密码,对当前登陆用户进行验证;

4)Realms:域,一般是指存储用户信息(用户名,密码,权限,角色)的数据库,也就是保存用户权限等信息的数据源

5)SecurityManager:shiro安全管理的顶级对象。它集合或者说调用所有其它相关组件,负责所有安全和权限相关处理过程,就像一个中央集权政府;

2. shiro的子系统

上面我们说到shiro的主要功能有:认证,授权,加密,session管理等。而每一个主要功能对应于shiro的一个子系统:

Java 权限框架 Shiro 实战(一)

下面正对每一个子系统分别介绍。

3. Authentication认证子系统

认证子系统,就是处理用户登录,验证用户登录。我们前面讲到Subject代表当前用户,而Principal和credential分别就代表用户名和密码。登录认证时,其实就是调用的 Subject.login(AuthenticationToken token)方法,AuthenticationToken是一个接口

public interface AuthenticationToken extends Serializable {  /**   * Returns the account identity submitted during the authentication process.*/  Object getPrincipal();  /**   * Returns the credentials submitted by the user during the authentication process that verifies   * the submitted {@link #getPrincipal() account identity}.*/  Object getCredentials();}

原标题:Java 权限框架 Shiro 实战(一)

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。