Merge remote-tracking branch 'origin/release/v2.0.0' into release/v2.0.0
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# JDevKit
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
JDevKit is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
|
||||
|
||||
## Installation and Usage
|
||||
|
||||
@@ -2,12 +2,4 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
This module is the main part of `JDevKit`, an open-source Java class library that provides a set of convenient tools to streamline code development and enhance productivity. This module serves as the basement of other modules.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience.
|
||||
|
||||
## Installation
|
||||
|
||||
You don't have to install this module at all, any module which is from `JDevKit` contains this `devkit-core` module.
|
||||
This module serves as the basement of `JDevKit`. It provides some base exceptions that `JDevKit` might use.
|
||||
+9
-47
@@ -2,53 +2,15 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
This module is part of `JDevKit`, an open-source Java Development Kit that provides a set of
|
||||
convenient tools to streamline code development and enhance productivity. This module serves as the
|
||||
useful toolkit for the library, contains a collection of utility classes commonly used in all Java
|
||||
Application development.
|
||||
This module provides a set of utilities to streamline Java codes.
|
||||
|
||||
## Prerequisites
|
||||
## Features
|
||||
|
||||
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for
|
||||
better experience.
|
||||
- AES encryption and decryption;
|
||||
- Base64 encode and decode;
|
||||
- Boolean calculation;
|
||||
- Reduce `if...else...` with **lambdas**;
|
||||
- Hash calculation for strings;
|
||||
- Convert Java beans to map and map to Java beans;
|
||||
- Simplified range generator.
|
||||
|
||||
## Installation
|
||||
|
||||
### If you are using `Maven`
|
||||
|
||||
It is quite simple to install this module by `Maven`. The only thing you need to do is find your
|
||||
`pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add
|
||||
the following codes to `<dependencies>` node:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.onixbyte</groupId>
|
||||
<artifactId>devkit-utils</artifactId>
|
||||
<version>${devkit-utils.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at
|
||||
`/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`),
|
||||
then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This
|
||||
could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do
|
||||
is click the refresh button of `Maven`.
|
||||
|
||||
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the
|
||||
following steps.
|
||||
|
||||
1. Download the `jar` file from any place you can get and transfer the `jar` files to your
|
||||
work computer.
|
||||
2. Move the `jar` files to your local `Maven` Repository as the path of
|
||||
`/path/to/maven_local_repo/com/onixbyte/devkit-utils/`.
|
||||
|
||||
### If you are using `Gradle`
|
||||
|
||||
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
|
||||
|
||||
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure
|
||||
in the build script:
|
||||
|
||||
```groovy
|
||||
implementation 'com.onixbyte:devkit-utils:${devkit-utils.version}'
|
||||
```
|
||||
|
||||
+20
-51
@@ -2,68 +2,37 @@
|
||||
|
||||
## Introduction
|
||||
|
||||
Module `guid` is a library that provides utilities for generating and working with globally unique
|
||||
identifiers (GUIDs). GUIDs are globally unique across all devices and systems, making them ideal
|
||||
for various use cases like database record keys, distributed systems, and tracking objects.
|
||||
Module `guid` serves as a guid creator for other `JDevKit` modules. You can also use this module as a guid creator standards.
|
||||
|
||||
The `guid` module offers a reliable and efficient GUID generator, allowing developers to create
|
||||
unique identifiers with low collision probability. It also provides features to customize the
|
||||
format of generated GUIDs, making it flexible and suitable for different applications.
|
||||
We have already implemented `SnowflakeGuidCreator`, you can also implement a custom guid creations by implementing `com.onixbyte.guid.GuidCreator`.
|
||||
|
||||
With `guid`, developers can easily integrate globally unique identifiers into their projects,
|
||||
ensuring data integrity, avoiding duplicates, and simplifying the identification of objects across
|
||||
various systems. The module is designed to be simple to use, highly performant, and compatible with
|
||||
different programming languages and frameworks.
|
||||
## Example usage
|
||||
|
||||
## Prerequisites
|
||||
### A UUID creator
|
||||
|
||||
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for
|
||||
better experience.
|
||||
|
||||
## Installation
|
||||
|
||||
### If you are using `Maven`
|
||||
|
||||
It is quite simple to install this module by `Maven`. The only thing you need to do is find your
|
||||
`pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add
|
||||
the following codes to `<dependencies>` node:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.onixbyte</groupId>
|
||||
<artifactId>devkit-utils</artifactId>
|
||||
<version>${devkit-utils.version}</version>
|
||||
</dependency>
|
||||
```java
|
||||
GuidCreator<UUID> uuidCreator = (GuidCreator<UUID>) UUID::randomUUID;
|
||||
```
|
||||
|
||||
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at
|
||||
`/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`),
|
||||
then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This
|
||||
could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do
|
||||
is click the refresh button of `Maven`.
|
||||
### A custom guid creator
|
||||
|
||||
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the
|
||||
following steps.
|
||||
Assume that you need serial guid creator.
|
||||
|
||||
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work
|
||||
computer.
|
||||
2. Move the `jar` files to your local `Maven` Repository as the path of
|
||||
`/path/to/maven_local_repo/com/onixbyte/devkit-utils/`.
|
||||
```java
|
||||
@Component
|
||||
public class CustomGuidCreator implementes GuidCreator<String> {
|
||||
|
||||
### If you are using `Gradle`
|
||||
public final RedisTemplate<String, Long> serialRedisTemplate;
|
||||
|
||||
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
|
||||
@Autowired
|
||||
public CustomGuidCreator(RedisTemplate<String, Long> serialRedisTemplate) {
|
||||
this.serialRedisTemplate = serialRedisTemplate;
|
||||
}
|
||||
|
||||
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure
|
||||
in the build script:
|
||||
@Override public String nextId() {
|
||||
return "SOME_PREFIX" + serialRedisTemplate.opsForValue().get("some_serial_key");
|
||||
}
|
||||
|
||||
```groovy
|
||||
implementation 'com.onixbyte:guid:${guid.version}'
|
||||
}
|
||||
```
|
||||
|
||||
### If you are not using `Maven` or `Gradle`
|
||||
|
||||
1. Download the `jar` file from the Internet.
|
||||
2. Create a folder in your project and name it as a name you like(i.e., for me, I prefer `vendor`).
|
||||
3. Put the `jar` file to the folder you just created in Step 2.
|
||||
4. Add this folder to your project `classpath`.
|
||||
|
||||
@@ -57,12 +57,15 @@ public class EcKeyLoader implements KeyLoader {
|
||||
|
||||
private final KeyFactory keyFactory;
|
||||
|
||||
private final Base64.Decoder decoder;
|
||||
|
||||
/**
|
||||
* Initialise a key loader for EC-based algorithms.
|
||||
*/
|
||||
public EcKeyLoader() {
|
||||
try {
|
||||
this.keyFactory = KeyFactory.getInstance("EC");
|
||||
this.decoder = Base64.getDecoder();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new KeyLoadingException(e);
|
||||
}
|
||||
@@ -84,7 +87,7 @@ public class EcKeyLoader implements KeyLoader {
|
||||
.replaceAll("-----BEGIN (EC )?PRIVATE KEY-----", "")
|
||||
.replaceAll("-----END (EC )?PRIVATE KEY-----", "")
|
||||
.replaceAll("\n", "");
|
||||
var decodedKeyString = Base64.getDecoder().decode(pemKeyText);
|
||||
var decodedKeyString = decoder.decode(pemKeyText);
|
||||
var keySpec = new PKCS8EncodedKeySpec(decodedKeyString);
|
||||
|
||||
var _key = keyFactory.generatePrivate(keySpec);
|
||||
@@ -114,7 +117,7 @@ public class EcKeyLoader implements KeyLoader {
|
||||
.replaceAll("-----BEGIN (EC )?PUBLIC KEY-----", "")
|
||||
.replaceAll("-----END (EC )?PUBLIC KEY-----", "")
|
||||
.replaceAll("\n", "");
|
||||
var keyBytes = Base64.getDecoder().decode(pemKeyText);
|
||||
var keyBytes = decoder.decode(pemKeyText);
|
||||
var spec = new X509EncodedKeySpec(keyBytes);
|
||||
var key = keyFactory.generatePublic(spec);
|
||||
if (key instanceof ECPublicKey publicKey) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Map Util Unsafe
|
||||
|
||||
`map-util-unsafe` provides a set of more convenient utilities for converting Java bean to Map or Map to Java bean, but which are less safe than the `MapUtil` provided in `devkit-utils`.
|
||||
|
||||
This `MapUtil` is implemented with Reflect API, which might be removed in later JDKs.
|
||||
@@ -0,0 +1,3 @@
|
||||
# Num4j
|
||||
|
||||
`num4j` provides some mathematical algorithms and utilities such as chained high-precision mathematical calculator and percentile statistic algorithm.
|
||||
@@ -1,97 +1,37 @@
|
||||
# Property Guard
|
||||
|
||||
## Introduction
|
||||
`property-guard-spring-boot-starter` is a utility that can help you protect secret values in Spring Boot configurations.
|
||||
|
||||
This feature is designed to protect the security of configurations and data, to a certain extent, to control the flow of developers leading to the leakage of sensitive information.
|
||||
## Example usage
|
||||
|
||||
## Prerequisites
|
||||
### 1. Implementation this module
|
||||
|
||||
This whole `JDevKit` is developed by **JDK 17**, which means you have to use JDK 17 for better experience. Except this, this module is designed for Spring Boot framework, so you have to install Spring Boot (v3) in your application.
|
||||
|
||||
## Installation
|
||||
|
||||
### If you are using `Maven`
|
||||
|
||||
It is quite simple to install this module by `Maven`. The only thing you need to do is find your `pom.xml` file in the project, then find the `<dependencies>` node in the `<project>` node, and add the following codes to `<dependencies>` node:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>cn.org.codecrafters</groupId>
|
||||
<artifactId>property-guard-spring-boot-starter</artifactId>
|
||||
<version>${property-guard-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation(platform("com.onixbyte:devkit-bom:$devKitVersion"))
|
||||
implementation("com.onixbyte:devkit-utils")
|
||||
implementation("com.onixbyte:property-guard-spring-boot-starter")
|
||||
}
|
||||
```
|
||||
|
||||
And run `mvn dependency:get` in your project root folder(i.e., if your `pom.xml` is located at `/path/to/your/project/pom.xml`, then your current work folder should be `/path/to/your/project`), then `Maven` will automatically download the `jar` archive from `Maven Central Repository`. This could be **MUCH EASIER** if you are using IDE(i.e., IntelliJ IDEA), the only thing you need to do is click the refresh button of `Maven`.
|
||||
### 2. Generate a secret
|
||||
|
||||
If you are restricted using the Internet, and have to make `Maven` offline, you could follow the following steps.
|
||||
Use the following codes to get a random secret.
|
||||
|
||||
1. Download the `jar` file from any place you can get and transfer the `jar` files to your work computer.
|
||||
2. Move the `jar` files to your local `Maven` Repository as the path of `/path/to/maven_local_repo/cn/org/codecrafters/property-guard-spring-boot-starter/`.
|
||||
|
||||
### If you are using `Gradle`
|
||||
|
||||
Add this module to your project with `Gradle` is much easier than doing so with `Maven`.
|
||||
|
||||
Find `build.gradle` in the needed project, and add the following code to the `dependencies` closure in the build script:
|
||||
|
||||
```groovy
|
||||
implementation 'cn.org.codecrafters:property-guard-spring-boot-starter:${property-guard-spring-boot-starter.version}'
|
||||
```
|
||||
|
||||
### If you are not using `Maven` or `Gradle`
|
||||
|
||||
1. Download the `jar` file from the Internet.
|
||||
2. Create a folder in your project and name it as a name you like(i.e., for me, I prefer `vendor`).
|
||||
3. Put the `jar` file to the folder you just created in Step 2.
|
||||
4. Add this folder to your project `classpath`.
|
||||
|
||||
## Usage
|
||||
|
||||
First, you need a 16-bit-long secret. If you don't have a good way to get a secret, you could consider using our `utils.com.onixbyte.devkit.AesUtil` or `com.onixbyte.simplejwt.SecretCreator` to create a secret.
|
||||
|
||||
For example:
|
||||
```java
|
||||
import utils.com.onixbyte.devkit.AesUtil;
|
||||
import com.onixbyte.simplejwt.SecretCreator;
|
||||
@SpringBootTest
|
||||
class SpringBootApplicationTest {
|
||||
|
||||
class GenerateRandomKeySample {
|
||||
public static void main(String[] args) {
|
||||
var secret1 = AesUtil.generateRandomSecret();
|
||||
var secret2 = SecretCreator.createSecret(16, true, true, true);
|
||||
@Test
|
||||
void contextLoads() {
|
||||
System.out.println(AesUtil.generateRandomSecret()); // Output: a 16-char long secret
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, remember this secret and encrypt the configuration properties that are required high security. For example:
|
||||
Or you can write a 16-char long secret by yourself.
|
||||
|
||||
```java
|
||||
import utils.com.onixbyte.devkit.AesUtil;
|
||||
### 3. Encrypt your secret properties and place them into your configuration file
|
||||
|
||||
class EncryptSample {
|
||||
public static void main(String[] args) {
|
||||
var dataNeedEncryption = "Sample Value";
|
||||
var key = "3856faef0d2d4f33";
|
||||
var encryptedData = AesUtil.encrypt(dataNeedEncryption, key);
|
||||
}
|
||||
}
|
||||
```
|
||||
### 4. Run application with parameter `--pg.key=$your_secret`
|
||||
|
||||
After that, copy the encrypted data to `application.properties` or `application.yml`.
|
||||
|
||||
For `yml`:
|
||||
```yaml
|
||||
app:
|
||||
sample-configuration: pe:t4YBfv8M9ZmTzWgTi2gJqg== # "pe:" is the prefix that declare that this property is encrypted.
|
||||
```
|
||||
|
||||
For `properties`:
|
||||
```properties
|
||||
app.sample-configuration=pe:t4YBfv8M9ZmTzWgTi2gJqg==
|
||||
```
|
||||
|
||||
## Contact
|
||||
|
||||
If you have any suggestions, ideas, don't hesitate contacting us via [GitHub Issues](https://github.com/CodeCraftersCN/jdevkit/issues/new) or [Discord Community](https://discord.gg/NQK9tjcBB8).
|
||||
|
||||
If you face any bugs while using our library and you are able to fix any bugs in our library, we would be happy to accept pull requests from you on [GitHub](https://github.com/CodeCraftersCN/jdevkit/compare).
|
||||
Reference in New Issue
Block a user