• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NtlmMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JobMapTaskRescheduledEvent类代码示例发布时间:2022-05-22
下一篇:
Java BlockPlacementPolicy类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap