Spring Common

Spring extension package that includes basic shared classes and functions, aimed at facilitating faster development:

Features

Not enumerating all; generally very intuitive and simple; you can directly refer to the source code during use.

Common

Class NameNote
SimpleResultBuilderResponseEntity builder
PageableResultBuilderSupports Pageable ResponseEntity builder
RuntimeContextInitializerRuntime context validation and description

SimpleResultBuilder

The ResponseEntity builder includes:

  1. Default functions on the ResponseEntity object
  2. Common errors like HttpStatus.TOO_MANY_REQUESTS, with user-friendly interface definition: tooManyRequests
  3. Hope defined errors: Error or HopeErrorDetailException

PageableResultBuilder

Supports Pageable ResponseEntity builder, result pre-packaged as a Pageable object, including:

  1. pageIndex: Current page number
  2. pageSize: Number of objects on this page
  3. totalCount: Total count
  4. totalPage: Total pages
  5. data: List of objects

RuntimeContextInitializer

Runtime context validation and description (RuntimeContext):

  1. Assembles runtime: RuntimeContext object
  2. Runtime version conflicts, particularly regarding stub dependencies on wire; checks if interface definitions have changed and whether to fail-fast under hope.runtime.check.module configuration set to RESTRICT mode.

Runtime version validation includes:

  1. Application version RuntimeContextInitializer.getClass().getPackage().getImplementationVersion() compared with RuntimeContext#getProject.
  2. Runtime project RuntimeContext#getProject compared with RuntimeContext#getProto version.
  3. Version comparison of dependencies within hope-stub.json.

The default configuration for hope.runtime.check.module is UNCHECK; changing it to RESTRICT will cause any validation errors to lead to program startup failure.

Util

Class NameNote
HelperHttp request header validation
NumberUtilsNumber utility functions
TripleTypesAssists in determining LONG/STRING/INTEGER

Audit

Related to security, retrieving the Audit context, including: Identify context account information and Tenant context tenant information, generally derived from HopeContextHolder;

Class NameNote
AuditContextRetrieves account and tenant context information
AuditContextSupplierCustom extension point for suppliers

Security

Built-in security framework protocol for Hope;

Class NameNote
SecurityContextHope resource (path) security configuration context
CustomerUser information, including common Identify & Tenant identifiers
SecurityCustomizerSecurity extension point for customization
EmptySecurityContextDefault empty SecurityContext
QuickCustomerRoleCheckerFactoryPredefined 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:

RoleNote
TENANTGeneral tenant user
TENANT_MANAGERTenant administrator
TENANT_OWNERTenant owner
PLATFORMGeneral platform user
PLATFORM_MANAGERPlatform administrator
PLATFORM_OWNERPlatform 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

checker

The checker package contains Authority & Role combination validation DSL definitions; it serves only as Java annotations and will not be read at runtime.

Runtime implementation is achieved through wire proto with RBAC definitions!

internal

  1. Identify context account information and Tenant context tenant information
  2. Value types: LONG | STRING | INTEGER

This results in a predefined Customer object with 3*3=9 combinations:

Class NameIdentifyTenant
CustomerIntegerIdentifyIntegerTenantIntegerInteger
CustomerIntegerIdentifyLongTenantIntegerLong
CustomerIntegerIdentifyStringTenantIntegerString
CustomerLongIdentifyIntegerTenantLongInteger
CustomerLongIdentifyLongTenantLongLong
CustomerLongIdentifyStringTenantLongString
CustomerStringIdentifyIntegerTenantStringInteger
CustomerStringIdentifyLongTenantStringLong
CustomerStringIdentifyStringTenantStringString

Aspect

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 NameNote
AspectAspect definition
AspectTypeAspect type

Aspects include:

  1. type AspectType
  2. priority: Higher values indicate higher priority
  3. name: Default class name
  4. before: Before advice
  5. after: After advice
  6. exception: Exception advice

AspectType:

TypeNote
ALLAll aspects supported
BEFOREOnly supports before advice
AFTEROnly supports after advice
EXCEPTIONOnly supports exception advice

Refer

│  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