use of java.net.PasswordAuthentication in project che by eclipse.
the class ProxyAuthenticatorTest method shouldInitHttpsProxyAuthenticator.
@Test
public void shouldInitHttpsProxyAuthenticator() throws Exception {
//when
ProxyAuthenticator.initAuthenticator(HTTPS_URL);
PasswordAuthentication testAuthentication = Authenticator.requestPasswordAuthentication(null, 0, null, null, null);
//then
assertEquals(testAuthentication.getUserName(), "user2");
assertEquals(String.valueOf(testAuthentication.getPassword()), "paswd2");
//when
ProxyAuthenticator.resetAuthenticator();
//then
testAuthentication = Authenticator.requestPasswordAuthentication(null, 0, null, null, null);
assertEquals(testAuthentication, null);
}
use of java.net.PasswordAuthentication in project che by eclipse.
the class ProxyAuthenticatorTest method shouldInitHttpProxyAuthenticator.
@Test
public void shouldInitHttpProxyAuthenticator() throws Exception {
//when
ProxyAuthenticator.initAuthenticator(HTTP_URL);
//then
PasswordAuthentication testAuthentication = Authenticator.requestPasswordAuthentication(null, 0, null, null, null);
assertEquals(testAuthentication.getUserName(), "user1");
assertEquals(String.valueOf(testAuthentication.getPassword()), "paswd1");
//when
ProxyAuthenticator.resetAuthenticator();
//then
testAuthentication = Authenticator.requestPasswordAuthentication(null, 0, null, null, null);
assertEquals(testAuthentication, null);
}
use of java.net.PasswordAuthentication in project buck by facebook.
the class HttpDownloader method fetch.
@Override
public boolean fetch(BuckEventBus eventBus, URI uri, Optional<PasswordAuthentication> authentication, Path output) throws IOException {
if (!("https".equals(uri.getScheme()) || "http".equals(uri.getScheme()))) {
return false;
}
DownloadEvent.Started started = DownloadEvent.started(uri);
eventBus.post(started);
try {
HttpURLConnection connection = createConnection(uri);
if (authentication.isPresent()) {
if ("https".equals(uri.getScheme()) && connection instanceof HttpsURLConnection) {
PasswordAuthentication p = authentication.get();
String authStr = p.getUserName() + ":" + new String(p.getPassword());
String authEncoded = BaseEncoding.base64().encode(authStr.getBytes(StandardCharsets.UTF_8));
connection.addRequestProperty("Authorization", "Basic " + authEncoded);
} else {
LOG.info("Refusing to send basic authentication over plain http.");
return false;
}
}
if (HttpURLConnection.HTTP_OK != connection.getResponseCode()) {
LOG.info("Unable to download %s: %s", uri, connection.getResponseMessage());
return false;
}
long contentLength = connection.getContentLengthLong();
try (InputStream is = new BufferedInputStream(connection.getInputStream());
OutputStream os = new BufferedOutputStream(Files.newOutputStream(output))) {
long read = 0;
while (true) {
int r = is.read();
read++;
if (r == -1) {
break;
}
if (read % PROGRESS_REPORT_EVERY_N_BYTES == 0) {
eventBus.post(new DownloadProgressEvent(uri, contentLength, read));
}
os.write(r);
}
}
return true;
} finally {
eventBus.post(DownloadEvent.finished(started));
}
}
use of java.net.PasswordAuthentication in project buck by facebook.
the class DownloadConfig method getRepoCredentials.
public Optional<PasswordAuthentication> getRepoCredentials(String repo) {
Optional<String> user = delegate.getValue("credentials", repo + "_user");
Optional<String> password = delegate.getValue("credentials", repo + "_pass");
if (!user.isPresent() || !password.isPresent()) {
return Optional.empty();
}
return Optional.of(new PasswordAuthentication(user.get(), password.get().toCharArray()));
}
use of java.net.PasswordAuthentication in project hudson-2.x by hudson.
the class Launcher method run.
public void run() throws Exception {
if (auth != null) {
final int idx = auth.indexOf(':');
if (idx < 0)
throw new CmdLineException(null, "No ':' in the -auth option");
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(auth.substring(0, idx), auth.substring(idx + 1).toCharArray());
}
});
}
if (connectionTarget != null) {
runAsTcpClient();
System.exit(0);
} else if (slaveJnlpURL != null) {
List<String> jnlpArgs = parseJnlpArguments();
try {
hudson.remoting.jnlp.Main._main(jnlpArgs.toArray(new String[jnlpArgs.size()]));
} catch (CmdLineException e) {
System.err.println("JNLP file " + slaveJnlpURL + " has invalid arguments: " + jnlpArgs);
System.err.println("Most likely a configuration error in the master");
System.err.println(e.getMessage());
System.exit(1);
}
} else if (tcpPortFile != null) {
runAsTcpServer();
System.exit(0);
} else {
runWithStdinStdout();
System.exit(0);
}
}
Aggregations