FileDocCategorySizeDatePackage
NTCredentials.javaAPI DocAndroid 1.5 API6108Wed May 06 22:41:10 BST 2009org.apache.http.auth

NTCredentials

public class NTCredentials extends Object implements Credentials
{@link Credentials} specific to the Windows platform.
author
Adrian Sutton
author
Mike Bowler
author
Oleg Kalnichevski
since
2.0

Fields Summary
private final NTUserPrincipal
principal
The user principal
private final String
password
Password
private final String
workstation
The host the authentication request is originating from.
Constructors Summary
public NTCredentials(String usernamePassword)
The constructor with the fully qualified username and password combined string argument.

param
usernamePassword the domain/username:password formed string

        super();
        if (usernamePassword == null) {
            throw new IllegalArgumentException("Username:password string may not be null");            
        }
        String username;
        int atColon = usernamePassword.indexOf(':");
        if (atColon >= 0) {
            username = usernamePassword.substring(0, atColon);
            this.password = usernamePassword.substring(atColon + 1);
        } else {
            username = usernamePassword;
            this.password = null;
        }
        int atSlash = username.indexOf('/");
        if (atSlash >= 0) {
            this.principal = new NTUserPrincipal(
                    username.substring(0, atSlash).toUpperCase(Locale.ENGLISH),
                    username.substring(atSlash + 1));
        } else {
            this.principal = new NTUserPrincipal(
                    null,
                    username.substring(atSlash + 1));
        }
        this.workstation = null;
    
public NTCredentials(String userName, String password, String workstation, String domain)
Constructor.

param
userName The user name. This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
param
password The password.
param
workstation The workstation the authentication request is originating from. Essentially, the computer name for this machine.
param
domain The domain to authenticate within.

        super();
        if (userName == null) {
            throw new IllegalArgumentException("User name may not be null");
        }
        this.principal = new NTUserPrincipal(domain, userName);
        this.password = password;
        if (workstation != null) {
            this.workstation = workstation.toUpperCase(Locale.ENGLISH);
        } else {
            this.workstation = null;
        }
    
Methods Summary
public booleanequals(java.lang.Object o)

        if (o == null) return false;
        if (this == o) return true;
        if (o instanceof NTCredentials) {
            NTCredentials that = (NTCredentials) o;
            if (LangUtils.equals(this.principal, that.principal)
                    && LangUtils.equals(this.workstation, that.workstation)) {
                return true;
            }
        }
        return false;
    
public java.lang.StringgetDomain()
Retrieves the name to authenticate with.

return
String the domain these credentials are intended to authenticate with.

        return this.principal.getDomain();
    
public java.lang.StringgetPassword()

        return this.password;
    
public java.lang.StringgetUserName()

        return this.principal.getUsername();
    
public java.security.PrincipalgetUserPrincipal()

        return this.principal;
    
public java.lang.StringgetWorkstation()
Retrieves the workstation name of the computer originating the request.

return
String the workstation the user is logged into.

        return this.workstation;
    
public inthashCode()

        int hash = LangUtils.HASH_SEED;
        hash = LangUtils.hashCode(hash, this.principal);
        hash = LangUtils.hashCode(hash, this.workstation);
        return hash;
    
public java.lang.StringtoString()

        StringBuilder buffer = new StringBuilder();
        buffer.append("[principal: ");
        buffer.append(this.principal);
        buffer.append("][workstation: ");
        buffer.append(this.workstation);
        buffer.append("]");
        return buffer.toString();