Credentials (@NotNull String login, String password, String host) { int domainIndex = login.indexOf("\\"); if (domainIndex > 0) { // if the username is in the form "user\domain" // then use NTCredentials instead of UsernamePasswordCredentials String domain = login.substring(0, domainIndex); if (login.length() > domainIndex + 1) { String user = login.substring(domainIndex + 1); return new NTCredentials(user, password, host, domain); } else { return null; } } else { return new UsernamePasswordCredentials(login, password); } }