Search in sources :

Example 1 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project robovm by robovm.

the class RFC2965Spec method getVersionHeader.

@Override
public Header getVersionHeader() {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 2 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class NTLMScheme method authenticate.

public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException {
    NTCredentials ntcredentials = null;
    try {
        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);
}
Also used : InvalidCredentialsException(org.apache.http.auth.InvalidCredentialsException) AuthenticationException(org.apache.http.auth.AuthenticationException) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) NTCredentials(org.apache.http.auth.NTCredentials)

Example 3 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class NetscapeDraftSpec method formatCookies.

public List<Header> formatCookies(final List<Cookie> cookies) {
    if (cookies == null) {
        throw new IllegalArgumentException("List of cookies may not be null");
    }
    if (cookies.isEmpty()) {
        throw new IllegalArgumentException("List of cookies may not be empty");
    }
    CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
    buffer.append(SM.COOKIE);
    buffer.append(": ");
    for (int i = 0; i < cookies.size(); i++) {
        Cookie cookie = cookies.get(i);
        if (i > 0) {
            buffer.append("; ");
        }
        buffer.append(cookie.getName());
        String s = cookie.getValue();
        if (s != null) {
            buffer.append("=");
            buffer.append(s);
        }
    }
    List<Header> headers = new ArrayList<Header>(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
}
Also used : ClientCookie(org.apache.http.cookie.ClientCookie) Cookie(org.apache.http.cookie.Cookie) BufferedHeader(org.apache.http.message.BufferedHeader) Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList)

Example 4 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project XobotOS by xamarin.

the class RFC2965Spec method getVersionHeader.

@Override
public Header getVersionHeader() {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append(SM.COOKIE2);
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 5 with BufferedHeader

use of org.apache.http.message.BufferedHeader in project robovm by robovm.

the class BasicScheme method authenticate.

/**
     * Returns a basic <tt>Authorization</tt> header value for the given 
     * {@link Credentials} and charset.
     * 
     * @param credentials The credentials to encode.
     * @param charset The charset to use for encoding the credentials
     * 
     * @return a basic authorization header
     */
public static Header authenticate(final Credentials credentials, final String charset, boolean proxy) {
    if (credentials == null) {
        throw new IllegalArgumentException("Credentials may not be null");
    }
    if (charset == null) {
        throw new IllegalArgumentException("charset may not be null");
    }
    StringBuilder tmp = new StringBuilder();
    tmp.append(credentials.getUserPrincipal().getName());
    tmp.append(":");
    tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());
    byte[] base64password = Base64.encodeBase64(EncodingUtils.getBytes(tmp.toString(), charset));
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (proxy) {
        buffer.append(AUTH.PROXY_AUTH_RESP);
    } else {
        buffer.append(AUTH.WWW_AUTH_RESP);
    }
    buffer.append(": Basic ");
    buffer.append(base64password, 0, base64password.length);
    return new BufferedHeader(buffer);
}
Also used : BufferedHeader(org.apache.http.message.BufferedHeader) CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Aggregations

BufferedHeader (org.apache.http.message.BufferedHeader)29 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)29 ArrayList (java.util.ArrayList)15 Header (org.apache.http.Header)12 ClientCookie (org.apache.http.cookie.ClientCookie)12 Cookie (org.apache.http.cookie.Cookie)12 FormattedHeader (org.apache.http.FormattedHeader)6 AuthenticationException (org.apache.http.auth.AuthenticationException)6 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)5 NTCredentials (org.apache.http.auth.NTCredentials)4 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 HttpHost (org.apache.http.HttpHost)1 BasicHeader (org.apache.http.message.BasicHeader)1 GSSContext (org.ietf.jgss.GSSContext)1 GSSException (org.ietf.jgss.GSSException)1 GSSManager (org.ietf.jgss.GSSManager)1 GSSName (org.ietf.jgss.GSSName)1 Oid (org.ietf.jgss.Oid)1