Skip to content

Commit

Permalink
Merge pull request #3 from EdwinBetanc0urt/feature/separate-setup-to-…
Browse files Browse the repository at this point in the history
…create-sys-config

feat: Separate setup create system config.
  • Loading branch information
yamelsenih authored Sep 27, 2024
2 parents faca697 + 49a0159 commit 91f704e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/main/java/org/spin/eca52/setup/CreateTokenDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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@";
}

Expand Down Expand Up @@ -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;
}

}
8 changes: 8 additions & 0 deletions src/main/java/org/spin/eca52/util/JWTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
* @author Yamel Senih, [email protected], 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";

}

0 comments on commit 91f704e

Please sign in to comment.