日常提交
This commit is contained in:
31
spring/Apache Shiro/Apache Shiro Authentication.md
Normal file
31
spring/Apache Shiro/Apache Shiro Authentication.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Apache Shiro Authentication
|
||||
## Apache Shiro Authentication简介
|
||||
Authentication是一个对用户进行身份认证的过程,在认证过程中用户需要向应用提供用于证明用户的凭据。
|
||||
## Apache Authentication概念
|
||||
### subject
|
||||
在应用的角度,subject即是一个用户
|
||||
### principals
|
||||
主体,用于标识一个用户,可以是username、social security nubmer等
|
||||
### credentials
|
||||
凭据,在用户认证过程中用于认证用户的身份,可以是密码、生物识别数据(如指纹、面容等)
|
||||
### realms
|
||||
专用于security的dao对象,用于和后端的datasource进行沟通。
|
||||
## Shiro Authentication过程
|
||||
### Shiro框架的Authentication过程
|
||||
1. 收集用户的principals和credentials
|
||||
2. 向应用的认证系统提交用户的principals和credentials
|
||||
3. 认证结束之后,根据认证结果允许访问、重试访问请求或者阻塞访问
|
||||
### 收集用户的principals和credentials
|
||||
可以通过UsernamePasswordToken来存储用户提交的username和password,并可以调用UsernamePasswordToken.rememberMe方法来启用Shiro的“remember-me”功能。
|
||||
```java
|
||||
//Example using most common scenario:
|
||||
//String username and password. Acquire in
|
||||
//system-specific manner (HTTP request, GUI, etc)
|
||||
UsernamePasswordToken token = new UsernamePasswordToken( username, password );
|
||||
|
||||
//”Remember Me” built-in, just do this:
|
||||
token.setRememberMe(true);
|
||||
```
|
||||
### 将收集的principals和credentials提交给认证系统
|
||||
在收集完用户的principals和credentials之后,需要将其提交给应用的认证系统。
|
||||
在Shiro中,代表认证系统的是Realm,其从存放安全数据的datasource中获取数据,并且
|
||||
Reference in New Issue
Block a user