Show warning if remote notebook url isn't https

This commit is contained in:
Valentina Kiryushkina
2017-02-06 17:21:23 +03:00
parent 4ae82cbbdd
commit 6b4f77f3a2
3 changed files with 67 additions and 4 deletions
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.ipnb.configuration.IpnbConfigurable">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="657" height="302"/>
@@ -107,7 +107,7 @@
</grid>
<vspacer id="9a11e">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b88d4" class="com.intellij.ui.TitledSeparator">
@@ -118,6 +118,27 @@
<text value="Remote notebook credentials"/>
</properties>
</component>
<grid id="161aa" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9a652" class="com.intellij.ui.components.JBLabel" binding="myWarningLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<hspacer id="cab57">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>
@@ -7,11 +7,16 @@ import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
public class IpnbConfigurable implements SearchableConfigurable {
private JPanel myMainPanel;
@@ -20,17 +25,47 @@ public class IpnbConfigurable implements SearchableConfigurable {
private JBTextField myArgumentsField;
private JPasswordField myPasswordField;
private JBTextField myUsernameField;
private JBLabel myWarningLabel;
@NotNull private final Project myProject;
public IpnbConfigurable(@NotNull Project project) {
myProject = project;
myWarningLabel.setForeground(new JBColor(new Color(164, 145, 52), new Color(187, 181, 41)));
final FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
myWorkingDirField.addBrowseFolderListener("Select Working Directory", null, myProject, fileChooserDescriptor);
myFieldUrl.setText(IpnbSettings.getInstance(myProject).getURL());
myFieldUrl.addFocusListener(createUrlProtocolValidationListener());
myUsernameField.addFocusListener(createUrlProtocolValidationListener());
myPasswordField.addFocusListener(createUrlProtocolValidationListener());
myWorkingDirField.setText(IpnbSettings.getInstance(myProject).getWorkingDirectory());
myArgumentsField.setText(IpnbSettings.getInstance(myProject).getArguments());
}
@NotNull
private FocusAdapter createUrlProtocolValidationListener() {
return new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
setWarningLabelText();
}
};
}
private void setWarningLabelText() {
final boolean isRemote = !myUsernameField.getText().isEmpty() && myPasswordField.getPassword().length > 0;
final String url = myFieldUrl.getText();
if (isRemote && !url.startsWith("https")) {
myWarningLabel.setText("Only HTTPS urls are supported in remote notebooks");
return;
}
if (!isRemote && url.startsWith("https")) {
myWarningLabel.setText("Only HTTP urls are supported in local notebooks");
return;
}
myWarningLabel.setText("");
}
@Nls
@Override
public String getDisplayName() {
@@ -98,6 +133,8 @@ public class IpnbConfigurable implements SearchableConfigurable {
myArgumentsField.setText(IpnbSettings.getInstance(myProject).getArguments());
myUsernameField.setText(IpnbSettings.getInstance(myProject).getUsername());
myPasswordField.setText(IpnbSettings.getInstance(myProject).getPassword());
setWarningLabelText();
}
@Override
@@ -94,8 +94,13 @@ public class IpnbConnection {
myProject = project;
myCookieManager = new CookieManager();
CookieHandler.setDefault(myCookieManager);
if (!isRemote() && !myURI.getScheme().equals("http")) {
throw new UnsupportedOperationException("Only http urls are supported for local notebooks");
if (!isRemote()) {
if (!myURI.getScheme().equals("http")) {
throw new UnsupportedOperationException("Only http urls are supported for local notebooks");
}
}
else if (!myURI.getScheme().equals("https")) {
throw new UnsupportedOperationException("Only https urls are supported for remote notebooks");
}
initXSRF(myURI.toString());