Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand SpringBoot to generate License

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to understand SpringBoot to generate License related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to understand SpringBoot generate License will have a harvest, let's take a look at it.

Preface

License refers to the copyright license. When we finish developing the system, if we don't want users to go whoring all the time, for example, renew it on a time-by-time basis, License will play a role.

We can specify the validity period of the License to the system and control the availability time of the system.

So for SpringBoot projects, how do you add License? Next, the prince brings you a set of solutions. (of course, there is more than one way to achieve it.)

Generate License

The tool has been packaged, and friends can download it directly and use it: https://gitee.com/lm970585581/spring-boot2-license

After downloading, open the cloud-license-serve project and start it directly.

Then call the API for obtaining information of the project: http://localhost:9081/license/getServerInfos?osName=windows

You will get a result similar to the following, representing the ip address, mac address, cpu serial number, and motherboard serial number, respectively.

{"ipAddress": ["192.168.80.1", "192.168.220.1"], "macAddress": ["01-51-56-C0-00-01", "00-52-56-C0-00-08", "BC-54-2D-DF-69-FC"], "cpuSerial": "BFECFBFF000806EC", "mainBoardSerial": "L1HF16301D5"}

Use the keytool tool that comes with JDK to generate a public and private key certificate library:

If we set the public KeyStore password to: public_password1234 and the private KeyStore password to: private_password1234, the generated command is as follows:

# generate commands keytool-genkeypair-keysize 1024-validity 3650-alias "privateKey"-keystore "privateKeys.keystore"-storepass "public_password1234"-keypass "private_password1234"-dname "CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH C=CN "# Export command keytool-exportcert-alias" privateKey "- keystore" privateKeys.keystore "- storepass" public_password1234 "- file" certfile.cer "# Import command keytool-import-alias" publicCert "- file" certfile.cer "- keystore" publicCerts.keystore "- storepass" public_password1234 "

After the above command is executed, three files are generated under the current path, namely, privateKeys.keystore, publicCerts.keystore, and certfile.cer. The file certfile.cer is no longer needed and can be deleted, the file privateKeys.keystore is used to generate the license file for the customer in the current ServerDemo project, and the file publicCerts.keystore is deployed to the client server with the application code, and the user decrypts the license file and verifies its license information.

Finally, we generate license, and the calling API address is: http://localhost:9081/license/generateLicense

The parameter to be called is a json parameter in the following format:

{"subject": "license_demo", "privateAlias": "privateKey", "keyPass": "private_password1234", "storePass": "public_password1234", "licensePath": "C:/Users/zifangsky/Desktop/license_demo/license.lic", "privateKeysStorePath": "C:/Users/zifangsky/Desktop/license_demo/privateKeys.keystore", "issuedTime": "2018-07-10 00:00:01" "expiryTime": "2019-12-31 23:59:59", "consumerType": "User", "consumerAmount": 1, "description": "this is the certificate description information", "licenseCheckModel": {"ipAddress": ["192.168.245.1", "10.0.5.22"], "macAddress": ["00-50-56-C0-00-01" "50-7B-9D-F9-18-41"], "cpuSerial": "BFEBFBFF000406E3", "mainBoardSerial": "L1HF65E00X9"}}

If the request is successful, a license.lic file is finally generated in the path set by the licensePath parameter, which is the server license file for the customer to deploy the code.

Use License

If our friends follow the steps above step by step, we have got license.lic, and then we will use license in our own project.

Cloud-license-client is an example of introducing a project, which can be used directly when opened.

To introduce your own project, just import the following files

And configure the interceptor LicenseCheckInterceptor can be used. The configuration method is in the InterceptorConfig class, which you can refer to.

It should be noted here that two files are required to use license: license.lic,publicCerts.keystore

The path of the demonstration project configuration is absolute. Generally, we will configure the relative path, put two files under the project, and configure the location in the LicenseCheckListener class.

Modify the following part to read the relative path.

I won't show you how to modify it here, because it's easy to modify.

There is one more thing to note:

For the two classes of LicenseCheckModel,LicenseCreatorParam, you must make sure that the package name is the same as the package name when you generate license when you introduce it to your client, otherwise it will lead to serialization failure.

This is the end of the article on "how to understand SpringBoot to generate License". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to understand SpringBoot to generate License". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report