Framework/Spring Common
Framework
ApiHug SDK spring common Extension
Spring extension package that includes basic shared classes and functions, aimed at facilitating faster development:
Source-of-truth note for this page:
github.com/apihug/skillsskills/spring-extensionNot enumerating all; generally very intuitive and simple; you can directly refer to the source code during use.
| Class Name | Note |
|---|---|
SimpleResultBuilder | ResponseEntity builder |
PageableResultBuilder | Supports Pageable ResponseEntity builder |
RuntimeContextInitializer | Runtime context validation and description |
The ResponseEntity builder includes:
HttpStatus.TOO_MANY_REQUESTS, with user-friendly interface definition: tooManyRequestsHope defined errors: Error or HopeErrorDetailExceptionSupports Pageable ResponseEntity builder, result pre-packaged as a Pageable object, including:
Runtime context validation and description (RuntimeContext):
RuntimeContext objectfail-fast under hope.runtime.check.module configuration set to RESTRICT mode.Runtime version validation includes:
RuntimeContextInitializer.getClass().getPackage().getImplementationVersion() compared with RuntimeContext#getProject.RuntimeContext#getProject compared with RuntimeContext#getProto version.dependencies within hope-stub.json.hope.runtime.check.module is UNCHECK; changing it to RESTRICT will cause any validation errors to lead to program startup failure. | Class Name | Note |
|---|---|
Helper | Http request header validation |
NumberUtils | Number utility functions |
TripleTypes | Assists in determining LONG/STRING/INTEGER |
Related to security, retrieving the Audit context, including: Identify context account information and Tenant context tenant information, generally derived from HopeContextHolder;
| Class Name | Note |
|---|---|
AuditContext | Retrieves account and tenant context information |
AuditContextSupplier | Custom extension point for suppliers |
Built-in security framework protocol for Hope;
| Class Name | Note |
|---|---|
SecurityContext | Hope resource (path) security configuration context |
Customer | User information, including common Identify & Tenant identifiers |
SecurityCustomizer | Security extension point for customization |
EmptySecurityContext | Default empty SecurityContext |
QuickCustomerRoleCheckerFactory | Predefined role quick-check factory |
Identify & Tenant identifiers only support: LONG | STRING | INTEGER and do not support complex or composite types;
The predefined roles include PredefinedRoleCheckerType:
| Role | Note |
|---|---|
TENANT | General tenant user |
TENANT_MANAGER | Tenant administrator |
TENANT_OWNER | Tenant owner |
PLATFORM | General platform user |
PLATFORM_MANAGER | Platform administrator |
PLATFORM_OWNER | Platform owner |
Predefined roles have limited configuration scope; they are suitable for coarse-grained roles involved in your platform. For finer-grained configuration, please use RBAC.
Refer to: ApiHug Spring Security Extensions
The checker package defines the DSL used to express authority and role combinations, but it is not "compile-time only". At runtime, ApiHug loads generated authority metadata, maps it into SecurityContext, and HopeSecurityManager resolves the checker for the current service method before enforcing access rules.
SecurityContext and HopeSecurityManager.Identify context account information and Tenant context tenant informationLONG | STRING | INTEGERThis results in a predefined Customer object with 3*3=9 combinations:
| Class Name | Identify | Tenant |
|---|---|---|
CustomerIntegerIdentifyIntegerTenant | Integer | Integer |
CustomerIntegerIdentifyLongTenant | Integer | Long |
CustomerIntegerIdentifyStringTenant | Integer | String |
CustomerLongIdentifyIntegerTenant | Long | Integer |
CustomerLongIdentifyLongTenant | Long | Long |
CustomerLongIdentifyStringTenant | Long | String |
CustomerStringIdentifyIntegerTenant | String | Integer |
CustomerStringIdentifyLongTenant | String | Long |
CustomerStringIdentifyStringTenant | String | String |
Due to the application of Hope, the base code employs code generation technology, so aspects do not require runtime dynamic proxies.
The Aspect protocol class includes only two; in our security framework, there is a SecurityAspect that implements security checks. You can also extend your own, such as for logging or auditing.
| Class Name | Note |
|---|---|
Aspect | Aspect definition |
AspectType | Aspect type |
Aspects include:
AspectTypeAspectType:
| Type | Note |
|---|---|
ALL | All aspects supported |
BEFORE | Only supports before advice |
AFTER | Only supports after advice |
EXCEPTION | Only supports exception advice |
│ PageableResultBuilder.java
│ RuntimeContextInitializer.java
│ SimpleResultBuilder.java
│
├─aspect
│ Aspect.java
│ AspectType.java
│
├─audit
│ AuditContext.java
│ AuditContextSupplier.java
│
├─context
│ CustomerContext.java
│ CustomerContextSupplier.java
│ package-info.java
│
├─security
│ │ AuthorizationToCheckerMapper.java
│ │ Customer.java
│ │ EmptySecurityContext.java
│ │ package-info.java
│ │ QuickCustomerRoleCheckerFactory.java
│ │ SecurityContext.java
│ │ SecurityCustomizer.java
│ │
│ ├─checker
│ │ And.java
│ └─internal
│ CustomerIntegerIdentifyIntegerTenant.java
│ CustomerIntegerIdentifyLongTenant.java
│ CustomerIntegerIdentifyStringTenant.java
│ CustomerLongIdentifyIntegerTenant.java
│ CustomerLongIdentifyLongTenant.java
│ CustomerLongIdentifyStringTenant.java
│ CustomerStringIdentifyIntegerTenant.java
│ CustomerStringIdentifyLongTenant.java
│ CustomerStringIdentifyStringTenant.java
│ ImmutableCustomer.java
│ PredefinedCustomerOption.java
│
└─util
Helper.java
NumberUtils.java
TripleTypes.java