java ntlm,在Java中验证NTLMv2身份验证

So I'm trying to track down a strange bug with NTLMv2 and Java. It seems like NTLM is ignoring any information I pass in during the Java based authentication, and finds the information somewhere else. Because of this, NTLM will authenticate on my machine, even if I provide the incorrect information, and won't work on any other machine even when the correct information is provided. The endpoint is the MOSS 2007 webservice API if that's relevant.

Here's the process I'm using to authenticate:

1) Pass in the target site and login info.

try {

JLists list = new JLists(siteUrl, DEFAULT_SP_USERNAME,

DEFAULT_SP_PASSWORD);

list.addList(name, description, 101);

} catch (Exception e) {

e.printStackTrace();

}

2) Set the default authenticator to my own NTLMAuthenticator,

create the service stub and pass in the login info.

public JLists(String siteURI, String username, String password)

throws Exception {

String endpointURI = siteURI + "/_vti_bin/Lists.asmx";

Authenticator.setDefault(new NtlmAuthenticator(username, password));

port = sharePointListsAuth(username, password);

BindingProvider bp = (BindingProvider) port;

bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,

endpointURI);

}

private ListsSoap sharePointListsAuth(String userName, String password) throws Exception {

ListsSoap port = null;

if (userName != null && password != null) {

try {

service = new Lists();

port = service.getListsSoap();

((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);

((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);

} catch (Exception e) {

throw new Exception("Error: " + e.toString());

}

} else {

throw new Exception("Couldn't authenticate: Invalid connection details given.");

}

return port;

}

Here's a copy of the NTLMAuthenticator class as well:

import java.net.Authenticator;

import java.net.PasswordAuthentication;

class NtlmAuthenticator extends Authenticator {

private final String username;

private final char[] password;

public NtlmAuthenticator(final String username, final String password) {

super();

this.username = username;

this.password = password.toCharArray();

}

public PasswordAuthentication getPasswordAuthentication() {

return (new PasswordAuthentication (username, password));

}

}

3) Make my service call. I'm not really having any problems in this part, but if someone needs the code I'll post it as well.

I feel like Java is somehow referencing my Active Directory information, and using that instead the information provided, but I have no idea at what point that would happen.

解决方案

It seems like the problem is based around Java's "Single Sign-On" functionality. Because I am attempting NTLM authentication on Windows machine, Java has a hard-coded value that defaults to the login information of the current account, then uses the Java Authenticator only if that fails.

Seems there is no way to bypass this without decompiling the Java source and modifying that variable yourself, but thankfully that wont be needed in the end case for my application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值