A simple and efficient jvm security framework that focus on the protection of REST API.
Home Page: usthe.com/sureness | su.usthe.com
Sureness is a simple and efficient open-source security framework that focus on the protection of REST API.
Provide authentication and authorization, based on RBAC.
No specific framework dependency (supports Javalin, Spring Boot, Quarkus, Ktor, Micronaut and more).
Supports dynamic modification of permissions.
Supports WebSockets and HTTP containers (Servlet and JAX-RS).
Supports JWT, Basic Auth, Digest Auth, and can custom auth methods.
High performance with Dictionary Matching Tree.
Good extension interface, demos and documentation.
Sureness has a sensible default configuration, is easy to customize, and is not couple to any one framework, which enables developers to quickly and safely protect their projects in multiple scenarios.
~ | Sureness | Shiro | Spring Security |
---|---|---|---|
Multi Framework Support | support | support need modify | not support |
REST API | support | support need modify | support |
Websocket | support | not support | not support |
Path Match | dictionary matching tree | ant match | ant match |
Annotation Support | support | support | support |
Servlet | support | support | support |
JAX-RS | support | not support | not support |
Dynamic Permissions | support | support need modify | support need modify |
Performance | fast | slower | slower |
Learning Curve | simple | simple | steep |
Benchmark test shows Sureness to lose 0.026ms performance compared to frameless application, Shiro lose 0.088ms, Spring Security lose 0.116ms.
In contrast, Sureness basically does not consume performance, and the performance (TPS loss) is 3 times that of Shiro and 4 times that of Spring Security.
The performance gap will be further widened as the api matching chain increases.
Detail see Benchmark Test
requestUri===httpMethod
.post,get,put,delete...
) is considered as a resource as a whole.eg: /api/v2/book===get
Resource path matching see: URI Match
When use maven or gradle build project, add coordinate
<dependency>
<groupId>com.usthe.sureness</groupId>
<artifactId>sureness-core</artifactId>
<version>1.0.8</version>
</dependency>
compile group: 'com.usthe.sureness', name: 'sureness-core', version: '1.0.8'
The default configuration -DefaultSurenessConfig
uses the document datasource sureness.yml
as the auth datasource.
It supports JWT auth, Basic auth, Digest authentication.
@Bean
public DefaultSurenessConfig surenessConfig() {
return new DefaultSurenessConfig();
}
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.Default Document DataSource Config - sureness.yml
, see: Default Document DataSource
Annotation DataSource Config Detail - AnnotationLoader
, see: Annotation DataSource
If the configuration resource data comes from text, please refer to Sureness integration Spring Boot sample(configuration file scheme)
If the configuration resource data comes from dataBase, please refer to Sureness integration Spring Boot sample(database scheme)
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)
Sureness uses exception handling process:
checkIn
will return a SubjectSum
object containing user information.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 {
SubjectSum subject = SurenessSecurityManager.getInstance().checkIn(servletRequest);
} catch (ProcessorNotFoundException | UnknownAccountException | UnsupportedSubjectException e4) {
// Create subject error related execption
} catch (DisabledAccountException | ExcessiveAttemptsException e2 ) {
// Account disable related exception
} catch (IncorrectCredentialsException | ExpiredCredentialsException e3) {
// Authentication failure related exception
} catch (UnauthorizedException e5) {
// Authorization failure related exception
} catch (SurenessAuthenticationException | SurenessAuthorizationException e) {
// other sureness exception
}
Detail see: Default Sureness Auth Exception
Have Fun
Sureness supports custom subject, custom subjectCreator, custom processor and more.
Before advanced custom extension, let's first understand the general process of Sureness:
As in the above process, Subject is created by SubjectCreate according to the request body, and different authentication processors process the supported Subjects.
Sureness provides the following common interfaces as extension points:
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.Refer to Extension Point for the extended documentation.
Implment Subject, add custom subject content
Implment SubjectCreate to create custom subject
Implment Processor to support custom subject
See Custom Subject
Implment SubjectCreate to create your custom subject
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
See Custom Processor
Implment PathTreeProvider, load in DefaultPathRoleMatcher
Implment SurenessAccountProvide, load in processor
Detail please refer to Sureness integration Spring Boot sample(database scheme)
Very welcome to Contribute this project, go further and better with Sureness.
Components of Repository:
See CONTRIBUTING
HertzBeat
An open-source, real-time monitoring system with custom-monitor and agentLess: Github
JustAuth
A Java library of third-party authorized login: Github
MaxKey
Leading-Edge Enterprise-Class open source IAM Identity and Access management product: Github
PhalApi
PHP Api Framework: Website
QQ Group: 390083213
Github Discussion
Gitter Channel
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
Activity
Community
Health
Trend
Influence
:Code submit frequency
:React/respond to issue & PR etc.
:Well-balanced team members and collaboration
:Recent popularity of project
:Star counts, download counts etc.