Overriding java methods in Igntion scripts

I need to do a http get to download files on a server that is using authentication so I am trying to use the setDefaultAuthenticator method of java.net.Authneticator. To do this I will need to override the getPasswordAuthentication method of the Authenticator class.

My problem is that I have no idea of how to do that in script. Can anyone provide a simple example of overriding a method using scripting within Ignition?

This seems to have done the trick:

username = "someuser"
password = "apassword"

class MyAuthenticator(Authenticator):
    def getPasswordAuthentication():
        return PasswordAuthentication(username, password.toCharArray())

m = MyAuthenticator()

The way to override a method apparently is to subclass the existing class with the original method in it; add a method to your subclass with the name of the method that you want to override. And then of course instantiate an instance of your subclass.

Yep, you’ve got it. :thumb_left: