本文整理汇总了Java中jcifs.ntlmssp.NtlmMessage类的典型用法代码示例。如果您正苦于以下问题:Java NtlmMessage类的具体用法?Java NtlmMessage怎么用?Java NtlmMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NtlmMessage类属于jcifs.ntlmssp包,在下文中一共展示了NtlmMessage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: performNtlmAuthentication
import jcifs.ntlmssp.NtlmMessage; //导入依赖的package包/类
protected String performNtlmAuthentication(InetSocketAddress target,
String challenge) throws IOException {
if (challenge.length() == 4) {
NtlmMessage type1 = new Type1Message(NTLMV2_FLAGS, null, null);
return "NTLM "
+ Base64
.encodeBytes(type1.toByteArray(), Base64.NO_OPTIONS);
} else {
challenge = challenge.substring(5); // "NTLM "
Type2Message type2 = new Type2Message(Base64.decode(challenge,
Base64.NO_OPTIONS));
String domain = type2.getTarget();
String hostname = target.getHostName();
InetAddress addr = target.isUnresolved() ? null : target
.getAddress();
PasswordAuthentication pa = Authenticator
.requestPasswordAuthentication(hostname, addr, target
.getPort(), "HTTP", domain, "NTLM");
if (pa == null)
return null;
String username = pa.getUserName();
String password = new String(pa.getPassword());
int slash = username.indexOf('\\');
if (slash > -1) {
domain = username.substring(0, slash);
username = username.substring(slash + 1);
}
Type3Message type3 = new Type3Message(type2, password, domain,
username, null, NTLMV2_FLAGS_TYPE3);
return "NTLM "
+ Base64
.encodeBytes(type3.toByteArray(), Base64.NO_OPTIONS);
}
}
开发者ID:intuit,项目名称:Tank,代码行数:36,代码来源:HttpAuthenticator.java
示例2: doHandshake
import jcifs.ntlmssp.NtlmMessage; //导入依赖的package包/类
private void doHandshake () throws IOException, GeneralSecurityException {
connect();
try {
int response = parseResponseCode();
if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) {
return;
}
NtlmMessage type1 = attemptNegotiation(response);
if ( type1 == null )
return; // no NTLM
int attempt = 0;
while ( attempt < MAX_REDIRECTS ) {
this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type1.toByteArray()));
this.connection.connect(); // send type 1
response = parseResponseCode();
if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) {
return;
}
NtlmMessage type3 = attemptNegotiation(response);
if ( type3 == null )
return;
this.connection.setRequestProperty(this.authProperty, this.authMethod + ' ' + Base64.toBase64String(type3.toByteArray()));
this.connection.connect(); // send type 3
if ( this.cachedOutput != null && this.doOutput ) {
@SuppressWarnings ( "resource" )
OutputStream output = this.connection.getOutputStream();
this.cachedOutput.writeTo(output);
output.flush();
}
response = parseResponseCode();
if ( response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH ) {
return;
}
attempt++;
if ( this.allowUserInteraction && attempt < MAX_REDIRECTS ) {
reconnect();
}
else {
break;
}
}
throw new IOException("Unable to negotiate NTLM authentication.");
}
finally {
this.cachedOutput = null;
}
}
开发者ID:AgNO3,项目名称:jcifs-ng,代码行数:48,代码来源:NtlmHttpURLConnection.java
注:本文中的jcifs.ntlmssp.NtlmMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论