当前位置: 首页>>代码示例>>Java>>正文


Java NTCredentials类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.NTCredentials的典型用法代码示例。如果您正苦于以下问题:Java NTCredentials类的具体用法?Java NTCredentials怎么用?Java NTCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NTCredentials类属于org.apache.commons.httpclient包,在下文中一共展示了NTCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
/**
 * Create a NTLM authorization string for the given
 * challenge and NT credentials.
 *
 * @param challenge The challenge.
 * @param credentials {@link NTCredentials}
 * @param charset The charset to use for encoding the credentials
 *
 * @return a ntlm authorization string
 * @throws AuthenticationException is thrown if authentication fails
 * 
 * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)}
 * 
 * @since 3.0
 */
public static String authenticate(
    final NTCredentials credentials, 
    final String challenge,
    String charset
) throws AuthenticationException {

    LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)");

    if (credentials == null) {
        throw new IllegalArgumentException("Credentials may not be null");
    }
    
    NTLM ntlm = new NTLM();
    ntlm.setCredentialCharset(charset);
    String s = ntlm.getResponseFor(
        challenge,
        credentials.getUserName(), 
        credentials.getPassword(),
        credentials.getHost(), 
        credentials.getDomain());
    return "NTLM " + s;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:NTLMScheme.java

示例2: testNTLMAuthenticationResponse2

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public void testNTLMAuthenticationResponse2() throws Exception {
    String challenge = 
        "NTLM TlRMTVNTUAACAAAACgAKADAAAAAGgoEAPc4kP4LtCV8AAAAAAAAAAJ4AngA" +
        "6AAAASU5UUkFFUEhPWAIAFABJAE4AVABSAEEARQBQAEgATwBYAAEAEgBCAE8AQQB" +
        "SAEQAUgBPAE8ATQAEACgAaQBuAHQAcgBhAGUAcABoAG8AeAAuAGUAcABoAG8AeAA" +
        "uAGMAbwBtAAMAPABCAG8AYQByAGQAcgBvAG8AbQAuAGkAbgB0AHIAYQBlAHAAaAB" +
        "vAHgALgBlAHAAaABvAHgALgBjAG8AbQAAAAAA";

    String expected = "NTLM TlRMTVNTUAADAAAAGAAYAFIAAAAAAAAAagAAAAYABgB" +
        "AAAAACAAIAEYAAAAEAAQATgAAAAAAAABqAAAABlIAAERPTUFJTlVTRVJOQU1FSE" +
        "9TVAaC+vLxUEHnUtpItj9Dp4kzwQfd61Lztg==";
    NTCredentials cred = new NTCredentials("username","password", "host", "domain");
    FakeHttpMethod method = new FakeHttpMethod(); 
    AuthScheme authscheme = new NTLMScheme(challenge);
    authscheme.processChallenge(challenge);
    String response = authscheme.authenticate(cred, method);
    assertEquals(expected, response);
    assertTrue(authscheme.isComplete());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestNTLMAuth.java

示例3: testNTLMAuthenticationRetry

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public void testNTLMAuthenticationRetry() throws Exception {

        this.server.setHttpService(new NTLMAuthService());

        // configure the client
        this.client.getHostConfiguration().setHost(
                server.getLocalAddress(), server.getLocalPort(),
                Protocol.getProtocol("http"));
        
        this.client.getState().setCredentials(AuthScope.ANY, 
                new NTCredentials("username", "password", "host", "domain"));
        
        FakeHttpMethod httpget = new FakeHttpMethod("/");
        try {
            client.executeMethod(httpget);
        } finally {
            httpget.releaseConnection();
        }
        assertNull(httpget.getResponseHeader("WWW-Authenticate"));
        assertEquals(200, httpget.getStatusCode());
    }
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:22,代码来源:TestNTLMAuth.java

示例4: testPreemptiveAuthorization

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
/**
 * Make sure preemptive authorization works when the server requires NLM.
 * @throws Exception
 */
public void testPreemptiveAuthorization() throws Exception {

    NTCredentials creds = 
        new NTCredentials("testuser", "testpass", "host", "domain");
    
    HttpState state = new HttpState();
    state.setCredentials(AuthScope.ANY, creds);
    this.client.setState(state);
    this.client.getParams().setAuthenticationPreemptive(true);

    this.server.setHttpService(new PreemptiveNTLMAuthService());

    GetMethod httpget = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertNotNull(httpget.getStatusLine());
    assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestNTLMAuth.java

示例5: setConnectionAuthorization

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
/**
 * Extracts all the required authorization for that particular URL request
 * and sets it in the <code>HttpMethod</code> passed in.
 *
 * @param client the HttpClient object
 *
 * @param u
 *            <code>URL</code> of the URL request
 * @param authManager
 *            the <code>AuthManager</code> containing all the authorisations for
 *            this <code>UrlConfig</code>
 */
private void setConnectionAuthorization(HttpClient client, URL u, AuthManager authManager) {
    HttpState state = client.getState();
    if (authManager != null) {
        HttpClientParams params = client.getParams();
        Authorization auth = authManager.getAuthForURL(u);
        if (auth != null) {
                String username = auth.getUser();
                String realm = auth.getRealm();
                String domain = auth.getDomain();
                if (log.isDebugEnabled()){
                    log.debug(username + " >  D="+ username + " D="+domain+" R="+realm);
                }
                state.setCredentials(
                        new AuthScope(u.getHost(),u.getPort(),
                                realm.length()==0 ? null : realm //"" is not the same as no realm
                                ,AuthScope.ANY_SCHEME),
                        // NT Includes other types of Credentials
                        new NTCredentials(
                                username,
                                auth.getPass(),
                                localHost,
                                domain
                        ));
                // We have credentials - should we set pre-emptive authentication?
                if (canSetPreEmptive){
                    log.debug("Setting Pre-emptive authentication");
                    params.setAuthenticationPreemptive(true);
                }
        } else {
            state.clearCredentials();
            if (canSetPreEmptive){
                params.setAuthenticationPreemptive(false);
            }
        }
    } else {
        state.clearCredentials();
    }
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:51,代码来源:HTTPHC3Impl.java

示例6: initExternalProxy

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
private void initExternalProxy(ExternalProxySettings ep)
{
    if (externalProxy != null)
    {

        String proxyServer = externalProxy.getProxyServer();
        String proxyUsername = externalProxy.getUsername();

        if (proxyUsername != null)
        {
            String proxyPassword = externalProxy.getPassword();
            String proxyDomain = externalProxy.getNTDomain();
            if (proxyDomain != null)
            {
                proxyCredentials = new NTCredentials(proxyUsername, proxyPassword, proxyServer, proxyDomain);
            }
            else
            {
                proxyCredentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
            }
        }
    }
}
 
开发者ID:apache,项目名称:flex-blazeds,代码行数:24,代码来源:HTTPProxyAdapter.java

示例7: AuthenticateProxy

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
private Socket AuthenticateProxy(ConnectMethod method, ProxyClient client, 
        String proxyHost, int proxyPort, 
        String proxyUsername, String proxyPassword) throws IOException {   
    if(method.getProxyAuthState().getAuthScheme().getSchemeName().equalsIgnoreCase("ntlm")) {
        // If Auth scheme is NTLM, set NT credentials with blank host and domain name
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), 
                        new NTCredentials(proxyUsername, proxyPassword,"",""));
    } else {
        // If Auth scheme is Basic/Digest, set regular Credentials
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), 
                new UsernamePasswordCredentials(proxyUsername, proxyPassword));
    }
    
    ProxyClient.ConnectResponse response = client.connect();
    Socket socket = response.getSocket();
    
    if (socket == null) {
        method = response.getConnectMethod();
        throw new ProtocolException("Proxy Authentication failed. Socket not created: " 
                + method.getStatusLine());
    }
    return socket;
}
 
开发者ID:dzh,项目名称:jframe,代码行数:24,代码来源:TlsTunnelBuilder.java

示例8: setNTLMCredentials

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public static void setNTLMCredentials(HttpClient httpClient, UsernamePasswordCredentials credentials,
                                      String domain) {
    initNTLMv2();

    String localHostName;
    try {
        localHostName = Inet4Address.getLocalHost().getHostName();
    } catch (Exception e) {
        localHostName = "";
    }

    AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
    httpClient.getState().setCredentials(
            authscope,
            new NTCredentials(
                    credentials.getUserName(),
                    credentials.getPassword(),
                    localHostName, domain));
}
 
开发者ID:DovAmir,项目名称:httpclientAuthHelper,代码行数:20,代码来源:CredentialsUtils.java

示例9: getCredentials

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
@Nullable
private static Credentials getCredentials(String login, String password, String host)
{
	int domainIndex = login.indexOf("\\");
	if(domainIndex > 0)
	{
		// if the username is in the form "user\domain"
		// then use NTCredentials instead of UsernamePasswordCredentials
		String domain = login.substring(0, domainIndex);
		if(login.length() > domainIndex + 1)
		{
			String user = login.substring(domainIndex + 1);
			return new NTCredentials(user, password, host, domain);
		}
		else
		{
			return null;
		}
	}
	else
	{
		return new UsernamePasswordCredentials(login, password);
	}
}
 
开发者ID:consulo,项目名称:consulo-tasks,代码行数:25,代码来源:BaseRepositoryImpl.java

示例10: setNtlmAuth

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public void setNtlmAuth(HttpState httpState) {
	// Setting NTLM authentication for proxy
	int indexSlash = this.proxyUser.indexOf("\\");	
	String domain = this.proxyUser.substring(0, indexSlash);
	String username = this.proxyUser.substring(indexSlash + 1);

	Engine.logProxyManager.debug("(ProxyManager) Using NTLM authentication on domain: " + domain);

	httpState.setProxyCredentials(
			new AuthScope(this.proxyServer, -1, AuthScope.ANY_REALM),
			new NTCredentials(username, this.proxyPassword, this.proxyServer, domain));
	
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:14,代码来源:ProxyManager.java

示例11: testNTLMAuthenticationResponse1

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public void testNTLMAuthenticationResponse1() throws Exception {
    String challenge = "NTLM";
    String expected = "NTLM TlRMTVNTUAABAAAABlIAAAYABgAkAAAABAAEACAAAABIT" +
        "1NURE9NQUlO";
    NTCredentials cred = new NTCredentials("username","password", "host", "domain");
    FakeHttpMethod method = new FakeHttpMethod(); 
    AuthScheme authscheme = new NTLMScheme(challenge);
    authscheme.processChallenge(challenge);
    String response = authscheme.authenticate(cred, method);
    assertEquals(expected, response);
    assertFalse(authscheme.isComplete());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:13,代码来源:TestNTLMAuth.java

示例12: getCredentials

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
private static Credentials getCredentials(final String username,
        final String password, final InetAddress address) {
    int i = username.indexOf("\\");
    if (i > 0 && i < username.length() - 1 && address != null) {
        return new NTCredentials(username.substring(i + 1), password,
                address.getHostName(), username.substring(0, i));
    } else {
        return new UsernamePasswordCredentials(username, password);
    }
}
 
开发者ID:jonico,项目名称:core,代码行数:11,代码来源:TrackerHttpSender.java

示例13: configureHttpClient

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
public void configureHttpClient(HttpClient client) {
    Credentials credentials = new NTCredentials(username, password, host, domain);
    if (proxy) {
        client.getState().setProxyCredentials(AuthScope.ANY, credentials);
    } else {
        client.getState().setCredentials(AuthScope.ANY, credentials);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:NTLMAuthenticationHttpClientConfigurer.java

示例14: getType1MessageResponse

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
@Override
protected String getType1MessageResponse(NTCredentials ntcredentials, HttpMethodParams params) {
  if (!params.getBooleanParameter(WebServiceHelper.USE_NATIVE_CREDENTIALS, false) || myAuthSequenceObject == null) {
    return super.getType1MessageResponse(ntcredentials, params);
  }

  try {
    return (String)myGetAuthHeaderMethod.invoke(myAuthSequenceObject, new Object[]{null});
  }
  catch (Throwable t) {
    LOG.warn("Native authentication failed", t);
    return "";
  }
}
 
开发者ID:Microsoft,项目名称:vso-intellij,代码行数:15,代码来源:NativeNTLM2Scheme.java

示例15: getType3MessageResponse

import org.apache.commons.httpclient.NTCredentials; //导入依赖的package包/类
@Override
protected String getType3MessageResponse(String type2message, NTCredentials ntcredentials, HttpMethodParams params)
  throws AuthenticationException {
  if (!params.getBooleanParameter(WebServiceHelper.USE_NATIVE_CREDENTIALS, false) || myAuthSequenceObject == null) {
    return super.getType3MessageResponse(type2message, ntcredentials, params);
  }

  try {
    return (String)myGetAuthHeaderMethod.invoke(myAuthSequenceObject, new Object[]{type2message});
  }
  catch (Throwable t) {
    LOG.warn("Native authentication failed", t);
    return "";
  }
}
 
开发者ID:Microsoft,项目名称:vso-intellij,代码行数:16,代码来源:NativeNTLM2Scheme.java


注:本文中的org.apache.commons.httpclient.NTCredentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。