未验证 提交 233800e0 编写于 作者: sinat_25235033's avatar sinat_25235033 提交者: GitHub

Feature update english docs (#67)

* update docs

* update docs

* update docs

* update docs
上级 372e8370
......@@ -41,8 +41,8 @@
| **servlet** | support | support | support |
| **jax-rs** | support | not support | not support |
| **dynamic modification of permissions** | support | support need modify | support need modify |
| **Performance** | extremely fast | faster | slower|
| **Learning curve** | simple | simple | steep|
| **performance** | extremely fast | faster | slower|
| **learning curve** | simple | simple | steep|
##### Benchmark
......@@ -76,7 +76,7 @@ Detail see [Benchmark Test](https://github.com/tomsun28/sureness-shiro-spring-se
Resource path matching see: [URI Match](docs/path-match.md)
#### Add sureness In Your Project
#### Add Sureness In Your Project
When use maven or gradle build project, add coordinate
```
......@@ -90,9 +90,9 @@ When use maven or gradle build project, add coordinate
compile group: 'com.usthe.sureness', name: 'sureness-core', version: '0.4.4'
```
#### Use the default configuration to configure sureness
#### Use the Default Configuration to Configure Sureness
The default configuration -`DefaultSurenessConfig` uses the document datasource sureness.yml as the auth datasource.
The default configuration -`DefaultSurenessConfig` uses the document datasource `sureness.yml` as the auth datasource.
It supports jwt, basic auth, digest auth authentication.
```
@Bean
......@@ -103,25 +103,22 @@ public DefaultSurenessConfig surenessConfig() {
#### Load Auth Config DataSource
Sureness need dataSource to authenticate and authorize, eg: role data, user data etc.
The dataSource can load from txt, dataBase, no dataBase or annotation etc.
Sureness authentication requires us to provide our own account data, role permission data, etc. These data may come from text, relational databases, non-relational databases, annotations, etc.
We provide interfaces `SurenessAccountProvider`, `PathTreeProvider` for user implement to load data from the dataSource where they want.
`SurenessAccountProvider` - Account datasource provider interface.
`PathTreeProvider` - Resource uri-role datasource provider interface.
We provide default dataSource implement which load dataSource from txt(sureness.yml), user can defined their data in sureness.yml.
We also provider dataSource implement which load dataSource form annotation - `AnnotationLoader`.
- `SurenessAccountProvider` - Account datasource provider interface.
- `PathTreeProvider` - Resource uri-role datasource provider interface.
Default Document DataSource Config - sureness.yml, see: [Default Document DataSource](docs/default-datasource.md)
Annotation DataSource Config Detail, see: [Annotation DataSource](docs/annotation-datasource.md)
Default Document DataSource Config - `sureness.yml`, see: [Default Document DataSource](docs/default-datasource.md)
Annotation DataSource Config Detail - `AnnotationLoader`, see: [Annotation DataSource](docs/annotation-datasource.md)
If the configuration resource data comes from text, please refer to [sureness integration springboot sample(configuration file scheme)--sample-bootstrap](https://github.com/tomsun28/sureness/tree/master/sample-bootstrap)
If the configuration resource data comes from dataBase, please refer to [sureness integration springboot sample(database scheme)-sample-tom](https://github.com/tomsun28/sureness/tree/master/sample-tom)
If the configuration resource data comes from text, please refer to [Sureness integration springboot sample(configuration file scheme)](https://github.com/tomsun28/sureness/tree/master/sample-bootstrap)
If the configuration resource data comes from dataBase, please refer to [Sureness integration springboot sample(database scheme)](https://github.com/tomsun28/sureness/tree/master/sample-tom)
#### Add an Interceptor Intercepting All Requests
The essence of `sureness` is to intercept all rest requests for authenticating and Authorizing.
The essence of sureness is to intercept all rest requests for authenticating and Authorizing.
The interceptor can be a filter or a spring interceptor, it intercepts all request to check them.
```
SubjectSum subject = SurenessSecurityManager.getInstance().checkIn(servletRequest)
......@@ -129,13 +126,14 @@ SubjectSum subject = SurenessSecurityManager.getInstance().checkIn(servletReques
#### Implement Auth Exception Handling Process
`sureness` uses exception handling process:
1. If auth success, method - `checkIn` will return a `SubjectSum` object containing user information.
2. If auth failure, method - `checkIn` will throw different types of auth exceptions.
Users need to continue the subsequent process based on these exceptions.(like return the request response)
Sureness uses exception handling process:
Here we need to customize the exceptions thrown by `checkIn`,
passed directly when auth success, catch exception when auth failure and do something:
- If auth success, method - `checkIn` will return a `SubjectSum` object containing user information.
- If auth failure, method - `checkIn` will throw different types of auth exceptions.
Users need to continue the subsequent process based on these exceptions.(eg: return the request response)
Here we need to customize the exceptions thrown by `checkIn`, passed directly when auth success, catch exception when auth failure and do something:
```
try {
......@@ -157,41 +155,55 @@ Detail sureness auth exception see: [Default Sureness Auth Exception](docs/defau
**Have Fun**
## Advanced Use
If know sureness Process flow, maybe know these extend points.
## Advanced Use
Sureness supports custom subject, custom subjectCreator, custom processor and more.
Suggest look these interface before extending:
Before advanced custom extension, let's first understand the general process of sureness:
- `Subject`: Authenticated authorized user's account interface, provide the account's username,password, request resources, roles, etc.
- `SubjectCreate`: create subject interface, provider create method.
- `Processor`: process subject interface, where happen authentication and authorization.
- `PathTreeProvider`: resource data provider, it can load data from txt or database,etc.
- `SurenessAccountProvider`: account data provider, it can load data from txt or database,etc.
![flow](/docs/_images/flow-en.png)
Sureness Process Flow:
As in the above process, Subject is created by SubjectCreate according to the request body, and different authentication processors process the supported Subjects.
![flow](/docs/_images/flow-en.png)
Sureness provides the following common interfaces as extension points:
1. **Custom Datasource**
- `Subject`: Authenticated authorized user's account interface, provide the account's username,password, request resources, roles, etc.
- `SubjectCreate`: Create subject interface, provider create method.
- `Processor`: Process subject interface, where happen authentication and authorization.
- `PathTreeProvider`: Resource data provider, it can load data from txt or database,etc.
- `SurenessAccountProvider`: Account data provider, it can load data from txt or database,etc.
`Implment PathTreeProvider, load in DefaultPathRoleMatcher`
`Implment SurenessAccountProvide, load in processor`
Refer to [Extension Point](docs/extend-point.md) for the extended documentation.
2. **Custom Subject**
1. **Custom Subject**
`Implment Subject, add custom subject content`
`Implment SubjectCreate to create custom subject`
`Implment Processor to support custom subject`
`Implment Processor to support custom subject`
See [Custom Subject](docs/custom-subject.md)
3. **Custom Processor**
2. **Custom SubjectCreator**
`Implment SubjectCreate to create your custom subject`
See [Custom SubjectCreator](docs/custom-subject-creator.md)
3. **Custom Processor**
`A subject also can support by different processor, so we can custom processor to support custom subject`
`Implment Processor, set which subject can support and implment processing details`
`Implment Processor, set which subject can support and implment processing details`
See [Custom Processor](docs/custom-processor.md)
4. **Custom Datasource**
`Implment PathTreeProvider, load in DefaultPathRoleMatcher`
`Implment SurenessAccountProvide, load in processor`
See [Custom Datasource](docs/custom-datasource.md)
Detail please refer to [sureness integration springboot sample(database scheme)-sample-tom](sample-tom)
Detail please refer to [Sureness integration springboot sample(database scheme)](sample-tom)
## Contributing
......
......@@ -108,15 +108,17 @@ public DefaultSurenessConfig surenessConfig() {
#### 配置权限账户数据源
`sureness`认证鉴权,当然也需要我们提供自己的账户数据,角色权限数据等,这些数据可能来自文本,关系数据库,非关系数据库,注解等。
我们提供了数据源接口:`SurenessAccountProvider` - 账户数据接口, `PathTreeProvider` - 资源权限数据接口,用户可以实现此接口实现自定义数据源。
我们提供了数据源接口:`SurenessAccountProvider`, `PathTreeProvider`,用户可以实现此接口实现自定义数据源。
当前我们也提供文本形式的数据源实现 `DocumentResourceDefaultProvider` 和 注解形式的资源权限数据源实现 `AnnotationLoader`
如果是使用了[默认sureness配置-DefaultSurenessConfig](#使用默认配置来配置sureness),其配置的是文本数据源,用户可以直接通过修改`sureness.yml`文件来配置数据。
- `PathTreeProvider`: 资源的数据源接口,实现从数据库,文本等加载数据,加载到对应的资源权限匹配器`DefaultPathRoleMatcher`
- `SurenessAccountProvider`: 用户的账户密钥信息接口,实现从数据库,文本等加载数据,加载到需要账户数据的`processor`
文本数据源`sureness.yml`配置使用方式详见文档 [默认文本数据源](docs/cn/default-datasource.md)
注解形式的资源权限数据源配置使用方式详见文档 [注解资源权限数据源](docs/cn/annotation-datasource.md)
当使用的是上方默认配置`DefaultSurenessConfig`时,则默认使用文本数据源和注解数据源作为数据提供者。
我们提供了使用代码`DEMO`
- 文本数据源使用`sureness.yml`配置数据,使用方式详见文档 [默认文本数据源](docs/cn/default-datasource.md)
- 注解数据源的注解`@RequiresRoles,@WithoutAuth`使用方式详见文档 [注解资源权限数据源](docs/cn/annotation-datasource.md)
我们提供了代码工程样例:
默认文本数据源具体实现,请参考[sureness集成springboot样例(配置文件方案)--sample-bootstrap](https://github.com/tomsun28/sureness/tree/master/sample-bootstrap)
若权限配置数据来自数据库,请参考[sureness集成springboot样例(数据库方案)--sample-tom](https://github.com/tomsun28/sureness/tree/master/sample-tom)
......
......@@ -38,8 +38,8 @@
| **servlet** | support | support | support |
| **jax-rs** | support | not support | not support |
| **dynamic modification of permissions** | support | support need modify | support need modify |
| **Performance** | extremely fast | faster | slower|
| **Learning curve** | simple | simple | steep|
| **performance** | extremely fast | faster | slower|
| **learning curve** | simple | simple | steep|
##### Benchmark
......
......@@ -9,14 +9,14 @@
- Advanced Extend
- [Extend Point](extend-point.md)
- [Custom Subject Creator](custom-subject-creator.md)
- [Custom Subject](custom-subject.md)
- [Custom Datasource](custom-datasource.md)
- [Custom Subject Creator](custom-subject-creator.md)
- [Custom Processor](custom-processor.md)
- [Custom Datasource](custom-datasource.md)
- Integration Demo
- [Quarkus-Sureness Sample(file scheme)](sample-bootstrap.md)
- [Quarkus-Sureness Sample(database scheme)](sample-tom.md)
- [SpringBoot-Sureness Sample(file scheme)](sample-bootstrap.md)
- [SpringBoot-Sureness Sample(database scheme)](sample-tom.md)
- [Quarkus-Sureness Sample](sample-quarkus.md)
- [Spring-Webflux-Sureness Sample](sample-spring-webflux.md)
- [Javalin-Sureness Sample](sample-javalin.md)
......
## Custom Datasource
Suggest take a look at the interface sureness provided, detail [Advanced Use](extend-point.md)
Before customization, it is recommended to understand the sureness's processor and the extended interface provided, see [Advanced Extension](extend-point.md) for details.
`Implment PathTreeProvider, load in DefaultPathRoleMatcher`
`Implment SurenessAccountProvide, load in processor`
First, let's get to know the two user information and resource permission information interfaces provided by Sureness. Users can customize these interfaces to provide data to Sureness from different data sources.
Detail please refer to [30 Minute Tutorial's Program--sample-tom](sample-tom.md)
- `PathTreeProvider`: Path resource provider interface, which can load data from database, text, etc., and load it into the resource permission matcher `DefaultPathRoleMatcher`.
- `SurenessAccountProvider`: Account information provider interface, to load data from database, text, etc., and load it into the `processor` that needs account data.
When we switched the project from the configuration file mode to the database mode, we simply replaced the implementation classes of these interfaces.
1. `PathTreeProvider`
````
public interface PathTreeProvider {
Set<String> providePathData();
Set<String> provideExcludedResource();
}
````
This interface mainly needs to implement the above two methods.
`ProvidePathData` is to load resource permission configuration information, which is the resourceRole information column of sureness.yml in our configuration file mode.
`ProvideExcludedResource` is to load which resources can be filtered without authentication, that is, the excludedResource information column under sureness.yml, as follows.
````
resourceRole:
- /api/v2/host===post===[role2,role3,role4]
- /api/v2/host===get===[role2,role3,role4]
- /api/v2/host===delete===[role2,role3,role4]
- /api/v2/host===put===[role2,role3,role4]
- /api/mi/**===put===[role2,role3,role4]
- /api/v1/getSource1===get===[role1,role2]
- /api/v2/getSource2/*/*===get===[role2]
excludedResource:
- /api/v1/source3===get
- /api/v3/host===get
- /**/*.css===get
- /**/*.ico===get
- /**/*.png===get
````
When we use the database mode, it is ok to realize that this information is read from the database association. The specification returns eg: `/api/v2/host===post===[role2,role3,role4]` format data column.
Database implementation reference class - [DatabasePathTreeProvider](https://github.com/tomsun28/sureness/blob/master/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabasePathTreeProvider.java)
2. `SurenessAccountProvider`
````
public interface SurenessAccountProvider {
SurenessAccount loadAccount(String appId);
}
````
This interface mainly needs to implement the above loadAccount method, and the user's account information can be found from the database or redis cache through the user's unique identification and returned.
Default account information class `SurnessAccount` is as follows:
````
public class DefaultAccount implements SurenessAccount {
private String appId;
private String password;
private String salt;
private List<String> ownRoles;
private boolean disabledAccount;
private boolean excessiveAttempts;
}
````
Database implementation reference class - [DatabaseAccountProvider](https://github.com/tomsun28/sureness/blob/master/sample-tom/src/main/java/com/usthe/sureness/sample/tom/sureness/provider/DatabaseAccountProvider.java)
Detail please refer to [Sureness integration springboot sample(database scheme)](sample-tom.md)
## Custom Processor
Suggest take a look at the interface sureness provided, detail [Advanced Use](extend-point.md)
A subject also can support by different processors, so we can custom processor to support custom subject.
`A subject also can support by different processor, so we can custom processor to support custom subject`
`implment Processor, define which subject can support and implment processing details`
The processor is the authentication and authentication processor for the requested user account information subject. We need to implement the BaseProcessor interface to implement our custom authentication and authentication method.
Sureness has built-in PasswordProcessor that processes PasswordSubject based on account password authentication, and JwtProcessor that processes JwtSubject based on jwt authentication.
Detail please refer to [30 Minute Tutorial's Program--sample-tom](sample-tom.md)
Before customization, it is recommended to understand the sureness's process and the extended interface provided, see [Advanced Extension](extend-point.md) for details.
-`Processor`: `Subject` processing interface, according to Subject information, perform authentication
```
public abstract class BaseProcessor implements Processor{
public abstract boolean canSupportSubjectClass(Class<?> var);
public abstract Subject authenticated (Subject var) throws SurenessAuthenticationException;
public abstract void authorized(Subject var) throws SurenessAuthorizationException;
}
```
The above are some important interface methods of BaseProcessor. The custom processor requires us to implement these methods.
-`canSupportSubjectClass` judges whether to support this subject class type of input, for example, JwtProcessor only supports JwtSubject, PasswordProcessor only supports PasswordSubject.
-`authenticated` authenticates the subject, and performs the account authentication of the requesting user based on the incoming subject information and system information.
-`authorized` authenticates the subject, and the authentication determines whether the user has the access right to access the api.
Sureness uses an exception process model. The above authentication failures or authentication failures will throw different types of exceptions. The user captures and judges at the outermost point to implement the next process.
Detail please refer to [Sureness integration springboot sample(database scheme)](sample-tom.md)
......@@ -4,7 +4,11 @@ Custom subject creator is our most frequently used extension.
When the request body object is not a servlet or jax-rs standard api, we need to customize the subject creator,
make it obtain the request information we need (request path, request method, authentication information, etc.) through the request object, thereby creating the corresponding subject.
Suggest take a look at the interface sureness provided, detail [Advanced Use](extend-point.md)
Sureness has built-in `BasicSubjectServletCreator` that can create `PasswordSubject` based on account password,
and create the `JwtSubjectServletCreator` of the jwt type `JwtSubject`, etc.
Of course, we can customize the subjectCreator we need to create the subject.
Before customization, it is recommended to understand the sureness's process and the extended interface provided, see [Advanced Extension](extend-point.md) for details.
- `SubjectCreate`: Create a `Subject` interface and create different types of `Subject` objects according to the request content.
......
## Custom Subject
Suggest take a look at the interface sureness provided, detail [Advanced Use](extend-point.md)
Subject contains the user information in our request.
Sureness has built-in `PasswordSubject` based on account password, `JwtSubject` based on jwt, etc.
Of course, we can customize the subject we need to expand our user information.
`Implment Subject, add custom subject content`
`Implment SubjectCreate to create custom subject`
`Implment Processor to support custom subject`
Before customization, it is recommended to understand the sureness's process and the extended interface provided, see [Advanced Extension](extend-point.md) for details.
Detail please refer to [30 Minute Tutorial's Program--sample-tom](sample-tom.md)
-`Subject`: Authentication and authorization object interface, providing access to the object's account info, requesting resources, roles and other information.
Customizing the subject requires the following process:
1. `Implment Subject, add custom subject content`
2. `Implment SubjectCreate to create custom subject`, see [Custom SubjectCreator](custom-subject-creator.md)
3. `Implment Processor to support custom subject`, see [Custom Processor](custom-processor.md)
Detail please refer to [Sureness integration springboot sample(database scheme)](sample-tom.md)
......@@ -37,39 +37,36 @@ public DefaultSurenessConfig surenessConfig() {
#### Load Auth Config DataSource
Sureness need dataSource to authenticate and authorize, eg: role data, user data etc.
The dataSource can load from txt, dataBase, no dataBase or annotation etc.
We provide interfaces `SurenessAccountProvider`, `PathTreeProvider` for user implement to load data from the dataSource where they want.
`SurenessAccountProvider` - Account datasource provider interface.
`PathTreeProvider` - Resource uri-role datasource provider interface.
Sureness authentication requires us to provide our own account data, role permission data, etc. These data may come from text, relational databases, non-relational databases, annotations, etc.
We provide interfaces `SurenessAccountProvider`, `PathTreeProvider` for user implement to load data from the dataSource where they want.
We provide default dataSource implement which load dataSource from txt(sureness.yml), user can defined their data in sureness.yml.
We also provider dataSource implement which load dataSource form annotation - `AnnotationLoader`.
- `SurenessAccountProvider` - Account datasource provider interface.
- `PathTreeProvider` - Resource uri-role datasource provider interface.
Default Document DataSource Config - sureness.yml, see: [Default Document DataSource](default-datasource.md)
Annotation DataSource Config Detail, see: [Annotation DataSource](annotation-datasource.md)
If the configuration resource data comes from text, please refer to [sureness integration springboot sample(configuration file scheme)--sample-bootstrap](https://github.com/tomsun28/sureness/tree/master/sample-bootstrap)
If the configuration resource data comes from dataBase, please refer to [sureness integration springboot sample(database scheme)-sample-tom](https://github.com/tomsun28/sureness/tree/master/sample-tom)
Default Document DataSource Config - `sureness.yml`, see: [Default Document DataSource](default-datasource.md)
Annotation DataSource Config Detail - `AnnotationLoader`, see: [Annotation DataSource](annotation-datasource.md)
If the configuration resource data comes from text, please refer to [Sureness integration springboot sample(configuration file scheme)](https://github.com/tomsun28/sureness/tree/master/sample-bootstrap)
If the configuration resource data comes from dataBase, please refer to [Sureness integration springboot sample(database scheme)](https://github.com/tomsun28/sureness/tree/master/sample-tom)
#### Add an Interceptor Intercepting All Requests
The essence of `sureness` is to intercept all rest requests for authenticating and Authorizing.
The interceptor can be a filter or a spring interceptor, it intercepts all request to check them.
The essence of sureness is to intercept all rest requests for authenticating and Authorizing.
The interceptor can be a filter or a spring interceptor, it intercepts all request to check them.
```
SubjectSum subject = SurenessSecurityManager.getInstance().checkIn(servletRequest)
```
#### Implement Auth Exception Handling Process
`sureness` uses exception handling process:
1. If auth success, method - `checkIn` will return a `SubjectSum` object containing user information.
2. If auth failure, method - `checkIn` will throw different types of auth exceptions.
Users need to continue the subsequent process based on these exceptions.(like return the request response)
Sureness uses exception handling process:
- If auth success, method - `checkIn` will return a `SubjectSum` object containing user information.
- If auth failure, method - `checkIn` will throw different types of auth exceptions.
Users need to continue the subsequent process based on these exceptions.(eg: return the request response)
Here we need to customize the exceptions thrown by `checkIn`,
passed directly when auth success, catch exception when auth failure and do something:
Here we need to customize the exceptions thrown by `checkIn`, passed directly when auth success, catch exception when auth failure and do something:
```
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册