如何在 Eclipse 插件代码中使用 URLConnection 时抑制身份验证窗口
我创建了一个 Eclipse 插件,并在其中通过扩展 org.eclipse.jface.wizard.Wizard 创建了一个向导。我正在使用 java.net.URLConnection 与服务器执行基本身份验证,如下所示
String auth = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
log(auth);
URL url = new URL(server);
URLConnection conn = url.openConnection();
// this fails -- can't stop the auth window when the username/password are invalid
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Authorization", "Basic " + auth);
monitor.beginTask("Authenticating: ", IProgressMonitor.UNKNOWN);
InputStream in = conn.getInputStream();
:密码有效,那么一切正常。但如果用户名 &如果密码不进行身份验证,Eclipse 会弹出自己的“需要密码”窗口(我不想要这个窗口——我想自己管理失败的身份验证)。我本以为 URLConnection.setAllowUserInteraction 会阻止这个,但它没有效果。
I have created an Eclipse Plugin, and within that I have created a Wizard by extending org.eclipse.jface.wizard.Wizard. In that I am using java.net.URLConnection to perform Basic Authentication with a server, like so:
String auth = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
log(auth);
URL url = new URL(server);
URLConnection conn = url.openConnection();
// this fails -- can't stop the auth window when the username/password are invalid
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Authorization", "Basic " + auth);
monitor.beginTask("Authenticating: ", IProgressMonitor.UNKNOWN);
InputStream in = conn.getInputStream();
If the username & password are valid, then everything works fine. But if the username & password do not authenticate, Eclipse pops up its own "Password Required" window (which I don't want -- I want to manage the failed authentication myself). I would have thought that URLConnection.setAllowUserInteraction would stop this, but it has no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅扩展点 org.eclipse.equinox.security.loginModule。
See extension point org.eclipse.equinox.security.loginModule.