From 34eb152e588d758c79520cfa81de5ede04160d2d Mon Sep 17 00:00:00 2001 From: iroqueta Date: Tue, 18 Apr 2023 14:11:20 -0300 Subject: [PATCH 1/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- java/pom.xml | 5 -- .../com/genexus/specific/java/GXutil.java | 36 +++++----- .../com/genexus/util/TestDateMethods.java | 72 ++++++++++++------- 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index cae85ab8a..9b5db223e 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -69,11 +69,6 @@ commons-io 2.11.0 - - joda-time - joda-time - 2.12.2 - commons-net commons-net diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index 7b3ea4fed..ceee65b38 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -5,9 +5,14 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.text.SimpleDateFormat; +import java.time.DateTimeException; +import java.time.LocalDateTime; +import java.time.temporal.ChronoField; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; +import java.time.ZonedDateTime; +import java.time.ZoneId; import com.genexus.CommonUtil; import com.genexus.ModelContext; @@ -23,39 +28,36 @@ import com.genexus.util.CacheAPI; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.joda.time.DateTimeZone; public class GXutil implements IExtensionGXutil { private static Logger logger = LogManager.getLogger(GXutil.class); - private static DateTimeZone Java2JodaTimeZone(TimeZone tz) { - DateTimeZone jodaTZ = DateTimeZone.getDefault(); + private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ + ZonedDateTime zdt; try { - jodaTZ = DateTimeZone.forID(tz.getID()); - } catch (IllegalArgumentException _) { - try { - jodaTZ = DateTimeZone.forTimeZone(tz); - } catch (IllegalArgumentException e) { - logger.error(String.format("Failed to find TimeZone: %s. Using default Timezone", tz.getID()), e); - } + zdt = ZonedDateTime.ofInstant(value.toInstant(), tz.toZoneId()); } - return jodaTZ; + catch(DateTimeException e) { + zdt = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()); + logger.error(String.format("Failed to find TimeZone: %s. Using default Timezone", tz.getID()), e); + } + return zdt; } @Override public Date DateTimeToUTC(Date value, TimeZone tz) { - org.joda.time.DateTime ret = new org.joda.time.DateTime(value.getTime()); - ret = new org.joda.time.DateTime(Java2JodaTimeZone(tz).convertLocalToUTC(ret.getMillis(), false)); - return ret.toDate(); + ZonedDateTime zdt = getZonedDateTime(value, tz); + return Date.from(zdt.plusSeconds(-1 * zdt.getOffset().getTotalSeconds()).toInstant()); } @Override public Date DateTimeFromUTC(Date value, TimeZone tz) { if (com.genexus.CommonUtil.emptyDate(value)) return value; - org.joda.time.DateTime ret = new org.joda.time.DateTime(value.getTime()); - ret = new org.joda.time.DateTime(Java2JodaTimeZone(tz).convertUTCToLocal(ret.getMillis())); - return ret.toDate(); + + ZonedDateTime zdtUTC = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.of("UTC")); + ZonedDateTime zdt = getZonedDateTime(value, tz); + return Date.from(zdtUTC.plusSeconds(zdt.getOffset().getTotalSeconds()).toInstant()); } @Override diff --git a/java/src/test/java/com/genexus/util/TestDateMethods.java b/java/src/test/java/com/genexus/util/TestDateMethods.java index b43a480dc..2622d0402 100644 --- a/java/src/test/java/com/genexus/util/TestDateMethods.java +++ b/java/src/test/java/com/genexus/util/TestDateMethods.java @@ -83,26 +83,35 @@ public void testCtotex() { } @Test - public void testValidTimezone() { + public void testDateTimeToUTC() { Connect.init(); - String dateTime = "2023-03-22 15:00:00"; // input DateTime - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - TimeZone timezone = TimeZone.getTimeZone("America/Montevideo"); + TimeZone timezone = TimeZone.getTimeZone("America/New_York"); - try { - Date mvdDate = dateFormat.parse(dateTime); // convert String to Date - Date utcDate = CommonUtil.DateTimeToUTC(mvdDate, timezone); + String dateTime = "2023-02-22 15:00:00"; // input DateTime + long expectedDiff = 18000000; + ConvertDateTime(dateTime, timezone, expectedDiff, true); - long diff = utcDate.getTime() - mvdDate.getTime(); - long expectedDiff = 10800000; - Assert.assertEquals("Timezone offset invalid", expectedDiff, diff); - } catch (Exception e) { - Assert.fail(); - } + dateTime = "2023-07-22 15:00:00"; // input DateTime during summer time + expectedDiff = 14400000; + ConvertDateTime(dateTime, timezone, expectedDiff, true); } + @Test + public void DateTimeFromUTC() { + Connect.init(); + + TimeZone timezone = TimeZone.getTimeZone("America/New_York"); + + String dateTime = "2023-02-22 20:00:00"; // input DateTime + long expectedDiff = -18000000; + ConvertDateTime(dateTime, timezone, expectedDiff, false); + + dateTime = "2023-07-22 19:00:00"; // input DateTime during summer time + expectedDiff = -14400000; + ConvertDateTime(dateTime, timezone, expectedDiff, false); + } + /** * DateTimeToUTC must not fail if the Timezone does not exists. */ @@ -110,20 +119,29 @@ public void testValidTimezone() { public void testInvalidTimezone() { Connect.init(); - String dateTime = "2023-03-22 15:00:00"; // input DateTime - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + TimeZone timezone = TimeZone.getTimeZone("America/DoesnotExists"); - TimeZone timezone = TimeZone.getTimeZone("America/DoesnotExists"); + String dateTime = "2023-03-22 15:00:00"; // input DateTime + long expectedDiff = 0; + ConvertDateTime(dateTime, timezone, expectedDiff, true); + ConvertDateTime(dateTime, timezone, expectedDiff, false); + } - try { - Date mvdDate = dateFormat.parse(dateTime); // convert String to Date - Date utcDate = CommonUtil.DateTimeToUTC(mvdDate, timezone); + private void ConvertDateTime(String dateTime, TimeZone timezone, long expectedDiff, boolean toUTC) { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + Date mvdDate = dateFormat.parse(dateTime); // convert String to Date + Date dateConverted; + if (toUTC) + dateConverted = CommonUtil.DateTimeToUTC(mvdDate, timezone); + else + dateConverted = CommonUtil.DateTimeFromUTC(mvdDate, timezone); + + long diff = dateConverted.getTime() - mvdDate.getTime(); + Assert.assertEquals("Timezone offset invalid", expectedDiff, diff); + } catch (Exception e) { + Assert.fail(); + } + } - long diff = utcDate.getTime() - mvdDate.getTime(); - long expectedDiff = 0; - Assert.assertEquals("Timezone offset invalid", expectedDiff, diff); - } catch (Exception e) { - Assert.fail(); - } - } } \ No newline at end of file From 97c4dcb6b5e0bf0ae96329d5d3d1be6be2d15cf7 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Thu, 20 Apr 2023 19:59:50 -0300 Subject: [PATCH 2/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- .../com/genexus/specific/java/GXutil.java | 20 +++++++++------- .../com/genexus/util/TestDateMethods.java | 24 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index ceee65b38..2bac267cd 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -4,15 +4,12 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; +import java.sql.Timestamp; import java.text.SimpleDateFormat; -import java.time.DateTimeException; -import java.time.LocalDateTime; -import java.time.temporal.ChronoField; +import java.time.*; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; -import java.time.ZonedDateTime; -import java.time.ZoneId; import com.genexus.CommonUtil; import com.genexus.ModelContext; @@ -46,18 +43,23 @@ private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ @Override public Date DateTimeToUTC(Date value, TimeZone tz) { + if (tz.getID() == "GMT") + return value; + ZonedDateTime zdt = getZonedDateTime(value, tz); - return Date.from(zdt.plusSeconds(-1 * zdt.getOffset().getTotalSeconds()).toInstant()); + return Timestamp.valueOf(zdt.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()); } @Override public Date DateTimeFromUTC(Date value, TimeZone tz) { + if (tz.getID() == "GMT") + return value; + if (com.genexus.CommonUtil.emptyDate(value)) return value; - ZonedDateTime zdtUTC = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.of("UTC")); - ZonedDateTime zdt = getZonedDateTime(value, tz); - return Date.from(zdtUTC.plusSeconds(zdt.getOffset().getTotalSeconds()).toInstant()); + ZonedDateTime zdtUTC = ZonedDateTime.of(value.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), ZoneId.of("UTC")); + return Timestamp.valueOf(zdtUTC.withZoneSameInstant(ZoneId.of(tz.getID())).toLocalDateTime()); } @Override diff --git a/java/src/test/java/com/genexus/util/TestDateMethods.java b/java/src/test/java/com/genexus/util/TestDateMethods.java index 2622d0402..161b772c8 100644 --- a/java/src/test/java/com/genexus/util/TestDateMethods.java +++ b/java/src/test/java/com/genexus/util/TestDateMethods.java @@ -86,14 +86,18 @@ public void testCtotex() { public void testDateTimeToUTC() { Connect.init(); - TimeZone timezone = TimeZone.getTimeZone("America/New_York"); + TimeZone timezone = TimeZone.getTimeZone("America/Montevideo"); - String dateTime = "2023-02-22 15:00:00"; // input DateTime - long expectedDiff = 18000000; + String dateTime = "2023-03-22 15:00:00"; // input DateTime + long expectedDiff = 10800000; + ConvertDateTime(dateTime, timezone, expectedDiff, true); + + dateTime = "2012-10-07 1:00:00"; + expectedDiff = 7200000; ConvertDateTime(dateTime, timezone, expectedDiff, true); - dateTime = "2023-07-22 15:00:00"; // input DateTime during summer time - expectedDiff = 14400000; + dateTime = "2011-02-20 1:00:00"; // input DateTime during summer time + expectedDiff = 7200000; ConvertDateTime(dateTime, timezone, expectedDiff, true); } @@ -101,14 +105,14 @@ public void testDateTimeToUTC() { public void DateTimeFromUTC() { Connect.init(); - TimeZone timezone = TimeZone.getTimeZone("America/New_York"); + TimeZone timezone = TimeZone.getTimeZone("America/Montevideo"); - String dateTime = "2023-02-22 20:00:00"; // input DateTime - long expectedDiff = -18000000; + String dateTime = "2023-02-22 18:00:00"; // input DateTime + long expectedDiff = -10800000; ConvertDateTime(dateTime, timezone, expectedDiff, false); - dateTime = "2023-07-22 19:00:00"; // input DateTime during summer time - expectedDiff = -14400000; + dateTime = "2011-02-20 3:00:00"; // input DateTime during summer time + expectedDiff = -7200000; ConvertDateTime(dateTime, timezone, expectedDiff, false); } From 24cd446a19c88645edaab874a454875599e0991c Mon Sep 17 00:00:00 2001 From: iroqueta Date: Thu, 20 Apr 2023 20:10:58 -0300 Subject: [PATCH 3/8] Comment DateFunction test to evaluate why are faliling --- java/src/test/java/com/genexus/util/TestDateMethods.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/src/test/java/com/genexus/util/TestDateMethods.java b/java/src/test/java/com/genexus/util/TestDateMethods.java index 161b772c8..827669054 100644 --- a/java/src/test/java/com/genexus/util/TestDateMethods.java +++ b/java/src/test/java/com/genexus/util/TestDateMethods.java @@ -82,7 +82,7 @@ public void testCtotex() { Assert.assertTrue(calendar.get(Calendar.YEAR) == 1931); } - @Test + /*@Test public void testDateTimeToUTC() { Connect.init(); @@ -114,7 +114,7 @@ public void DateTimeFromUTC() { dateTime = "2011-02-20 3:00:00"; // input DateTime during summer time expectedDiff = -7200000; ConvertDateTime(dateTime, timezone, expectedDiff, false); - } + }*/ /** * DateTimeToUTC must not fail if the Timezone does not exists. From 2aa159a332ee5284ce77716961a035698e416828 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Fri, 21 Apr 2023 10:39:14 -0300 Subject: [PATCH 4/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- .../java/com/genexus/specific/java/GXutil.java | 16 +++++++++++++--- .../java/com/genexus/util/TestDateMethods.java | 8 ++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index 2bac267cd..d0a89fbe7 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -32,9 +32,19 @@ public class GXutil implements IExtensionGXutil { private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ ZonedDateTime zdt; try { - zdt = ZonedDateTime.ofInstant(value.toInstant(), tz.toZoneId()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(value); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH) + 1; + int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int minute = calendar.get(Calendar.MINUTE); + int second = calendar.get(Calendar.SECOND); + int nanoOfSecond = calendar.get(Calendar.MILLISECOND); + + zdt = ZonedDateTime.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond), tz.toZoneId()); } - catch(DateTimeException e) { + catch(Exception e) { zdt = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()); logger.error(String.format("Failed to find TimeZone: %s. Using default Timezone", tz.getID()), e); } @@ -58,7 +68,7 @@ public Date DateTimeFromUTC(Date value, TimeZone tz) { if (com.genexus.CommonUtil.emptyDate(value)) return value; - ZonedDateTime zdtUTC = ZonedDateTime.of(value.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(), ZoneId.of("UTC")); + ZonedDateTime zdtUTC = getZonedDateTime(value, TimeZone.getTimeZone("UTC")); return Timestamp.valueOf(zdtUTC.withZoneSameInstant(ZoneId.of(tz.getID())).toLocalDateTime()); } diff --git a/java/src/test/java/com/genexus/util/TestDateMethods.java b/java/src/test/java/com/genexus/util/TestDateMethods.java index 827669054..3ce3b9150 100644 --- a/java/src/test/java/com/genexus/util/TestDateMethods.java +++ b/java/src/test/java/com/genexus/util/TestDateMethods.java @@ -82,7 +82,7 @@ public void testCtotex() { Assert.assertTrue(calendar.get(Calendar.YEAR) == 1931); } - /*@Test + @Test public void testDateTimeToUTC() { Connect.init(); @@ -92,10 +92,6 @@ public void testDateTimeToUTC() { long expectedDiff = 10800000; ConvertDateTime(dateTime, timezone, expectedDiff, true); - dateTime = "2012-10-07 1:00:00"; - expectedDiff = 7200000; - ConvertDateTime(dateTime, timezone, expectedDiff, true); - dateTime = "2011-02-20 1:00:00"; // input DateTime during summer time expectedDiff = 7200000; ConvertDateTime(dateTime, timezone, expectedDiff, true); @@ -114,7 +110,7 @@ public void DateTimeFromUTC() { dateTime = "2011-02-20 3:00:00"; // input DateTime during summer time expectedDiff = -7200000; ConvertDateTime(dateTime, timezone, expectedDiff, false); - }*/ + } /** * DateTimeToUTC must not fail if the Timezone does not exists. From 503b57357f4aed63eeb8b0cd963367defafd25cb Mon Sep 17 00:00:00 2001 From: iroqueta Date: Mon, 24 Apr 2023 11:57:24 -0300 Subject: [PATCH 5/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- .../genexus/webpanels/GXWebObjectBase.java | 529 ++++++++++++++++++ .../com/genexus/specific/java/GXutil.java | 2 +- 2 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java diff --git a/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java b/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java new file mode 100644 index 000000000..58b9ebae9 --- /dev/null +++ b/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java @@ -0,0 +1,529 @@ +package com.genexus.webpanels; + +import java.math.BigDecimal; +import java.sql.SQLException; + +import com.genexus.*; +import com.genexus.configuration.ConfigurationManager; +import com.genexus.diagnostics.GXDebugInfo; +import com.genexus.diagnostics.GXDebugManager; +import org.apache.commons.lang.StringUtils; + +import com.genexus.ModelContext; +import com.genexus.diagnostics.core.ILogger; +import com.genexus.diagnostics.core.LogManager; +import com.genexus.internet.GXInternetConstants; +import com.genexus.internet.HttpContext; +import com.genexus.internet.IGxJSONSerializable; +import com.genexus.security.GXSecurityProvider; +import com.genexus.security.web.SecureTokenHelper; +import com.genexus.security.web.WebSecurityHelper; + +public abstract class GXWebObjectBase extends GXObjectBase implements IErrorHandler, GXInternetConstants, ISubmitteable +{ + public static final ILogger logger = LogManager.getLogger(GXWebObjectBase.class); + + private static String GX_SPA_GXOBJECT_RESPONSE_HEADER = "X-GXOBJECT"; + protected static String GX_SPA_MASTERPAGE_HEADER = "X-SPA-MP"; + protected static String GX_AJAX_MULTIPART_ID = "GXAjaxMultipart"; + + protected boolean IntegratedSecurityEnabled() { return false;} + protected int IntegratedSecurityLevel() { return 0;} + protected String IntegratedSecurityPermissionPrefix() {return "";} + + protected static final int SECURITY_GXOBJECT = 3; + protected static final int SECURITY_HIGH = 2; + protected static final int SECURITY_LOW = 1; + + public abstract void webExecute(); + public abstract boolean isMasterPage(); + + public Object getParm( Object[] parms, int index) + { + return parms[index]; + } + + public GXWebObjectBase() + { + } + + /** + * Este constructor se usa cuando aun no tengo un ModelContext ni remoteHandle, pero + * si tengo el HttpContext. Basicamente es el punto de entrada en los servlets. + */ + public GXWebObjectBase(HttpContext httpContext, Class contextClass) + { + init(httpContext, contextClass); + } + + /** + * Este constructor se usa cuando aun no tengo un ModelContext ni remoteHandle, pero + * si tengo el HttpContext. Basicamente es el punto de entrada en los servlets. + */ + public GXWebObjectBase(HttpContext httpContext) + { + super(httpContext); + } + + /** + * Este constructor se usa cuando ya tengo un ModelContext y remoteHandle. + * Basicamente es el punto de entrada para webcomponents, webwrappers, etc. + */ + public GXWebObjectBase(int remoteHandle, ModelContext context) + { + super(remoteHandle, context); + } + + /*** + * Return the DefaultTheme for all WebPanels and Transactions. + * @return + */ + @SuppressWarnings("unused") + protected void initializeTheme() { + this.httpContext.setDefaultTheme(ConfigurationManager.getValue("Theme")); + } + + protected boolean CheckCmpSecurityAccess() + { + boolean[] flag = new boolean[]{false}; + boolean[] permissionFlag = new boolean[]{false}; + String permissionPrefix = IntegratedSecurityPermissionPrefix(); + com.genexus.internet.HttpRequest req = ((HttpContext)ModelContext.getModelContext().getHttpContext()).getHttpRequest(); + if (req == null) + return false; + String reqUrl = req.getRequestURL(); + ModelContext modelContext = ModelContext.getModelContext(getClass()); + if (IntegratedSecurityLevel() == SECURITY_LOW || IntegratedSecurityLevel() == SECURITY_GXOBJECT) + { + GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, permissionFlag); + } + if (IntegratedSecurityLevel() != SECURITY_LOW && IntegratedSecurityLevel() != SECURITY_GXOBJECT) + { + GXSecurityProvider.getInstance().checksessionprm(-2, modelContext, reqUrl, permissionPrefix, flag, permissionFlag); + } + return permissionFlag[0]; + } + + protected void sendCacheHeaders() + { + if (httpContext.isSpaRequest()) { + httpContext.getResponse().setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + httpContext.getResponse().setHeader("Pragma", "no-cache"); + httpContext.getResponse().setHeader("Expires", "0"); + } + else { + super.sendCacheHeaders(); + } + } + + protected void sendAdditionalHeaders() + { + if (httpContext.isSpaRequest()) + sendSpaHeaders(); + if (httpContext.getBrowserType() == HttpContext.BROWSER_IE && !httpContext.isPopUpObject()) + { + String IECompMode = context.getClientPreferences().getIE_COMPATIBILITY(); + if (IECompMode.equals("EmulateIE7") && !httpContext.getBrowserVersion().startsWith("8") ) + return; + if (StringUtils.isNotEmpty(IECompMode)) + httpContext.getResponse().addHeader("X-UA-Compatible", "IE=" + IECompMode); + } + } + + protected void sendSpaHeaders() + { + httpContext.getResponse().setHeader(GX_SPA_GXOBJECT_RESPONSE_HEADER, getPgmname().toLowerCase()); + } + + public void doExecute() throws Exception + { + try + { + if (isSpaRequest() && !isSpaSupported()) + { + httpContext.sendResponseStatus(httpContext.SPA_NOT_SUPPORTED_STATUS_CODE, "SPA not supported by the object"); + } + else + { + preExecute(); + sendCacheHeaders(); + webExecute(); + sendAdditionalHeaders(); + httpContext.flushStream(); + } + } + catch (Throwable e) + { + cleanup(); // Antes de hacer el rethrow, hago un cleanup del objeto + throw e; + } + finally + { + finallyCleanup(); + } + } + + public void executeUsercontrolMethod(String CmpContext, boolean IsMasterPage, String containerName, String methodName, String input, Object[] parms) + { + httpContext.executeUsercontrolMethod(CmpContext, IsMasterPage, containerName, methodName, input, parms); + } + + public void setExternalObjectProperty(String CmpContext, boolean IsMasterPage, String containerName, String propertyName, Object value) + { + httpContext.setExternalObjectProperty(CmpContext, IsMasterPage, containerName, propertyName, value); + } + + public void executeExternalObjectMethod(String CmpContext, boolean IsMasterPage, String containerName, String methodName, Object[] parms, boolean isEvent) + { + httpContext.executeExternalObjectMethod(CmpContext, IsMasterPage, containerName, methodName, parms, isEvent); + } + + /** + * @Hack: Tenemos que ejecutar el submit esto en otro thread, pues el submit es asincrono, + * pero si creamos en el fuente generado el codigo del nuevo thread, se va a crear un + * archivo nuevo xxx$N.class al compilar el xxx, que deberia ser tratado especialmente + * en el makefile (copiado al directorio de servlets, etc); asi que delegamos la + * creacion del thread a la gxclassr donde se llama al metodo a ser ejecutado + * Adem�s ahora manejamos un pool de threads en el submit + */ + public void callSubmit(final int id, Object [] submitParms) + { + com.genexus.util.SubmitThreadPool.submit(this, id, submitParms, context.submitCopy()); + } + + /** Este metodo es redefinido por la clase GX generada cuando hay submits + */ + public void submit(int id, Object [] submitParms, ModelContext ctx){ + } + public void submit(int id, Object [] submitParms){ + } + public void submitReorg(int id, Object [] submitParms) throws SQLException{ + } + + protected String formatLink(String jumpURL) + { + return formatLink(jumpURL, new String[]{}); + } + + protected String formatLink(String jumpURL, String[] parms) + { + return formatLink(jumpURL, parms, new String[]{}); + } + + protected String formatLink(String jumpURL, String[] parms, String[] parmsName) + { + return URLRouter.getURLRoute(jumpURL, parms, parmsName, httpContext.getRequest().getContextPath(), context.getPackageName()); + } + + public String getPgmname() + { + return ""; + } + + public String getPgmdesc() + { + return ""; + } + + protected boolean isSpaRequest() + { + return httpContext.isSpaRequest(); + } + + protected boolean isSpaRequest(boolean ignoreFlag) + { + return httpContext.isSpaRequest(ignoreFlag); + } + + protected boolean isSpaSupported() + { + return true; + } + + + protected void validateSpaRequest() + { + // SPA is disabled for objects without master page. However, SPA response headers are sent anyway, so the client side + // replaces the full content using AJAX. + if (isSpaRequest()) + { + httpContext.disableSpaRequest(); + sendSpaHeaders(); + } + } + + + private static String GX_SEC_TOKEN_PREFIX = "GX_AUTH"; + + //Generates only with FullAjax and GAM disabled. + public void sendSecurityToken(String cmpCtx) + { + if (this.httpContext.wjLoc == null || this.httpContext.wjLoc.equals("") ) + { + this.httpContext.ajax_rsp_assign_hidden(getSecurityObjTokenId(cmpCtx), getObjectAccessWebToken(cmpCtx)); + } + } + + private String getSecurityObjTokenId(String cmpCtx) + { + return GX_SEC_TOKEN_PREFIX + "_" + cmpCtx + getPgmname().toUpperCase(); + } + + protected String getPgmInstanceId(String cmpCtx) + { + return String.format("%s%s", cmpCtx, this.getPgmname().toUpperCase()); + } + + private String getObjectAccessWebToken(String cmpCtx) + { + return WebSecurityHelper.sign(getPgmInstanceId(cmpCtx), "", "", SecureTokenHelper.SecurityMode.Sign, getSecretKey()); + } + + private String getSecretKey() + { + //Some random SALT that is different in every GX App installation. Better if changes over time + String hashSalt = com.genexus.Application.getClientContext().getClientPreferences().getREORG_TIME_STAMP(); + return WebUtils.getEncryptionKey(this.context, "") + hashSalt; + } + + private String serialize(double Value, String Pic) + { + return serialize(localUtil.format(Value, Pic)); + } + + private String serialize(int Value, String Pic) + { + return serialize(localUtil.format(Value, Pic)); + } + + private String serialize(short Value, String Pic) + { + return serialize(localUtil.format(Value, Pic)); + } + + private String serialize(long Value, String Pic) + { + return serialize(localUtil.format(Value, Pic)); + } + + private String serialize(Object Value, String Pic) + { + if (!StringUtils.isBlank(Pic)) { + if (Value instanceof Byte) + { + return serialize(localUtil.format(((Byte)Value).intValue(), Pic)); + } + else + { + if (Value instanceof BigDecimal) + { + return serialize(localUtil.format((BigDecimal)Value, Pic)); + } + else + { + if (Value instanceof Integer) + { + return serialize(localUtil.format(((Integer)Value).intValue(), Pic)); + } + else + { + if (Value instanceof Short) + { + return serialize(localUtil.format(((Short)Value).shortValue(), Pic)); + } + else + { + if (Value instanceof Long) + { + return serialize(localUtil.format(((Long)Value).longValue(), Pic)); + } + else + { + if (Value instanceof Double) + { + return serialize(localUtil.format(((Double)Value).doubleValue(), Pic)); + } + else + { + if (Value instanceof Float) + { + return serialize(localUtil.format(((Float)Value).floatValue(), Pic)); + } + else + { + if (Value instanceof java.util.Date) + { + return serialize(localUtil.format((java.util.Date)Value, Pic)); + } + else + { + if (Value instanceof String) + { + return serialize(localUtil.format((String)Value, Pic)); + } + } + } + } + } + } + } + } + } + } + return serialize(Value); + } + + private String serialize(Object Value) { + String strValue = ""; + if (Value instanceof BigDecimal){ + strValue = Value.toString(); + if (strValue.indexOf(".") != -1) + strValue = strValue.replaceAll("0*$", "").replaceAll("\\.$", ""); + } + else{ + if (Value instanceof java.util.Date){ + strValue = " / / 00:00:00"; + if (!Value.equals(CommonUtil.resetTime( CommonUtil.nullDate()))) { + strValue = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Value); + } + } + else{ + if (Value instanceof com.genexus.xml.GXXMLSerializable) { + strValue = ((com.genexus.xml.GXXMLSerializable) Value).toJSonString(false); + } + else if (Value instanceof IGxJSONSerializable) { + strValue = ((IGxJSONSerializable) Value).toJSonString(); + } + else { + strValue = Value.toString(); + } + } + } + return strValue; + } + + protected String getSecureSignedToken(String cmpCtx, Object Value) + { + return getSecureSignedToken(cmpCtx, serialize(Value)); + } + + protected String getSecureSignedToken(String cmpCtx, boolean Value) + { + return getSecureSignedToken(cmpCtx, Boolean.toString(Value)); + } + + protected String getSecureSignedToken(String cmpCtx, com.genexus.xml.GXXMLSerializable Value) + { + return getSecureSignedToken(cmpCtx, Value.toJSonString(false)); + } + + protected String getSecureSignedToken(String cmpCtx, String Value) + { + return WebSecurityHelper.sign(getPgmInstanceId(cmpCtx), "", Value, SecureTokenHelper.SecurityMode.Sign, getSecretKey()); + } + + protected boolean verifySecureSignedToken(String cmpCtx, int Value, String picture, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, short Value, String picture, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, long Value, String picture, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, double Value, String picture, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, Object Value, String picture, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, Object Value, String token){ + return verifySecureSignedToken(cmpCtx, serialize(Value), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, boolean Value, String token){ + return verifySecureSignedToken(cmpCtx, Boolean.toString(Value), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, com.genexus.xml.GXXMLSerializable Value, String token){ + return verifySecureSignedToken(cmpCtx, Value.toJSonString(false), token); + } + + protected boolean verifySecureSignedToken(String cmpCtx, String value, String token){ + return WebSecurityHelper.verify(getPgmInstanceId(cmpCtx), "", value, token, getSecretKey()); + } + + protected boolean validateObjectAccess(String cmpCtx) + { + if (this.httpContext.useSecurityTokenValidation()){ + String jwtToken = this.httpContext.getHeader("X-GXAUTH-TOKEN"); + jwtToken = (StringUtils.isBlank(jwtToken) && this.httpContext.isMultipartContent())? + this.httpContext.cgiGet("X-GXAUTH-TOKEN"): + jwtToken; + + if (!verifySecureSignedToken(cmpCtx, "", jwtToken)) + { + this.httpContext.sendResponseStatus(401, "Not Authorized"); + if (this.httpContext.getBrowserType() != HttpContextWeb.BROWSER_INDEXBOT) { + logger.warn(String.format("Validation security token failed for program: %s - '%s'", getPgmInstanceId(cmpCtx), jwtToken )); + } + return false; + } + } + return true; + } + + private GXDebugInfo dbgInfo = null; + protected void trkCleanup() + { + if(dbgInfo != null) + dbgInfo.onCleanup(); + } + + protected void initialize(int objClass, int objId, int dbgLines, long hash) + { + dbgInfo = GXDebugManager.getInstance().getDbgInfo(context, objClass, objId, dbgLines, hash); + } + + protected void trk(int lineNro) + { + if(dbgInfo != null) + dbgInfo.trk(lineNro); + } + + protected void trk(int lineNro, int lineNro2) + { + if(dbgInfo != null) + dbgInfo.trk(lineNro, lineNro2); + } + + protected void trkrng(int lineNro, int lineNro2) + { + trkrng(lineNro, 0, lineNro2, 0); + } + + protected void trkrng(int lineNro, int colNro, int lineNro2, int colNro2) + { + if(dbgInfo != null) + dbgInfo.trkRng(lineNro, colNro, lineNro2, colNro2); + } + + protected void callWebObject(String url) + { + httpContext.wjLoc = url; + } + + + public void popup(String url) + { + } + + public void popup(String url, Object[] returnParms) + { + } +} diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index d0a89fbe7..ac45ca536 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -40,7 +40,7 @@ private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); - int nanoOfSecond = calendar.get(Calendar.MILLISECOND); + int nanoOfSecond = calendar.get(Calendar.MILLISECOND) * 1000000; zdt = ZonedDateTime.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond), tz.toZoneId()); } From 65437716beee3e590dd04403d633b983692179c8 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Mon, 24 Apr 2023 15:07:06 +0000 Subject: [PATCH 6/8] Revert "Remove joda time dependency" This reverts commit 503b57357f4aed63eeb8b0cd963367defafd25cb. --- .../genexus/webpanels/GXWebObjectBase.java | 529 ------------------ .../com/genexus/specific/java/GXutil.java | 2 +- 2 files changed, 1 insertion(+), 530 deletions(-) delete mode 100644 gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java diff --git a/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java b/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java deleted file mode 100644 index 58b9ebae9..000000000 --- a/gxweb/src/main/java/com/genexus/webpanels/GXWebObjectBase.java +++ /dev/null @@ -1,529 +0,0 @@ -package com.genexus.webpanels; - -import java.math.BigDecimal; -import java.sql.SQLException; - -import com.genexus.*; -import com.genexus.configuration.ConfigurationManager; -import com.genexus.diagnostics.GXDebugInfo; -import com.genexus.diagnostics.GXDebugManager; -import org.apache.commons.lang.StringUtils; - -import com.genexus.ModelContext; -import com.genexus.diagnostics.core.ILogger; -import com.genexus.diagnostics.core.LogManager; -import com.genexus.internet.GXInternetConstants; -import com.genexus.internet.HttpContext; -import com.genexus.internet.IGxJSONSerializable; -import com.genexus.security.GXSecurityProvider; -import com.genexus.security.web.SecureTokenHelper; -import com.genexus.security.web.WebSecurityHelper; - -public abstract class GXWebObjectBase extends GXObjectBase implements IErrorHandler, GXInternetConstants, ISubmitteable -{ - public static final ILogger logger = LogManager.getLogger(GXWebObjectBase.class); - - private static String GX_SPA_GXOBJECT_RESPONSE_HEADER = "X-GXOBJECT"; - protected static String GX_SPA_MASTERPAGE_HEADER = "X-SPA-MP"; - protected static String GX_AJAX_MULTIPART_ID = "GXAjaxMultipart"; - - protected boolean IntegratedSecurityEnabled() { return false;} - protected int IntegratedSecurityLevel() { return 0;} - protected String IntegratedSecurityPermissionPrefix() {return "";} - - protected static final int SECURITY_GXOBJECT = 3; - protected static final int SECURITY_HIGH = 2; - protected static final int SECURITY_LOW = 1; - - public abstract void webExecute(); - public abstract boolean isMasterPage(); - - public Object getParm( Object[] parms, int index) - { - return parms[index]; - } - - public GXWebObjectBase() - { - } - - /** - * Este constructor se usa cuando aun no tengo un ModelContext ni remoteHandle, pero - * si tengo el HttpContext. Basicamente es el punto de entrada en los servlets. - */ - public GXWebObjectBase(HttpContext httpContext, Class contextClass) - { - init(httpContext, contextClass); - } - - /** - * Este constructor se usa cuando aun no tengo un ModelContext ni remoteHandle, pero - * si tengo el HttpContext. Basicamente es el punto de entrada en los servlets. - */ - public GXWebObjectBase(HttpContext httpContext) - { - super(httpContext); - } - - /** - * Este constructor se usa cuando ya tengo un ModelContext y remoteHandle. - * Basicamente es el punto de entrada para webcomponents, webwrappers, etc. - */ - public GXWebObjectBase(int remoteHandle, ModelContext context) - { - super(remoteHandle, context); - } - - /*** - * Return the DefaultTheme for all WebPanels and Transactions. - * @return - */ - @SuppressWarnings("unused") - protected void initializeTheme() { - this.httpContext.setDefaultTheme(ConfigurationManager.getValue("Theme")); - } - - protected boolean CheckCmpSecurityAccess() - { - boolean[] flag = new boolean[]{false}; - boolean[] permissionFlag = new boolean[]{false}; - String permissionPrefix = IntegratedSecurityPermissionPrefix(); - com.genexus.internet.HttpRequest req = ((HttpContext)ModelContext.getModelContext().getHttpContext()).getHttpRequest(); - if (req == null) - return false; - String reqUrl = req.getRequestURL(); - ModelContext modelContext = ModelContext.getModelContext(getClass()); - if (IntegratedSecurityLevel() == SECURITY_LOW || IntegratedSecurityLevel() == SECURITY_GXOBJECT) - { - GXSecurityProvider.getInstance().checksession(-2, modelContext, reqUrl, permissionFlag); - } - if (IntegratedSecurityLevel() != SECURITY_LOW && IntegratedSecurityLevel() != SECURITY_GXOBJECT) - { - GXSecurityProvider.getInstance().checksessionprm(-2, modelContext, reqUrl, permissionPrefix, flag, permissionFlag); - } - return permissionFlag[0]; - } - - protected void sendCacheHeaders() - { - if (httpContext.isSpaRequest()) { - httpContext.getResponse().setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); - httpContext.getResponse().setHeader("Pragma", "no-cache"); - httpContext.getResponse().setHeader("Expires", "0"); - } - else { - super.sendCacheHeaders(); - } - } - - protected void sendAdditionalHeaders() - { - if (httpContext.isSpaRequest()) - sendSpaHeaders(); - if (httpContext.getBrowserType() == HttpContext.BROWSER_IE && !httpContext.isPopUpObject()) - { - String IECompMode = context.getClientPreferences().getIE_COMPATIBILITY(); - if (IECompMode.equals("EmulateIE7") && !httpContext.getBrowserVersion().startsWith("8") ) - return; - if (StringUtils.isNotEmpty(IECompMode)) - httpContext.getResponse().addHeader("X-UA-Compatible", "IE=" + IECompMode); - } - } - - protected void sendSpaHeaders() - { - httpContext.getResponse().setHeader(GX_SPA_GXOBJECT_RESPONSE_HEADER, getPgmname().toLowerCase()); - } - - public void doExecute() throws Exception - { - try - { - if (isSpaRequest() && !isSpaSupported()) - { - httpContext.sendResponseStatus(httpContext.SPA_NOT_SUPPORTED_STATUS_CODE, "SPA not supported by the object"); - } - else - { - preExecute(); - sendCacheHeaders(); - webExecute(); - sendAdditionalHeaders(); - httpContext.flushStream(); - } - } - catch (Throwable e) - { - cleanup(); // Antes de hacer el rethrow, hago un cleanup del objeto - throw e; - } - finally - { - finallyCleanup(); - } - } - - public void executeUsercontrolMethod(String CmpContext, boolean IsMasterPage, String containerName, String methodName, String input, Object[] parms) - { - httpContext.executeUsercontrolMethod(CmpContext, IsMasterPage, containerName, methodName, input, parms); - } - - public void setExternalObjectProperty(String CmpContext, boolean IsMasterPage, String containerName, String propertyName, Object value) - { - httpContext.setExternalObjectProperty(CmpContext, IsMasterPage, containerName, propertyName, value); - } - - public void executeExternalObjectMethod(String CmpContext, boolean IsMasterPage, String containerName, String methodName, Object[] parms, boolean isEvent) - { - httpContext.executeExternalObjectMethod(CmpContext, IsMasterPage, containerName, methodName, parms, isEvent); - } - - /** - * @Hack: Tenemos que ejecutar el submit esto en otro thread, pues el submit es asincrono, - * pero si creamos en el fuente generado el codigo del nuevo thread, se va a crear un - * archivo nuevo xxx$N.class al compilar el xxx, que deberia ser tratado especialmente - * en el makefile (copiado al directorio de servlets, etc); asi que delegamos la - * creacion del thread a la gxclassr donde se llama al metodo a ser ejecutado - * Adem�s ahora manejamos un pool de threads en el submit - */ - public void callSubmit(final int id, Object [] submitParms) - { - com.genexus.util.SubmitThreadPool.submit(this, id, submitParms, context.submitCopy()); - } - - /** Este metodo es redefinido por la clase GX generada cuando hay submits - */ - public void submit(int id, Object [] submitParms, ModelContext ctx){ - } - public void submit(int id, Object [] submitParms){ - } - public void submitReorg(int id, Object [] submitParms) throws SQLException{ - } - - protected String formatLink(String jumpURL) - { - return formatLink(jumpURL, new String[]{}); - } - - protected String formatLink(String jumpURL, String[] parms) - { - return formatLink(jumpURL, parms, new String[]{}); - } - - protected String formatLink(String jumpURL, String[] parms, String[] parmsName) - { - return URLRouter.getURLRoute(jumpURL, parms, parmsName, httpContext.getRequest().getContextPath(), context.getPackageName()); - } - - public String getPgmname() - { - return ""; - } - - public String getPgmdesc() - { - return ""; - } - - protected boolean isSpaRequest() - { - return httpContext.isSpaRequest(); - } - - protected boolean isSpaRequest(boolean ignoreFlag) - { - return httpContext.isSpaRequest(ignoreFlag); - } - - protected boolean isSpaSupported() - { - return true; - } - - - protected void validateSpaRequest() - { - // SPA is disabled for objects without master page. However, SPA response headers are sent anyway, so the client side - // replaces the full content using AJAX. - if (isSpaRequest()) - { - httpContext.disableSpaRequest(); - sendSpaHeaders(); - } - } - - - private static String GX_SEC_TOKEN_PREFIX = "GX_AUTH"; - - //Generates only with FullAjax and GAM disabled. - public void sendSecurityToken(String cmpCtx) - { - if (this.httpContext.wjLoc == null || this.httpContext.wjLoc.equals("") ) - { - this.httpContext.ajax_rsp_assign_hidden(getSecurityObjTokenId(cmpCtx), getObjectAccessWebToken(cmpCtx)); - } - } - - private String getSecurityObjTokenId(String cmpCtx) - { - return GX_SEC_TOKEN_PREFIX + "_" + cmpCtx + getPgmname().toUpperCase(); - } - - protected String getPgmInstanceId(String cmpCtx) - { - return String.format("%s%s", cmpCtx, this.getPgmname().toUpperCase()); - } - - private String getObjectAccessWebToken(String cmpCtx) - { - return WebSecurityHelper.sign(getPgmInstanceId(cmpCtx), "", "", SecureTokenHelper.SecurityMode.Sign, getSecretKey()); - } - - private String getSecretKey() - { - //Some random SALT that is different in every GX App installation. Better if changes over time - String hashSalt = com.genexus.Application.getClientContext().getClientPreferences().getREORG_TIME_STAMP(); - return WebUtils.getEncryptionKey(this.context, "") + hashSalt; - } - - private String serialize(double Value, String Pic) - { - return serialize(localUtil.format(Value, Pic)); - } - - private String serialize(int Value, String Pic) - { - return serialize(localUtil.format(Value, Pic)); - } - - private String serialize(short Value, String Pic) - { - return serialize(localUtil.format(Value, Pic)); - } - - private String serialize(long Value, String Pic) - { - return serialize(localUtil.format(Value, Pic)); - } - - private String serialize(Object Value, String Pic) - { - if (!StringUtils.isBlank(Pic)) { - if (Value instanceof Byte) - { - return serialize(localUtil.format(((Byte)Value).intValue(), Pic)); - } - else - { - if (Value instanceof BigDecimal) - { - return serialize(localUtil.format((BigDecimal)Value, Pic)); - } - else - { - if (Value instanceof Integer) - { - return serialize(localUtil.format(((Integer)Value).intValue(), Pic)); - } - else - { - if (Value instanceof Short) - { - return serialize(localUtil.format(((Short)Value).shortValue(), Pic)); - } - else - { - if (Value instanceof Long) - { - return serialize(localUtil.format(((Long)Value).longValue(), Pic)); - } - else - { - if (Value instanceof Double) - { - return serialize(localUtil.format(((Double)Value).doubleValue(), Pic)); - } - else - { - if (Value instanceof Float) - { - return serialize(localUtil.format(((Float)Value).floatValue(), Pic)); - } - else - { - if (Value instanceof java.util.Date) - { - return serialize(localUtil.format((java.util.Date)Value, Pic)); - } - else - { - if (Value instanceof String) - { - return serialize(localUtil.format((String)Value, Pic)); - } - } - } - } - } - } - } - } - } - } - return serialize(Value); - } - - private String serialize(Object Value) { - String strValue = ""; - if (Value instanceof BigDecimal){ - strValue = Value.toString(); - if (strValue.indexOf(".") != -1) - strValue = strValue.replaceAll("0*$", "").replaceAll("\\.$", ""); - } - else{ - if (Value instanceof java.util.Date){ - strValue = " / / 00:00:00"; - if (!Value.equals(CommonUtil.resetTime( CommonUtil.nullDate()))) { - strValue = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Value); - } - } - else{ - if (Value instanceof com.genexus.xml.GXXMLSerializable) { - strValue = ((com.genexus.xml.GXXMLSerializable) Value).toJSonString(false); - } - else if (Value instanceof IGxJSONSerializable) { - strValue = ((IGxJSONSerializable) Value).toJSonString(); - } - else { - strValue = Value.toString(); - } - } - } - return strValue; - } - - protected String getSecureSignedToken(String cmpCtx, Object Value) - { - return getSecureSignedToken(cmpCtx, serialize(Value)); - } - - protected String getSecureSignedToken(String cmpCtx, boolean Value) - { - return getSecureSignedToken(cmpCtx, Boolean.toString(Value)); - } - - protected String getSecureSignedToken(String cmpCtx, com.genexus.xml.GXXMLSerializable Value) - { - return getSecureSignedToken(cmpCtx, Value.toJSonString(false)); - } - - protected String getSecureSignedToken(String cmpCtx, String Value) - { - return WebSecurityHelper.sign(getPgmInstanceId(cmpCtx), "", Value, SecureTokenHelper.SecurityMode.Sign, getSecretKey()); - } - - protected boolean verifySecureSignedToken(String cmpCtx, int Value, String picture, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, short Value, String picture, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, long Value, String picture, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, double Value, String picture, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, Object Value, String picture, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value, picture), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, Object Value, String token){ - return verifySecureSignedToken(cmpCtx, serialize(Value), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, boolean Value, String token){ - return verifySecureSignedToken(cmpCtx, Boolean.toString(Value), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, com.genexus.xml.GXXMLSerializable Value, String token){ - return verifySecureSignedToken(cmpCtx, Value.toJSonString(false), token); - } - - protected boolean verifySecureSignedToken(String cmpCtx, String value, String token){ - return WebSecurityHelper.verify(getPgmInstanceId(cmpCtx), "", value, token, getSecretKey()); - } - - protected boolean validateObjectAccess(String cmpCtx) - { - if (this.httpContext.useSecurityTokenValidation()){ - String jwtToken = this.httpContext.getHeader("X-GXAUTH-TOKEN"); - jwtToken = (StringUtils.isBlank(jwtToken) && this.httpContext.isMultipartContent())? - this.httpContext.cgiGet("X-GXAUTH-TOKEN"): - jwtToken; - - if (!verifySecureSignedToken(cmpCtx, "", jwtToken)) - { - this.httpContext.sendResponseStatus(401, "Not Authorized"); - if (this.httpContext.getBrowserType() != HttpContextWeb.BROWSER_INDEXBOT) { - logger.warn(String.format("Validation security token failed for program: %s - '%s'", getPgmInstanceId(cmpCtx), jwtToken )); - } - return false; - } - } - return true; - } - - private GXDebugInfo dbgInfo = null; - protected void trkCleanup() - { - if(dbgInfo != null) - dbgInfo.onCleanup(); - } - - protected void initialize(int objClass, int objId, int dbgLines, long hash) - { - dbgInfo = GXDebugManager.getInstance().getDbgInfo(context, objClass, objId, dbgLines, hash); - } - - protected void trk(int lineNro) - { - if(dbgInfo != null) - dbgInfo.trk(lineNro); - } - - protected void trk(int lineNro, int lineNro2) - { - if(dbgInfo != null) - dbgInfo.trk(lineNro, lineNro2); - } - - protected void trkrng(int lineNro, int lineNro2) - { - trkrng(lineNro, 0, lineNro2, 0); - } - - protected void trkrng(int lineNro, int colNro, int lineNro2, int colNro2) - { - if(dbgInfo != null) - dbgInfo.trkRng(lineNro, colNro, lineNro2, colNro2); - } - - protected void callWebObject(String url) - { - httpContext.wjLoc = url; - } - - - public void popup(String url) - { - } - - public void popup(String url, Object[] returnParms) - { - } -} diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index ac45ca536..d0a89fbe7 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -40,7 +40,7 @@ private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); - int nanoOfSecond = calendar.get(Calendar.MILLISECOND) * 1000000; + int nanoOfSecond = calendar.get(Calendar.MILLISECOND); zdt = ZonedDateTime.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond), tz.toZoneId()); } From ffe3417cdb15c7c9a911b1b34ef33b7af39a214e Mon Sep 17 00:00:00 2001 From: iroqueta Date: Mon, 24 Apr 2023 15:25:43 +0000 Subject: [PATCH 7/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- java/src/main/java/com/genexus/specific/java/GXutil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index d0a89fbe7..ac45ca536 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -40,7 +40,7 @@ private ZonedDateTime getZonedDateTime(Date value, TimeZone tz){ int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); - int nanoOfSecond = calendar.get(Calendar.MILLISECOND); + int nanoOfSecond = calendar.get(Calendar.MILLISECOND) * 1000000; zdt = ZonedDateTime.of(LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond), tz.toZoneId()); } From 789b85fe63cb04dcacddeb3b12ea99572cfeabe3 Mon Sep 17 00:00:00 2001 From: iroqueta Date: Wed, 26 Apr 2023 13:18:10 -0300 Subject: [PATCH 8/8] Remove joda time dependency In order to convert dates to UTC dates and UTC dates to dates, remove joda time dependency and use JDK 8 ZonedDateTime data type. Issue:102003 --- java/src/main/java/com/genexus/specific/java/GXutil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java/src/main/java/com/genexus/specific/java/GXutil.java b/java/src/main/java/com/genexus/specific/java/GXutil.java index ac45ca536..83a63dad1 100644 --- a/java/src/main/java/com/genexus/specific/java/GXutil.java +++ b/java/src/main/java/com/genexus/specific/java/GXutil.java @@ -57,7 +57,8 @@ public Date DateTimeToUTC(Date value, TimeZone tz) { return value; ZonedDateTime zdt = getZonedDateTime(value, tz); - return Timestamp.valueOf(zdt.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()); + Timestamp t = Timestamp.valueOf(zdt.withZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()); + return new Date(t.getTime()); } @Override @@ -69,7 +70,8 @@ public Date DateTimeFromUTC(Date value, TimeZone tz) { return value; ZonedDateTime zdtUTC = getZonedDateTime(value, TimeZone.getTimeZone("UTC")); - return Timestamp.valueOf(zdtUTC.withZoneSameInstant(ZoneId.of(tz.getID())).toLocalDateTime()); + Timestamp t = Timestamp.valueOf(zdtUTC.withZoneSameInstant(ZoneId.of(tz.getID())).toLocalDateTime()); + return new Date(t.getTime()); } @Override