in src/org/jetbrains/plugins/ipnb/protocol/IpnbConnection.java [183:223]
private String login(@NotNull String username, @NotNull String password, @NotNull String loginUrl) throws IOException {
String urlParameters = null;
try {
urlParameters = new URIBuilder()
.addParameter(XSRF_PARAMETER, myXsrf)
.addParameter(USERNAME_PARAMETER, username)
.addParameter(PASSWORD_PARAMETER, password)
.build().toString();
}
catch (URISyntaxException e) {
LOG.warn(e.getMessage());
}
if (urlParameters == null) throw new IOException("Unable to login");
byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8);
final HttpsURLConnection connection = ObjectUtils.tryCast(configureConnection((HttpURLConnection)new URL(myURI + loginUrl).openConnection(),
HTTPMethod.POST.name()), HttpsURLConnection.class);
if (connection != null) {
connection.setUseCaches(false);
connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postData.length));
connection.setDoOutput(true);
final OutputStream outputStream = connection.getOutputStream();
try (DataOutputStream wr = new DataOutputStream(outputStream)) {
wr.write(postData);
wr.flush();
}
connection.connect();
final int code = connection.getResponseCode();
if (code != HttpURLConnection.HTTP_FORBIDDEN && code != HttpURLConnection.HTTP_UNAUTHORIZED) {
final List<HttpCookie> cookies = myCookieManager.getCookieStore().getCookies();
if (!cookies.isEmpty()) {
return cookies.stream().map(cookie -> cookie.getName() + "=" + cookie.getValue()).collect(Collectors.joining(";"));
}
}
}
String message = connection == null ? "" : connection.getResponseCode() + " " + connection.getResponseMessage();
throw new IOException(UNABLE_LOGIN_MESSAGE + message);
}