Joaquín Reñé
2025-11-03 64993ff80e90bee69de7a179dc6af8b5b079197b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
 */
package net.curisit.securis;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import net.curisit.securis.beans.LicenseBean;
import net.curisit.securis.beans.RequestBean;
import net.curisit.securis.beans.SignedLicenseBean;
import net.curisit.securis.utils.JsonUtils;
/**
* FreeLicenseGenerator
* <p>
* Helper to generate a signed FREE license (no expiration) for a given app and code.
* @author JRA
 * Last reviewed by JRA on Oct 5, 2025.
*/
public class FreeLicenseGenerator {
   /** Constant license type code for FREE licenses. */
   public static final String FREE_LICENSE_TYPE = "FREE";
   
   /**
   * generateLicense
   * <p>
   * Build and sign a FREE license using the default generator. Uses a <code>Date(-1)</code>
   * sentinel as "no expiration".
   *
   * @param appName application name
   * @param licCode license code
   * @param metadata additional metadata to embed
   * @return signed license bean wrapper
   * @throws SeCurisException on generation/signature errors
   */
    public static SignedLicenseBean generateLicense(String appName, String licCode, Map<String, Object> metadata) throws SeCurisException  {
        SignedLicenseBean sl = null;
        RequestBean rb = new RequestBean();
        rb.setLicenseTypeCode(FREE_LICENSE_TYPE);
        LicenseGenerator licenseGenerator = LicenseGenerator.getInstance();
        
        LicenseBean lb = licenseGenerator.generateLicense(rb, metadata, new Date(-1), licCode, appName);
        sl = new SignedLicenseBean(lb);
        return sl;
    }
    
    /**
     * Demo main
     * 
     * @param args
     * @throws SeCurisException
     */
    public static void main(String[] args) throws SeCurisException {
        Map<String, Object> metadata = new HashMap<>();
        metadata.put("max_docs", 2000);
        metadata.put("max_size", 5L*1024*1024*1024);
        SignedLicenseBean lic = generateLicense("Doxr", "DOXR-FREE-01", metadata);
        
        System.out.println(JsonUtils.toPrettyJSON(lic));
   }
}