diff --git a/src/main/java/org/spin/eca52/setup/CreateTokenDefinition.java b/src/main/java/org/spin/eca52/setup/CreateTokenDefinition.java index 3c1f0ff..df4fd27 100644 --- a/src/main/java/org/spin/eca52/setup/CreateTokenDefinition.java +++ b/src/main/java/org/spin/eca52/setup/CreateTokenDefinition.java @@ -22,6 +22,7 @@ import org.compiere.model.Query; import org.compiere.util.Env; import org.spin.eca52.security.JWT; +import org.spin.eca52.util.JWTUtil; import org.spin.model.MADTokenDefinition; import org.spin.util.ISetupDefinition; @@ -39,7 +40,11 @@ public class CreateTokenDefinition implements ISetupDefinition { public String doIt(Properties context, String transactionName) { // Add Token Definition createTokenDefinition(context, transactionName); - // financial management + + // Add System Configurator + createSystemConfigurator(context, transactionName); + + // token definition return "@AD_SetupDefinition_ID@ @Ok@"; } @@ -70,13 +75,25 @@ private MADTokenDefinition createTokenDefinition(Properties context, String tran tokenDefinition.setIsHasExpireDate(false); tokenDefinition.setExpirationTime(Env.ZERO); tokenDefinition.saveEx(); - MSysConfig secretKey = new MSysConfig(context, 0, transactionName); + return tokenDefinition; + } + + + private MSysConfig createSystemConfigurator(Properties context, String transactionName) { + MSysConfig secretKey = MSysConfig.get(context, JWTUtil.ECA52_JWT_SECRET_KEY, transactionName); + if (secretKey != null) { + return secretKey; + } + // + secretKey = new MSysConfig(context, 0, transactionName); + secretKey.setEntityType(JWTUtil.ECA52_EntityType); secretKey.setAD_Org_ID(0); secretKey.setConfigurationLevel(MSysConfig.CONFIGURATIONLEVEL_Client); secretKey.setValue(""); - secretKey.setName("ECA52_JWT_SECRET_KEY"); + secretKey.setName(JWTUtil.ECA52_JWT_SECRET_KEY); secretKey.setDescription("A Secret Key for generate JWT based token, fill it"); secretKey.saveEx(); - return tokenDefinition; + return secretKey; } + } diff --git a/src/main/java/org/spin/eca52/util/JWTUtil.java b/src/main/java/org/spin/eca52/util/JWTUtil.java index 729ba7f..50e9c18 100644 --- a/src/main/java/org/spin/eca52/util/JWTUtil.java +++ b/src/main/java/org/spin/eca52/util/JWTUtil.java @@ -23,6 +23,14 @@ * @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com */ public class JWTUtil { + + /** Entity Type Spin Contribution (JWT Token Generator) */ + public static final String ECA52_EntityType = "ECA52"; + /** Default key for JWT */ public static final String ECA52_JWT_SECRET_KEY = "ECA52_JWT_SECRET_KEY"; + + /** Default expiration time for JWT */ + public static final String ECA52_JWT_EXPIRATION_TIME = "ECA52_JWT_EXPIRATION_TIME"; + }