early exit from Nashorn script?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

early exit from Nashorn script?

Jim Fox

Every Nashorn script I've seen ends with its return value, e.g.,
"nextFlow;" in mfa scripts.  Is there a way to exit with a value in the
middle of the script?

e.g.

   # I know user cannot complete the login
   exit("authn/you-are-toast");


Jim
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Joshua Brodie
From java -- a  guess:

break;


On Mon, 27 Jan 2020 at 16:00, Jim Fox <[hidden email]> wrote:

Every Nashorn script I've seen ends with its return value, e.g.,
"nextFlow;" in mfa scripts.  Is there a way to exit with a value in the
middle of the script?

e.g.

   # I know user cannot complete the login
   exit("authn/you-are-toast");


Jim
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]

--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Cantor, Scott E.
In reply to this post by Jim Fox
On 1/27/20, 7:00 PM, "users on behalf of Jim Fox" <[hidden email] on behalf of [hidden email]> wrote:

> Every Nashorn script I've seen ends with its return value, e.g.,
> "nextFlow;" in mfa scripts.  Is there a way to exit with a value in the
> middle of the script?

It seems inconceivable, but I'm not aware of any in any of the Javascript engines.

-- Scott


--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: early exit from Nashorn script?

Lipscomb, Gary
In reply to this post by Jim Fox
Maybe this

exit and quit functions[1]

These synonymous functions exit the current process with specified (optional) exit code.
exit
exit(1); // exit with given exit code
exit();  // exit 0
 
quit(2); // exit with given exit code
quit();  // exit 0

[1] https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions

-----Original Message-----
From: users [mailto:[hidden email]] On Behalf Of Cantor, Scott
Sent: Tuesday, 28 January 2020 12:07
To: Shib Users <[hidden email]>
Subject: Re: early exit from Nashorn script?

On 1/27/20, 7:00 PM, "users on behalf of Jim Fox" <[hidden email] on behalf of [hidden email]> wrote:

> Every Nashorn script I've seen ends with its return value, e.g.,
> "nextFlow;" in mfa scripts.  Is there a way to exit with a value in the
> middle of the script?

It seems inconceivable, but I'm not aware of any in any of the Javascript engines.

-- Scott


--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Cantor, Scott E.
I think what might work is inlining a function declaration that uses return statements inside itself, and then making the script itself end with my_fn(input, custom)

-- Scott


--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: early exit from Nashorn script?

Rod Widdowson
> I think what might work is inlining a function declaration that uses return statements inside itself, and then making the script
itself end
> with my_fn(input, custom)

This is the solution I have seen used most often.



--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Tom Scavo
In reply to this post by Jim Fox
On Mon, Jan 27, 2020 at 7:00 PM Jim Fox <[hidden email]> wrote:
>
> Every Nashorn script I've seen ends with its return value, e.g.,
> "nextFlow;" in mfa scripts.  Is there a way to exit with a value in the
> middle of the script?
>
> e.g.
>
>    # I know user cannot complete the login
>    exit("authn/you-are-toast");

This is a dev question but...

JavaScript embraces multiple styles of programming (which is both a
blessing and a curse). In this case, you probably want to adopt the
functional style and write a self-executing anonymous function [1]
whose inputs are the inputs to the script. A JavaScript function may
have multiple return statements so you can short-circuit function
execution under various conditions as desired.

There are examples of self-executing anonymous functions in the wiki.

Cheers,

Tom

[1] http://markdalgleish.com/2011/03/self-executing-anonymous-functions/
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Jim Fox

Thanks for the suggestion. It seems obvious once it's been pointed out.

>
> This is a dev question but...
>

Have to take issue with that.  This is about configuring the MFA login
flow.

Thanks again,

Jim
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: early exit from Nashorn script?

Mak, Steve
Jim,

Taking a step back, if the scope of this question is purely "How to do I exit MFA script properly?"

The rules of the MFA script dictate that you exit an MFA subscript with one of two options: "name of the next flow to execute" or null.

If you want to "do something", you can either make the script log a line using built in logger, call some custom authn/foo flow you created, call some built-in authn/flow, or exit with null.


I've achieved the conditional nextFlow returns using regular JavaScript if blocks.  I set a sensible default of nextFlow = null, then using JS conditions I check a few things that will result in nextFlow being set to my 2FA authn/flow.  It always returns nextFlow, either null or 2FA.

Maybe this helps you?

- Steve

On 1/28/20, 12:36, "users on behalf of Jim Fox" <[hidden email] on behalf of [hidden email]> wrote:


Thanks for the suggestion. It seems obvious once it's been pointed out.

>
> This is a dev question but...
>

Have to take issue with that.  This is about configuring the MFA login
flow.

Thanks again,

Jim
--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]

--
For Consortium Member technical support, see https://wiki.shibboleth.net/confluence/x/coFAAg
To unsubscribe from this list send an email to [hidden email]