private Credentials createCredentials(String userName, String password) { if (userName.indexOf('\\') >= 0){ final String domain = userName.substring(0, userName.indexOf('\\')); final String user = userName.substring(userName.indexOf('\\') + 1); return new NTCredentials(user, Secret.fromString(password).getPlainText(), "", domain); } else { return new UsernamePasswordCredentials(userName, Secret.fromString(password).getPlainText()); } } }
/** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails * * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)} */ public static String authenticate( final NTCredentials credentials, final String challenge) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)"); if (credentials == null) { throw new IllegalArgumentException("Credentials may not be null"); } NTLM ntlm = new NTLM(); String s = ntlm.getResponseFor(challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s; }
/** * Creates a {@link Type3Message} for NTLM authentication. * * @param ntCredentials the credentials used for the authentication * @param type2Message the {@link Type2Message} received from the server * in response to a {@link Type1Message} message previously sent. * @return a {@link Type3Message} to continue the authentication process. */ public Type3Message createType3Message(NTCredentials ntCredentials, Type2Message type2Message) { return new Type3Message(type2Message, ntCredentials.getPassword(), type2Message.getTarget(), ntCredentials.getUserName(), ntCredentials.getHost(), DEFAULT_TYPE_3_MESSAGE_FLAGS); } }
/** * Enable NTLM authentication on http client * * @param httpClient HttpClient instance */ public static void addNTLM(HttpClient httpClient) { // disable preemptive authentication httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, false); // register the jcifs based NTLMv2 implementation AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, NTLMv2Scheme.class); ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // make sure NTLM is always active needNTLM = true; // separate domain from username in credentials AuthScope authScope = new AuthScope(null, -1); NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope); if (credentials != null && credentials.getDomain() == null) { setCredentials(httpClient, credentials.getUserName(), credentials.getPassword()); } }
public static HttpClientConfigurer ntlmAutenticationConfigurer(boolean proxy, String user, String pwd, String domain, String host) { return new AuthenticationHttpClientConfigurer(proxy, new NTCredentials(user, pwd, host, domain)); } }
String s = ntlm.getResponseFor( challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s;
private static Credentials createCredentials(String username, String password) { String user; String domain; int backslashIndex = username.indexOf('\\'); if (backslashIndex >= 0) { user = username.substring(backslashIndex + 1); domain = username.substring(0, backslashIndex); } else { user = username; domain = System.getProperty("http.auth.ntlm.domain", ""); } return new NTCredentials(user, password, HostUtil.getLocalHostName(), domain); }
if (this.state == INITIATED || this.state == FAILED) { response = ntlm.getType1Message( ntcredentials.getHost(), ntcredentials.getDomain()); this.state = TYPE1_MSG_GENERATED; } else { response = ntlm.getType3Message( ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getHost(), ntcredentials.getDomain(), ntlm.parseType2Message(this.ntlmchallenge)); this.state = TYPE3_MSG_GENERATED;
private Credentials getCredentials(String username, String password){ client.getParams().setAuthenticationPreemptive(true); int domainIndex = username.indexOf('\\'); if (domainIndex > 0 && username.length() > domainIndex + 1) { return new NTCredentials( username.substring(domainIndex+1), password, "localhost", // TODO: resolve local host name username.substring(0, domainIndex)); } return new UsernamePasswordCredentials(username,password); }
/** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails * * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)} */ public static String authenticate( final NTCredentials credentials, final String challenge) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)"); if (credentials == null) { throw new IllegalArgumentException("Credentials may not be null"); } NTLM ntlm = new NTLM(); String s = ntlm.getResponseFor(challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s; }
private Credentials createCredentials(String userName, String password) { if (userName.indexOf('\\') >= 0){ final String domain = userName.substring(0, userName.indexOf('\\')); final String user = userName.substring(userName.indexOf('\\') + 1); return new NTCredentials(user, Secret.fromString(password).getPlainText(), "", domain); } else { return new UsernamePasswordCredentials(userName, Secret.fromString(password).getPlainText()); } } }
/** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails * * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)} */ public static String authenticate( final NTCredentials credentials, final String challenge) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)"); if (credentials == null) { throw new IllegalArgumentException("Credentials may not be null"); } NTLM ntlm = new NTLM(); String s = ntlm.getResponseFor(challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s; }
/** * Set credentials on HttpClient instance. * * @param httpClient httpClient instance * @param userName user name * @param password user password */ public static void setCredentials(HttpClient httpClient, String userName, String password) { // some Exchange servers redirect to a different host for freebusy, use wide auth scope AuthScope authScope = new AuthScope(null, -1); int backSlashIndex = userName.indexOf('\\'); if (needNTLM && backSlashIndex >= 0) { // separate domain from username in credentials String domain = userName.substring(0, backSlashIndex); userName = userName.substring(backSlashIndex + 1); httpClient.getState().setCredentials(authScope, new NTCredentials(userName, password, WORKSTATION_NAME, domain)); } else { httpClient.getState().setCredentials(authScope, new NTCredentials(userName, password, WORKSTATION_NAME, "")); } }
/** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails * * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)} */ public static String authenticate( final NTCredentials credentials, final String challenge) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)"); if (credentials == null) { throw new IllegalArgumentException("Credentials may not be null"); } NTLM ntlm = new NTLM(); String s = ntlm.getResponseFor(challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s; }
private NTCredentials getNTCredentials(ConnectionParam param) { // NTCredentials credentials = new NTCredentials( // param.getProxyChainUserName(), param.getProxyChainPassword(), // param.getProxyChainName(), param.getProxyChainName()); return new NTCredentials(param.getProxyChainUserName(), param.getProxyChainPassword(), "", param.getProxyChainRealm().equals("") ? "" : param.getProxyChainRealm()); }
/** * Create a NTLM authorization string for the given * challenge and NT credentials. * * @param challenge The challenge. * @param credentials {@link NTCredentials} * * @return a ntlm authorization string * @throws AuthenticationException is thrown if authentication fails * * @deprecated Use non-static {@link #authenticate(Credentials, HttpMethod)} */ public static String authenticate( final NTCredentials credentials, final String challenge) throws AuthenticationException { LOG.trace("enter NTLMScheme.authenticate(NTCredentials, String)"); if (credentials == null) { throw new IllegalArgumentException("Credentials may not be null"); } NTLM ntlm = new NTLM(); String s = ntlm.getResponseFor(challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s; }
List authPrefs = new ArrayList(); authPrefs.add(AuthPolicy.NTLM); client.getState().setProxyCredentials(new AuthScope(null, proxyPort, null), new NTCredentials(user, password, "", domain)); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
String s = ntlm.getResponseFor( challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s;
return new NTCredentials(userField.getText(), new String(passwordField.getPassword()), host, domainField.getText());
String s = ntlm.getResponseFor( challenge, credentials.getUserName(), credentials.getPassword(), credentials.getHost(), credentials.getDomain()); return "NTLM " + s;