4

trying to get a NTLM connection but my jython is not proficient enough to translate Authenticator part of the code. what information do i need to accomplish this? if this is even possible to do in jython.

from java.net import Authenticator
from java.net import PasswordAuthentication
from java.net import URL
from java.net import HttpURLConnection
from java.lang import StringBuilder
from java.io import InputStream, BufferedReader
from java.io import InputStreamReader

url = ""
domain = ""
user = ""
pswd = ""

'''Authenticator.setDefault( new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(domain + "\\" + user, pswd.toCharArray());
    }
});
'''

urlReq = URL(url)

con = urlReq.openConnection()
con.setRequestMethod("GET")

res = StringBuilder()

s = con.getInputStream()
isr = InputStreamReader(s)
br = BufferedReader(isr)
ins = br.readLine()
while ins is not None:
    res.append(ins)
    ins = br.readLine()
br.close()
print("stuff:"+res.toString())
Dee
  • 41
  • 1
  • It might help to think "Java" instead of "Jython". Yes, your syntax is Jython, but that's it -- your libraries and available APIs are all Java. If Maximo can do it, you can too with what is available. That said, I think Maximo gets WebSphere to do that, so maybe you can get WebSphere to do it for you, too. – Preacher Aug 28 '19 at 18:50

1 Answers1

1

Reviewing the JavaDocs for Authenticator may help here. This should get you somewhere close to what you're looking for:

from java.net import Authenticator
from java.net import PasswordAuthentication
from java.net import URL
from java.net import HttpURLConnection
from java.lang import StringBuilder
from java.io import InputStream, BufferedReader
from java.io import InputStreamReader

url = ""
domain = ""
user = ""
pswd = ""

'''Authenticator.setDefault( new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(domain + "\\" + user, pswd.toCharArray());
    }
});
'''

auth = Authenticator()
auth.PasswordAuthentication(domain + "\\" + user, pswd.toCharArray())

setDefault(auth)

urlReq = URL(url)

con = urlReq.openConnection()
con.setRequestMethod("GET")

res = StringBuilder()

s = con.getInputStream()
isr = InputStreamReader(s)
br = BufferedReader(isr)
ins = br.readLine()
while ins is not None:
    res.append(ins)
    ins = br.readLine()
br.close()
print("stuff:"+res.toString())
Maximo.Wiki
  • 631
  • 5
  • 17