public Executor auth(final HttpHost host, final String username, final char[] password, final String workstation, final String domain) { return auth(host, new NTCredentials(username, password, workstation, domain)); }
@Override public String generateAuthResponse( final HttpHost host, final HttpRequest request, final HttpContext context) throws AuthenticationException { if (this.credentials == null) { throw new AuthenticationException("NT credentials not available"); } final String response; if (this.state == State.FAILED) { throw new AuthenticationException("NTLM authentication failed"); } else if (this.state == State.CHALLENGE_RECEIVED) { response = this.engine.generateType1Msg( this.credentials.getNetbiosDomain(), this.credentials.getWorkstation()); this.state = State.MSG_TYPE1_GENERATED; } else if (this.state == State.MSG_TYPE2_RECEVIED) { response = this.engine.generateType3Msg( this.credentials.getUserName(), this.credentials.getPassword(), this.credentials.getNetbiosDomain(), this.credentials.getWorkstation(), this.challenge); this.state = State.MSG_TYPE3_GENERATED; } else { throw new AuthenticationException("Unexpected state: " + this.state); } return "NTLM " + response; }
/** * 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. */ public NTCredentials( final String userName, final char[] password, final String workstation, final String domain) { this(userName, password, convertHost(workstation), domain, convertDomain(domain)); }
/** Convert host to standard form */ private static String convertHost(final String host) { return stripDotSuffix(host); }
@Override public Principal getPrincipal() { return this.credentials != null ? this.credentials.getUserPrincipal() : null; }
/** Convert domain to standard form */ private static String convertDomain(final String domain) { final String returnString = stripDotSuffix(domain); return returnString == null ? returnString : returnString.toUpperCase(Locale.ROOT); }
public Executor auth(final HttpHost host, final String username, final char[] password, final String workstation, final String domain) { return auth(host, new NTCredentials(username, password, workstation, domain)); }
final String domain = System.getProperty("http.auth.ntlm.domain"); if (domain != null) { return new NTCredentials(systemcreds.getUserName(), systemcreds.getPassword(), null, domain); return new NTCredentials( systemcreds.getUserName(), systemcreds.getPassword(), null, null);