Example usage for org.apache.http.auth NTCredentials getPassword

List of usage examples for org.apache.http.auth NTCredentials getPassword

Introduction

In this page you can find the example usage for org.apache.http.auth NTCredentials getPassword.

Prototype

public String getPassword() 

Source Link

Usage

From source file:com.psiphon3.psiphonlibrary.UpstreamProxySettings.java

public synchronized static String getUpstreamProxyUrl(Context context) {
    ProxySettings proxySettings = getProxySettings(context);

    if (proxySettings == null) {
        return "";
    }//from  w  w  w . j  a  v a2 s.  com

    StringBuilder url = new StringBuilder();
    url.append("http://");

    NTCredentials credentials = (NTCredentials) getProxyCredentials(context);

    if (credentials != null) {
        if (!credentials.getDomain().equals("")) {
            url.append(credentials.getDomain());
            url.append("\\");
        }
        url.append(credentials.getUserName());
        url.append(":");
        url.append(credentials.getPassword());
        url.append("@");
    }

    url.append(proxySettings.proxyHost);
    url.append(":");
    url.append(proxySettings.proxyPort);

    return url.toString();
}

From source file:io.cloudslang.content.httpclient.build.auth.CredentialsProviderBuilderTest.java

@Test
public void createNtlmCredentialsProvider() {
    CredentialsProvider credentialsProvider = getCredentialsProvider(AuthSchemes.NTLM);
    Credentials credentials = credentialsProvider.getCredentials(new AuthScope("host", 80));

    assertThat(credentials, instanceOf(NTCredentials.class));
    NTCredentials ntCredentials = (NTCredentials) credentials;
    assertEquals("DOMAIN", ntCredentials.getDomain());
    assertEquals("HOST", ntCredentials.getWorkstation());
    assertEquals("pass", ntCredentials.getPassword());
    Credentials proxyCredentials = credentialsProvider.getCredentials(new AuthScope("proxy", 8080));
    assertThat(proxyCredentials, instanceOf(UsernamePasswordCredentials.class));
    UsernamePasswordCredentials userCredentials = (UsernamePasswordCredentials) proxyCredentials;
    assertEquals("proxyUsername", userCredentials.getUserName());
}

From source file:com.androidquery.test.NTLMScheme.java

public Header authenticate(final Credentials credentials, final HttpRequest request)
        throws AuthenticationException {
    NTCredentials ntcredentials = null;
    try {/*from   ww  w .  j  a  va  2s . c  o  m*/
        ntcredentials = (NTCredentials) credentials;
    } catch (ClassCastException e) {
        throw new InvalidCredentialsException(
                "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
    }
    String response = null;
    if (this.state == State.CHALLENGE_RECEIVED || this.state == State.FAILED) {
        response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getWorkstation());
        this.state = State.MSG_TYPE1_GENERATED;
    } else if (this.state == State.MSG_TYPE2_RECEVIED) {
        response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(),
                ntcredentials.getDomain(), ntcredentials.getWorkstation(), this.challenge);
        this.state = State.MSG_TYPE3_GENERATED;
    } else {
        throw new AuthenticationException("Unexpected state: " + this.state);
    }
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": NTLM ");
    buffer.append(response);
    return new BufferedHeader(buffer);
}

From source file:org.jasig.portlet.calendar.adapter.exchange.ExchangeCredentialsInitializationServiceTest.java

@Test
public void testInitialize() {
    service.initialize(request);//  w w w  .  j a va2s  .c o m

    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    final NTCredentials credentials = (NTCredentials) requestAttributes.getAttribute(
            ExchangeWsCredentialsProvider.EXCHANGE_CREDENTIALS_ATTRIBUTE, RequestAttributes.SCOPE_SESSION);
    assertEquals("user", credentials.getUserName());
    assertEquals("pass", credentials.getPassword());
}

From source file:org.jasig.portlet.calendar.adapter.exchange.ExchangeCredentialsInitializationServiceTest.java

@Test
public void testWithExistingRequestInitialize() {
    final RequestAttributes requestAttributes = new PortletRequestAttributes(request);
    requestAttributes.setAttribute("testAttr", "testVal", RequestAttributes.SCOPE_SESSION);
    RequestContextHolder.setRequestAttributes(requestAttributes);

    service.initialize(request);//from   w ww  .  j  a va  2  s . co  m

    final RequestAttributes newRequestAttributes = RequestContextHolder.getRequestAttributes();
    final NTCredentials credentials = (NTCredentials) newRequestAttributes.getAttribute(
            ExchangeWsCredentialsProvider.EXCHANGE_CREDENTIALS_ATTRIBUTE, RequestAttributes.SCOPE_SESSION);
    assertEquals("user", credentials.getUserName());
    assertEquals("pass", credentials.getPassword());
    assertEquals("testVal", newRequestAttributes.getAttribute("testAttr", RequestAttributes.SCOPE_SESSION));
}