From ffab507e6ed4c8d84057d0f2b31f57932b1bac9b Mon Sep 17 00:00:00 2001 From: shanggeeth Date: Fri, 5 Jan 2024 17:02:29 +0530 Subject: [PATCH] Fix following bugs: * Fix serializing not working for array objects * Fix callback function not working * Fix interpreter warning being displayed --- .../graaljs/GraalSerializableJsFunction.java | 2 +- .../model/graph/graaljs/GraalSerializer.java | 30 +++++++------------ .../graaljs/JsGraalGraphBuilderFactory.java | 1 + 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializableJsFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializableJsFunction.java index c99a129cabef..08712285834a 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializableJsFunction.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializableJsFunction.java @@ -67,7 +67,7 @@ public void setSource(String source) { @Override public boolean isFunction() { - return isHostFunction; + return isPolyglotFunction; } @Override diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializer.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializer.java index 0b20b4a3bf87..119ed7cfe2b1 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializer.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/GraalSerializer.java @@ -74,20 +74,21 @@ public static Object toJsSerializableInternal(Object value) { return valueObj.asDate(); } else if (valueObj.isBoolean()) { return valueObj.asBoolean(); + } else if (valueObj.isDuration()) { + return valueObj.asDuration(); + } else if (valueObj.isTime()) { + return valueObj.asTime(); + } else if (valueObj.isTimeZone()) { + return valueObj.asTimeZone(); + } else if (valueObj.isNull()) { + return null; } else if (valueObj.hasArrayElements()) { int arraySize = (int) valueObj.getArraySize(); List arrayItems = new ArrayList<>(arraySize); for (int key = 0; key < arraySize; key++) { - Object serializedObj = (valueObj.getArrayElement(key)); - if (serializedObj instanceof Serializable) { - arrayItems.add((Serializable) serializedObj); - if (log.isDebugEnabled()) { - log.debug("Serialized the value of array item as : " + serializedObj); - } - } else { - log.warn(String.format("Non serializable array item: %s. and will not be persisted.", - serializedObj)); - } + Object arrayObj = valueObj.getArrayElement(key); + Object serializedObj = toJsSerializableInternal(arrayObj); + arrayItems.add((Serializable) serializedObj); } return arrayItems; } else if (valueObj.hasMembers()) { @@ -105,20 +106,11 @@ public static Object toJsSerializableInternal(Object value) { } }); return serializedMap; - } else if (valueObj.isDuration()) { - return valueObj.asDuration(); - } else if (valueObj.isTime()) { - return valueObj.asTime(); - } else if (valueObj.isTimeZone()) { - return valueObj.asTimeZone(); - } else if (valueObj.isNull()) { - return null; } else { return Collections.EMPTY_MAP; } } return value; - } @Override diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/JsGraalGraphBuilderFactory.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/JsGraalGraphBuilderFactory.java index 2a501a67b193..23445941e4e3 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/JsGraalGraphBuilderFactory.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/graaljs/JsGraalGraphBuilderFactory.java @@ -77,6 +77,7 @@ public Context createEngine(AuthenticationContext authenticationContext) { Context context = Context.newBuilder(FrameworkConstants.JSAttributes.POLYGLOT_LANGUAGE).allowHostAccess(HostAccess.ALL) + .option("engine.WarnInterpreterOnly", "false") .build(); Value bindings = context.getBindings(FrameworkConstants.JSAttributes.POLYGLOT_LANGUAGE);