Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get an NTLM authentication through jython script in maximo

Tags:

jython

maximo

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())
like image 859
Dee Avatar asked Dec 04 '25 16:12

Dee


1 Answers

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())
like image 100
Maximo.Wiki Avatar answered Dec 10 '25 09:12

Maximo.Wiki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!