anonymous classes and NetRexx

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

anonymous classes and NetRexx

Marc Remes-2
How would one translate the following Java fragment with an anonymous class to NetRexx?

//
        final char[] pswd;
        pswd = pass.toCharArray();
        final String Userid = username;

        Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication (Userid, pswd);
                }
        });
//

Thanks
Marc

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes and NetRexx

alansam
Something like this should work:


  protected char[] pswd;
  protected String Userid;

  void auth(String username, String pass) {

    pswd = pass.toCharArray();
    Userid = username;
  
    Authenticator.setDefault(new MyAuthenticator());

    return;
  }

  private class MyAuthenticator extends Authenticator {
    protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(Userid, pswd);
    }
  }


A.

On 21 June 2012 15:16, Marc Remes <[hidden email]> wrote:
How would one translate the following Java fragment with an anonymous class to NetRexx?

//
       final char[] pswd;
       pswd = pass.toCharArray();
       final String Userid = username;

       Authenticator.setDefault(new Authenticator() {
               protected PasswordAuthentication getPasswordAuthentication() {
                       return new PasswordAuthentication (Userid, pswd);
               }
       });
//

Thanks
Marc

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes and NetRexx

Marc Remes-2

Interesting..
Which magic invokes the getPasswordAuthentication method?

Marc

On 06/22/2012 01:15 AM, Alan Sampson wrote:

> Something like this should work:
>
>
>
>  protected char[] pswd;
>  protected String Userid;
>
>
>  void auth(String username, String pass) {
>
>
>    pswd = pass.toCharArray();
>    Userid = username;
>
>    Authenticator.setDefault(new MyAuthenticator());
>
>
>    return;
>  }
>
>
>   private class MyAuthenticator extends Authenticator {
>     protected PasswordAuthentication getPasswordAuthentication() {
>       return new PasswordAuthentication(Userid, pswd);
>     }
>   }
>
>
>
> A.
>
> On 21 June 2012 15:16, Marc Remes <[hidden email] <mailto:[hidden email]>> wrote:
>
>     How would one translate the following Java fragment with an anonymous class to NetRexx?
>
>     //
>             final char[] pswd;
>             pswd = pass.toCharArray();
>             final String Userid = username;
>
>             Authenticator.setDefault(new Authenticator() {
>                     protected PasswordAuthentication getPasswordAuthentication() {
>                             return new PasswordAuthentication (Userid, pswd);
>                     }
>             });
>     //
>
>     Thanks
>     Marc
>
>     _________________________________________________
>     Ibm-netrexx mailing list
>     [hidden email] <mailto:[hidden email]>
>     Online Archive : http://ibm-netrexx.215625.n3.__nabble.com/ <http://ibm-netrexx.215625.n3.nabble.com/>
>
>
>
>
> --
> Can't tweet, won't tweet!
>
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: anonymous classes and NetRexx

alansam


On 21 June 2012 16:44, Marc Remes <[hidden email]> wrote:

Interesting..
Which magic invokes the getPasswordAuthentication method?

Marc


On 06/22/2012 01:15 AM, Alan Sampson wrote:
Something like this should work:



 protected char[] pswd;
 protected String Userid;


 void auth(String username, String pass) {


  pswd = pass.toCharArray();
  Userid = username;

  Authenticator.setDefault(new MyAuthenticator());


  return;
 }


 private class MyAuthenticator extends Authenticator {
   protected PasswordAuthentication getPasswordAuthentication() {
     return new PasswordAuthentication(Userid, pswd);
   }
 }




I haven't investigated this corner of Java but I suspect that when the JVM tries authenticating using your class it will use your getPasswordAuthentication() method.  All you're doing here is defining a call-back and telling the JVM's current Authenticator what it's default Authenticator object is via the setDefault() call.  Note too that getPasswordAuthentication() is a protected method so it can only be called polymorhically or from instances of the inner class and/or it's children.

A.

--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.