Skip to content
Snippets Groups Projects
Commit 7ba4af30 authored by Barbara B. Frosik's avatar Barbara B. Frosik
Browse files

modified ExperimentSync tools to work with java 7

parent 5310fb5e
No related branches found
No related tags found
No related merge requests found
......@@ -189,13 +189,13 @@ class ExperimentList extends JFrame
private ExperimentTableModel tableModel = null;
private JScrollPane scrollPane;
ExperimentList(String sector, OracleConnection oconnection, StorageServiceConnection sconnection, DaqServiceConnection dconnection) {
ExperimentList(final String sector, final OracleConnection oconnection, final StorageServiceConnection sconnection, final DaqServiceConnection dconnection) {
this.sconnection = sconnection;
setTitle("Experiment Import");
setSize(1000, 500);
setBackground(Color.gray);
JPanel topPanel = new JPanel();
final JPanel topPanel = new JPanel();
topPanel.setBorder(BorderFactory.createLoweredSoftBevelBorder());
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
......@@ -203,7 +203,7 @@ class ExperimentList extends JFrame
JPanel entryPanel = new JPanel(new FlowLayout());
topPanel.add(entryPanel, BorderLayout.NORTH);
JLabel entryLabel = new JLabel("Enter date range of experiment start date");
final JLabel entryLabel = new JLabel("Enter date range of experiment start date");
entryPanel.add(entryLabel);
UtilDateModel startModel = new UtilDateModel();
......@@ -212,28 +212,28 @@ class ExperimentList extends JFrame
p.put("text.month", "Month");
p.put("text.year", "Year");
JDatePanelImpl startDatePanel = new JDatePanelImpl(startModel, p);
JDatePickerImpl startDatePicker = new JDatePickerImpl(startDatePanel, new DateLabelFormatter());
final JDatePickerImpl startDatePicker = new JDatePickerImpl(startDatePanel, new DateLabelFormatter());
entryPanel.add(startDatePicker);
UtilDateModel endModel = new UtilDateModel();
JDatePanelImpl endDatePanel = new JDatePanelImpl(endModel, p);
JDatePickerImpl endDatePicker = new JDatePickerImpl(endDatePanel, new DateLabelFormatter());
final JDatePickerImpl endDatePicker = new JDatePickerImpl(endDatePanel, new DateLabelFormatter());
entryPanel.add(endDatePicker);
JButton submitDatesBtn = new JButton("click to get experiments list");
final JButton submitDatesBtn = new JButton("click to get experiments list");
entryPanel.add(submitDatesBtn);
JPanel selectPanel = new JPanel(new FlowLayout());
topPanel.add(selectPanel, BorderLayout.SOUTH);
JButton submitSelectionBtn = new JButton("select experiments and click the button to import");
final JButton submitSelectionBtn = new JButton("select experiments and click the button to import");
selectPanel.add(submitSelectionBtn);
submitSelectionBtn.setVisible(false);
JButton submitSelectionStartExpBtn = new JButton("select experiments and click the button to import and start");
final JButton submitSelectionStartExpBtn = new JButton("select experiments and click the button to import and start");
selectPanel.add(submitSelectionStartExpBtn);
submitSelectionStartExpBtn.setVisible(false);
submitDatesBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
......@@ -244,7 +244,7 @@ class ExperimentList extends JFrame
submitSelectionStartExpBtn.setVisible(true);
DateLabelFormatter df = new DateLabelFormatter();
Date startSelectedDate = (Date) startDatePicker.getModel().getValue();
final Date startSelectedDate = (Date) startDatePicker.getModel().getValue();
String start = df.valueToString(startSelectedDate);
Date endSelectedDate = (Date) endDatePicker.getModel().getValue();
String end = df.valueToString(endSelectedDate);
......@@ -302,7 +302,7 @@ class ExperimentList extends JFrame
// addRole((String)table.getModel().getValueAt(selection[i], Column.PI.ordinal()), experimentName, Role.PI);
addRole((String)table.getModel().getValueAt(selection[i], Column.USER.ordinal()), experimentName, Role.USER);
if (sconnection.startExperiment(experimentName) == ServiceConnection.ServiceConnectionStatus.SUCCESS) {
// dconnection.startDaq(experimentName, experimentName);
dconnection.startDaq(experimentName, experimentName);
} else {
System.out.println("didn't start");
}
......
......@@ -22,7 +22,7 @@ class Gui
{
String configFile = arg[0];
Properties configProperties = new Properties();
final Properties configProperties = new Properties();
setConfig(configFile, configProperties);
SwingUtilities.invokeLater(new Runnable() {
......@@ -33,16 +33,16 @@ class Gui
}
private Gui(Properties configProperties) {
System.setProperty("javax.net.ssl.trustStore", configProperties.getProperty("dm.truststore"));
// System.setProperty("javax.net.ssl.trustStore", configProperties.getProperty("dm.truststore"));
OracleConnection oconnection = new OracleConnection();
final OracleConnection oconnection = new OracleConnection();
try {
oconnection.connect(configProperties);
} catch (SQLException e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
System.exit(0);
}
StorageServiceConnection sconnection = new StorageServiceConnection();
final StorageServiceConnection sconnection = new StorageServiceConnection();
if (sconnection.init(configProperties.getProperty("dm.storageServ.connection")) != ServiceConnection.ServiceConnectionStatus.SUCCESS) {
System.exit(0);
}
......
......@@ -17,7 +17,7 @@ public final class LoginWindow extends JFrame {
OracleConnection oconnection;
JPanel panel;
LoginWindow(StorageServiceConnection sconnection, OracleConnection oconnection, DaqServiceConnection dconnection) {
LoginWindow(final StorageServiceConnection sconnection, final OracleConnection oconnection, final DaqServiceConnection dconnection) {
this.sconnection = sconnection;
this.oconnection = oconnection;
......@@ -30,7 +30,7 @@ public final class LoginWindow extends JFrame {
userLabel.setBounds(10, 10, 80, 25);
panel.add(userLabel);
JTextField userText = new JTextField(20);
final JTextField userText = new JTextField(20);
userText.setBounds(100, 10, 160, 25);
panel.add(userText);
......@@ -38,7 +38,7 @@ public final class LoginWindow extends JFrame {
passwordLabel.setBounds(10, 40, 80, 25);
panel.add(passwordLabel);
JPasswordField passwordText = new JPasswordField(20);
final JPasswordField passwordText = new JPasswordField(20);
passwordText.setBounds(100, 40, 160, 25);
panel.add(passwordText);
......@@ -46,7 +46,7 @@ public final class LoginWindow extends JFrame {
sectorLabel.setBounds(10, 70, 80, 25);
panel.add(sectorLabel);
JTextField sectorText = new JTextField(20);
final JTextField sectorText = new JTextField(20);
sectorText.setBounds(100, 70, 160, 25);
panel.add(sectorText);
......
package gov.anl.dm.esafsync.serviceconn;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
/**
* Dummy trust manager class.
*
* A trivial implementation of <code>X509TrustManager</code> that doesn't
* actually check the validity of a certificate. This allows us to make SSL
* connections to internal servers without requiring the installation and
* maintenance of certificates in the client keystore.
*
* @see NoServerVerificationSSLSocketFactory
*/
public class NoOpTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] cert, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] cert, String authType) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
package gov.anl.dm.esafsync.serviceconn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
/**
* SSL socket factory that does not verify server credentials.
*
* A minor extension of <code>SSLSocketFactory</code> that installs a dummy
* trust manager. This allows creation of SSL sockets that don't verify the
* server certificates.
*
* @see NoOpTrustManager
*/
public class NoServerVerificationSSLSocketFactory extends SSLSocketFactory {
private SSLSocketFactory factory;
/**
* Default constructor.
*/
public NoServerVerificationSSLSocketFactory() {
try {
TrustManager tm = new NoOpTrustManager();
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, // No KeyManager required
new TrustManager[]{tm},
new java.security.SecureRandom());
factory = (SSLSocketFactory) sslcontext.getSocketFactory();
} catch (KeyManagementException | NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
}
/**
* Get default (no server verification) socket factory.
*
* @return socket factory
*/
public static SocketFactory getDefault() {
return new NoServerVerificationSSLSocketFactory();
}
/**
* Create SSL socket layered over an existing socket connected to the named
* host, at a given port.
*
* @param socket existing socket
* @param host
* @param port
* @param autoClose
* @return created socket
* @throws IOException in case of IO errors
*/
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
throws IOException {
return factory.createSocket(socket, host, port, autoClose);
}
/**
* Create a socket and connect it to the specified remote address/port, and
* bind it to the specified local address/port.
*
* @param address server network address
* @param port server port
* @param localAddress client network address
* @param localPort client port
* @return created socket
* @throws IOException in case of IO errors
*/
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
throws IOException {
return factory.createSocket(address, port, localAddress, localPort);
}
/**
* Create a socket and connect it to the specified remote address/port.
*
* @param address server network address
* @param port server port
* @return created socket
* @throws IOException in case of IO errors
*/
@Override
public Socket createSocket(InetAddress address, int port) throws IOException {
return factory.createSocket(address, port);
}
/**
* Create a socket and connect it to the specified remote host/port, and
* bind it to the specified local address/port.
*
* @param host server host
* @param port server port
* @param localAddress client network address
* @param localPort client port
* @return created socket
* @throws IOException in case of IO errors
*/
@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
throws IOException {
return factory.createSocket(host, port, localAddress, localPort);
}
/**
* Create a socket and connect it to the specified remote host/port, and
* bind it to the specified local address/port.
*
* @param host server host
* @param port server port
* @return created socket
* @throws IOException in case of IO errors
*/
@Override
public Socket createSocket(String host, int port) throws IOException {
return factory.createSocket(host, port);
}
/**
* Get default cipher suites from socket factory.
*
* @return list of default ciphers
*/
@Override
public String[] getDefaultCipherSuites() {
return factory.getSupportedCipherSuites();
}
/**
* Get supported cipher suites from socket factory.
*
* @return list of supported ciphers
*/
@Override
public String[] getSupportedCipherSuites() {
return factory.getSupportedCipherSuites();
}
}
......@@ -10,9 +10,11 @@ import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Base64;
// import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.DatatypeConverter;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.JOptionPane;
......@@ -116,8 +118,8 @@ public class ServiceConnection {
return ServiceConnectionStatus.ERROR;
}
// System.setProperty("javax.net.ssl.trustStore", "/etc/pki/ca-trust/extracted/java/cacerts");
HttpsURLConnection.setDefaultSSLSocketFactory(new NoServerVerificationSSLSocketFactory());
return ServiceConnectionStatus.SUCCESS;
}
......@@ -327,12 +329,41 @@ public class ServiceConnection {
}
}
protected String encode(String s) {
byte[] encoded1 = Base64.getEncoder().encode(s.getBytes());
String encoded2 = Base64.getEncoder().encodeToString(encoded1);
return encoded2;
}
// // this method works with java 8 java.util.Base64
// protected String encode(String s) {
// byte[] encoded1 = Base64.getEncoder().encode(s.getBytes());
// String encoded2 = Base64.getEncoder().encodeToString(encoded1);
// return encoded2;
// }
public static String encode(String input) {
try {
// Input is twice encoded in order to avoid issues like
// '+' being interpreted as space
if (input == null) {
return input;
}
String s1 = DatatypeConverter.printBase64Binary(input.getBytes());
String s2 = DatatypeConverter.printBase64Binary(s1.getBytes());
return s2;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
// public static String decode(String input) {
// try {
// // Input is twice encoded in order to avoid issues like
// // '+' being interpreted as space
// byte[] ba1 = DatatypeConverter.parseBase64Binary(input);
// byte[] ba2 = DatatypeConverter.parseBase64Binary(new String(ba1));
// return new String(ba2);
// } catch (Exception ex) {
// ex.printStackTrace();
// return null;
// }
// }
// private String verifySessionCookie() {
// return session.verifyCookie();
// }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment