Reputation: 41
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())
Upvotes: 4
Views: 234
Reputation: 631
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())
Upvotes: 1