Marcus Tornberg

Admiral
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-09
09:44
389 views
ECMA script error
Hi all.
I have a customer that is running an HR-system using Service Bus for
Windows Server. I need to retrieve updates from this HR-system using
REST.
To authenticate I need to send a SAS token as an Authorization header.
To generate the SAS token I have created a ECMA-script seen below. I
call the function using
getToken('https://fake.url.org','secretkey','username');
When I call the function using Designer it works well. However when I
try to run it on the engine I get an error message. What could be the
cause for this issue on the engine side? Does anyone have any idea what
could be done to fix it?
The response should be similar to:
Code:
--------------------
SharedAccessSignature sr=https%3a%2f%2ffake.url.org&sig=lCXLvuP%2fbek0vRpPYiCWXXe%2brcGt8h4nGvmYaJtGgqc%3d&se=1441794669&skn=username
--------------------
Error message on the engine:
Code:
--------------------
DirXML Log Event -------------------
Driver: \DEV-TREE\idm\system\Driver Set\ECMA
Channel: Subscriber
Status: Error
Message: Code(-9083) Error submitting event to subscriber: Code(-9010) An exception occurred: java.lang.NoSuchMethodError: com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.thisGet(Lcom/novell/soa/script/mozilla/javascript/Scriptable;Ljava/lang/String;Lcom/novell/soa/script/mozilla/javascript/Scriptable;)Ljava/lang/Object;
at com.novell.soa.script.mozilla.javascript.gen.c9._c13(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:152)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call1(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c24(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:221)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call1(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c29(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:257)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call1(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c45(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:375)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.callProp0(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c44(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:370)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.ScriptRuntime.applyOrCall(Unknown Source)
at com.novell.soa.script.mozilla.javascript.BaseFunction.execIdCall(Unknown Source)
at com.novell.soa.script.mozilla.javascript.IdFunctionObject.call(Unknown Source)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call2(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c7(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:114)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call2(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c35(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:279)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.optimizer.OptRuntime.call2(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9._c1(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:12)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.soa.script.mozilla.javascript.ScriptRuntime.doTopCall(Unknown Source)
at com.novell.soa.script.mozilla.javascript.gen.c9.call(vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data)
at com.novell.xsl.extensions.ECMAScriptFunctionImpl.invoke(ECMAScriptFunctionImpl.java:108)
at com.novell.xml.xpath.FunctionCall.evaluate(FunctionCall.java:90)
at com.novell.xml.dom.DOMEvaluator.evaluate(DOMEvaluator.java:89)
at com.novell.nds.dirxml.engine.rules.RuleDynamicContext.evaluateXPath(RuleDynamicContext.java:165)
at com.novell.nds.dirxml.engine.rules.TokenXPath.expand(TokenXPath.java:72)
at com.novell.nds.dirxml.engine.rules.Arg.evaluate(Arg.java:460)
at com.novell.nds.dirxml.engine.rules.DoSetLocalVariable.apply(DoSetLocalVariable.java:100)
at com.novell.nds.dirxml.engine.rules.ActionSet.apply(ActionSet.java:180)
at com.novell.nds.dirxml.engine.rules.DirXMLScriptProcessor.applyRules(DirXMLScriptProcessor.java:307)
at com.novell.nds.dirxml.engine.Subscriber.processEvents(Subscriber.java:902)
at com.novell.nds.dirxml.engine.Driver.submitTransaction(Driver.java:628)
at com.novell.nds.dirxml.engine.DriverEntry.submitTransaction(DriverEntry.java:1065)
at com.novell.nds.dirxml.engine.DriverEntry.processCachedTransaction(DriverEntry.java:949)
at com.novell.nds.dirxml.engine.DriverEntry.eventLoop(DriverEntry.java:771)
at com.novell.nds.dirxml.engine.DriverEntry.run(DriverEntry.java:561)
at java.lang.Thread.run(Unknown Source)
--------------------
I have uploaded the ECMA-script to pastebin:
http://pastebin.com/V7TG3t44
Any help is greatly appriciated!
Best Regards
Marcus
--
marcus_jonsson
------------------------------------------------------------------------
marcus_jonsson's Profile: https://forums.netiq.com/member.php?userid=1157
View this thread: https://forums.netiq.com/showthread.php?t=54258
5 Replies


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-09
13:39
marcus jonsson wrote:
> vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:152
The error occurs at this line in your script.
As for the actual reason, not so clear.
What is the patch version of the engine vs Designer?
> vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:152
The error occurs at this line in your script.
As for the actual reason, not so clear.
What is the patch version of the engine vs Designer?
Alex McHugh - Knowledge Partner - Stavanger, Norway
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-09
14:25
On 9/9/2015 8:39 AM, Alex McHugh wrote:
> marcus jonsson wrote:
>
>> vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:152
>
> The error occurs at this line in your script.
>
> As for the actual reason, not so clear.
>
>
> What is the patch version of the engine vs Designer?
Some JAR that Designer has and engine does not, is relied on, you have a
Class Not Found error.
> marcus jonsson wrote:
>
>> vnd.nds.stream://DEV-TREE/idm/system/Driver+Set/ECMA/SAS-token2#DirXML-Data:152
>
> The error occurs at this line in your script.
>
> As for the actual reason, not so clear.
>
>
> What is the patch version of the engine vs Designer?
Some JAR that Designer has and engine does not, is relied on, you have a
Class Not Found error.


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-09
15:07
Geoffrey Carman <geoffreycarmanNOSPAM@NOSPAMgmail.com> wrote:
> Some JAR that Designer has and engine does not, is relied on, you have a
> Class Not Found error.
I think it is that there needs to be a bit more explicit type conversion.
The optimizer is choking due to this.
--
If you find this post helpful and are logged into the web interface, show
your appreciation and click on the star below...
> Some JAR that Designer has and engine does not, is relied on, you have a
> Class Not Found error.
I think it is that there needs to be a bit more explicit type conversion.
The optimizer is choking due to this.
--
If you find this post helpful and are logged into the web interface, show
your appreciation and click on the star below...
Alex McHugh - Knowledge Partner - Stavanger, Norway
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.
Marcus Tornberg

Admiral
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-11
08:44
Hi.
Thanks for your replies.
I'm sure you are on the right track. However I got help from a colleague
in rewriting the script, and now I have a version that works with the
engine. I won’t pursue cause of the original problem I posted.
I will share the code used now in case anyone else needs to generate a
SAS token for Service Bus for Windows (I think the same applies to Azure
as well).
Code:
--------------------
importPackage(java.io);
importPackage(java.net);
importPackage(java.util);
importPackage(java.math);
importPackage(Packages.javax.crypto.spec);
importPackage(Packages.javax.crypto);
importPackage(Packages.javax.xml.bind);
importPackage(Packages.org.w3c.dom);
importClass(Packages.com.novell.xml.util.Base64Codec);
importClass(Packages.com.novell.nds.dirxml.driver.XmlDocument);
importClass(Packages.com.novell.xml.dom.DOMWriter);
importClass(java.util.GregorianCalendar);
importClass(java.text.DateFormat);
importClass(java.text.SimpleDateFormat);
importClass(java.lang.System);
importClass(java.lang.Integer);
function getToken2(resourceUri, keyName, key) {
var token = "";
try {
var targetUri = URLEncoder.encode(resourceUri.toLowerCase(), "UTF-8").toLowerCase();
var currentTime = new Date();
var expiration = Math.round((currentTime.getTime() + 300000) / 1000);
var expAsString = new java.lang.String(expiration);
var signature = targetUri + "\n" + expiration;
var keyJ = new java.lang.String(key);
var signingKey = new SecretKeySpec(keyJ.getBytes(), "HmacSHA256");
var mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
var signatureJ = new java.lang.String(signature);
var rawHmac = mac.doFinal(signatureJ.getBytes());
var hmac = URLEncoder.encode(DatatypeConverter.printBase64Binary(rawHmac), "UTF-8");
var array = java.lang.reflect.Array.newInstance(java.lang.Object, 4);
array[0] = targetUri;
array[1] = hmac;
array[2] = expAsString;
array[3] = keyName;
var sasToken = java.lang.String.format("SharedAccessSignature sr=%s&sig=%s&se=%s&skn=%s", array);
token = sasToken;
} catch (e) {
token = "Token generation failed: " + e + "\n";
if (e.javaException != null) {
var stacktrace = e.javaException.getStackTrace();
for (var i = 0; i < stacktrace.length; i++) {
token = token + stacktrace + "\n";
}
}
}
return token;
}
--------------------
--
marcus_jonsson
------------------------------------------------------------------------
marcus_jonsson's Profile: https://forums.netiq.com/member.php?userid=1157
View this thread: https://forums.netiq.com/showthread.php?t=54258


Knowledge Partner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-09-11
12:29
marcus jonsson wrote:
>
> Hi.
>
> Thanks for your replies.
>
> I'm sure you are on the right track. However I got help from a colleague
> in rewriting the script, and now I have a version that works with the
> engine. I won�t pursue cause of the original problem I posted.
>
> I will share the code used now in case anyone else needs to generate a
> SAS token for Service Bus for Windows (I think the same applies to Azure
> as well).
Thanks for sharing. This version seems far shorter and simpler than the other one.
>
> Hi.
>
> Thanks for your replies.
>
> I'm sure you are on the right track. However I got help from a colleague
> in rewriting the script, and now I have a version that works with the
> engine. I won�t pursue cause of the original problem I posted.
>
> I will share the code used now in case anyone else needs to generate a
> SAS token for Service Bus for Windows (I think the same applies to Azure
> as well).
Thanks for sharing. This version seems far shorter and simpler than the other one.
Alex McHugh - Knowledge Partner - Stavanger, Norway
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.