return "Specifies authentication credentials";
}
public void perform() {
final WTKXSerializer sheetSerializer = new WTKXSerializer();
final Sheet sheet;
try {
sheet = (Sheet)sheetSerializer.readObject("pivot/tools/net/setAuthentication.wtkx");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Button okButton = (Button)sheetSerializer.getObjectByName("okButton");
okButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
sheet.close(true);
}
});
Button cancelButton = (Button)sheetSerializer.getObjectByName("cancelButton");
cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
sheet.close(false);
}
});
if (credentials != null) {
TextInput usernameTextInput = (TextInput)sheetSerializer.getObjectByName("username");
TextInput passwordTextInput = (TextInput)sheetSerializer.getObjectByName("password");
usernameTextInput.setText(credentials.getUsername());
passwordTextInput.setText(credentials.getPassword());
}
sheet.getSheetStateListeners().add(new SheetStateListener() {
public Vote previewSheetClose(Sheet sheet, boolean result) {
return Vote.APPROVE;
}
public void sheetCloseVetoed(Sheet sheet, Vote reaso) {
// No-op
}
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
TextInput usernameTextInput = (TextInput)
sheetSerializer.getObjectByName("username");
TextInput passwordTextInput = (TextInput)
sheetSerializer.getObjectByName("password");
String username = usernameTextInput.getText();
String password = passwordTextInput.getText();
if (username.length() == 0 && password.length() == 0) {
credentials = null;
} else {
credentials = new Credentials(username, password);
}
}
}
});
sheet.open(window);
}
};
new Action("toggleHostnameVerificationAction") {
public String getDescription() {
return "Toggles lenient hostname verification";
}
public void perform() {
lenientHostnameVerification = !lenientHostnameVerification;
}
};
new Action("setKeystoreAction") {
private String keystorePath = null;
private String keystorePassword = null;
public String getDescription() {
return "Sets a trusted keystore";
}
public void perform() {
final WTKXSerializer sheetSerializer = new WTKXSerializer();
final Sheet sheet;
try {
sheet = (Sheet)sheetSerializer.readObject("pivot/tools/net/setKeystore.wtkx");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Button okButton = (Button)sheetSerializer.getObjectByName("okButton");
okButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
sheet.close(true);
}
});
Button cancelButton = (Button)sheetSerializer.getObjectByName("cancelButton");
cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
public void buttonPressed(Button button) {
sheet.close(false);
}
});
if (keystorePath != null) {
TextInput pathTextInput = (TextInput)sheetSerializer.getObjectByName("path");
pathTextInput.setText(keystorePath);
}
if (keystorePassword != null) {
TextInput passwdTextInput = (TextInput)sheetSerializer.getObjectByName("passwd");
passwdTextInput.setText(keystorePassword);
}
sheet.getSheetStateListeners().add(new SheetStateListener() {
public Vote previewSheetClose(Sheet sheet, boolean result) {
Vote vote = Vote.APPROVE;
if (result) {
TextInput pathTextInput = (TextInput)sheetSerializer.getObjectByName("path");
TextInput passwdTextInput = (TextInput)sheetSerializer.getObjectByName("passwd");
keystorePath = pathTextInput.getText();
keystorePassword = passwdTextInput.getText();
File file = new File(keystorePath);
if (!file.exists()
|| !file.isFile()) {
vote = Vote.DENY;
} else if (!file.canRead()) {
vote = Vote.DENY;
}
}
return vote;
}
public void sheetCloseVetoed(Sheet sheet, Vote reaso) {
// No-op
}
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
System.setProperty("javax.net.ssl.trustStore", keystorePath);
System.setProperty("javax.net.ssl.keyStorePassword", keystorePassword);
}
}
});
sheet.open(window);
}
};
// Load the main app window
serializer = new WTKXSerializer();