【问题标题】:how to get an NTLM authentication through jython script in maximo如何通过 maximo 中的 jython 脚本获得 NTLM 身份验证
【发布时间】:2019-10-02 01:53:48
【问题描述】:

试图获得 NTLM 连接,但我的 jython 不够熟练,无法翻译 Authenticator 部分代码。我需要什么信息来完成这个?如果这甚至可以在 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())

【问题讨论】:

  • 考虑“Java”而不是“Jython”可能会有所帮助。是的,您的语法是 Jython,但仅此而已 - 您的库和可用的 API 都是 Java。如果 Maximo 可以做到,那么您也可以使用可用的东西。也就是说,我认为 Maximo 让 WebSphere 来做这件事,所以也许您也可以让 WebSphere 来为您做这件事。

标签: jython maximo


【解决方案1】:

查看Authenticator 的JavaDocs 可能会有所帮助。这应该会让你接近你正在寻找的东西:

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())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多