public char[] askPassword() { char[] password = null; final JDialog dlg = new JDialog(frm, "Password", true); final JPasswordField jpf = new JPasswordField(15); final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")}; for (int i = 0; i < btns.length; i++) { btns[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dlg.setVisible(false); } }); } Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long"); System.exit(1); } return password; }
private void copyFile() throws Exception { // Load the JDBC driver Class.forName(((String) jcboDriver.getSelectedItem()).trim()); System.out.println("Driver loaded"); // Establish a connection Connection conn = DriverManager.getConnection( ((String) jcboURL.getSelectedItem()).trim(), jtfUsername.getText().trim(), String.valueOf(jtfPassword.getPassword()).trim()); System.out.println("Database connected"); // Read each line from the text file and insert it to the table insertRows(conn); }
/** * Parses the given http response. * * @param response the http response to parse * @return the new account */ private NewAccount parseHttpResponse(String response) { NewAccount newAccount = null; try { JSONObject jsonObject = (JSONObject) JSONValue.parseWithException(response); boolean isSuccess = (Boolean) jsonObject.get("success"); if (isSuccess) { newAccount = new NewAccount( (String) jsonObject.get("sip_address"), passField.getPassword(), null, (String) jsonObject.get("outbound_proxy")); String xcapRoot = (String) jsonObject.get("xcap_root"); // as sip2sip adds @sip2sip.info at the end of the // xcap_uri but doesn't report it in resullt after // creating account, we add it String domain = null; int delimIndex = newAccount.getUserName().indexOf("@"); if (delimIndex != -1) { domain = newAccount.getUserName().substring(delimIndex); } if (domain != null) { if (xcapRoot.endsWith("/")) xcapRoot = xcapRoot.substring(0, xcapRoot.length() - 1) + domain; else xcapRoot += domain; } newAccount.setXcapRoot(xcapRoot); } else { showErrorMessage((String) jsonObject.get("error_message")); } } catch (Throwable e1) { if (logger.isInfoEnabled()) logger.info("Failed Json parsing.", e1); } return newAccount; }
/** * Creates this account on the server. * * @return the created account */ public NewAccount createAccount() { // Check if the two passwords match. String pass1 = new String(passField.getPassword()); String pass2 = new String(retypePassField.getPassword()); if (!pass1.equals(pass2)) { showErrorMessage( IppiAccRegWizzActivator.getResources() .getI18NString("plugin.sipaccregwizz.NOT_SAME_PASSWORD")); return null; } NewAccount newAccount = null; try { StringBuilder registerLinkBuilder = new StringBuilder(registerLink); registerLinkBuilder .append(URLEncoder.encode("email", "UTF-8")) .append("=") .append(URLEncoder.encode(emailField.getText(), "UTF-8")) .append("&") .append(URLEncoder.encode("password", "UTF-8")) .append("=") .append(URLEncoder.encode(new String(passField.getPassword()), "UTF-8")) .append("&") .append(URLEncoder.encode("display_name", "UTF-8")) .append("=") .append(URLEncoder.encode(displayNameField.getText(), "UTF-8")) .append("&") .append(URLEncoder.encode("username", "UTF-8")) .append("=") .append(URLEncoder.encode(usernameField.getText(), "UTF-8")) .append("&") .append(URLEncoder.encode("user_agent", "UTF-8")) .append("=") .append(URLEncoder.encode("sip-communicator.org", "UTF-8")); URL url = new URL(registerLinkBuilder.toString()); URLConnection conn = url.openConnection(); // If this is not an http connection we have nothing to do here. if (!(conn instanceof HttpURLConnection)) { return null; } HttpURLConnection httpConn = (HttpURLConnection) conn; int responseCode = httpConn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String str; StringBuffer stringBuffer = new StringBuffer(); while ((str = in.readLine()) != null) { stringBuffer.append(str); } if (logger.isInfoEnabled()) logger.info("JSON response to create account request: " + stringBuffer.toString()); newAccount = parseHttpResponse(stringBuffer.toString()); } } catch (MalformedURLException e1) { if (logger.isInfoEnabled()) logger.info("Failed to create URL with string: " + registerLink, e1); } catch (IOException e1) { if (logger.isInfoEnabled()) logger.info("Failed to open connection.", e1); } return newAccount; }
protected Settings initSettings(String fileName) { // TODO Why try to load settings from current directory before using root? // This caused a bug in Eclipse: // https://sourceforge.net/tracker/?func=detail&atid=737763&aid=2620284&group_id=136013 File settingsFile = new File(fileName).exists() ? new File(fileName) : null; try { if (settingsFile == null) { settingsFile = new File(new File(getRoot()), DEFAULT_SETTINGS_FILE); if (!settingsFile.exists()) { settingsFile = new File(new File(System.getProperty("user.home", ".")), DEFAULT_SETTINGS_FILE); lastSettingsLoad = 0; } } else { settingsFile = new File(fileName); if (!settingsFile.getAbsolutePath().equals(this.settingsFile)) { lastSettingsLoad = 0; } } if (!settingsFile.exists()) { if (settingsDocument == null) { log.info("Creating new settings at [" + settingsFile.getAbsolutePath() + "]"); settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance(); setInitialImport(true); } lastSettingsLoad = System.currentTimeMillis(); } else if (settingsFile.lastModified() > lastSettingsLoad) { settingsDocument = SoapuiSettingsDocumentConfig.Factory.parse(settingsFile); byte[] encryptedContent = settingsDocument.getSoapuiSettings().getEncryptedContent(); if (encryptedContent != null) { char[] password = null; if (this.password == null) { // swing element -!! uh! JPasswordField passwordField = new JPasswordField(); JLabel qLabel = new JLabel("Password"); JOptionPane.showConfirmDialog( null, new Object[] {qLabel, passwordField}, "Global Settings", JOptionPane.OK_CANCEL_OPTION); password = passwordField.getPassword(); } else { password = this.password.toCharArray(); } String encryptionAlgorithm = settingsDocument.getSoapuiSettings().getEncryptedContentAlgorithm(); byte[] data = OpenSSL.decrypt( StringUtils.isNullOrEmpty(encryptionAlgorithm) ? "des3" : encryptionAlgorithm, password, encryptedContent); try { settingsDocument = SoapuiSettingsDocumentConfig.Factory.parse(new String(data, "UTF-8")); } catch (Exception e) { log.warn("Wrong password."); JOptionPane.showMessageDialog( null, "Wrong password, creating backup settings file [ " + settingsFile.getAbsolutePath() + ".bak.xml. ]\nSwitch to default settings.", "Error - Wrong Password", JOptionPane.ERROR_MESSAGE); settingsDocument.save(new File(settingsFile.getAbsolutePath() + ".bak.xml")); throw e; } } log.info("initialized soapui-settings from [" + settingsFile.getAbsolutePath() + "]"); lastSettingsLoad = settingsFile.lastModified(); if (settingsWatcher == null) { settingsWatcher = new SettingsWatcher(); SoapUI.getSoapUITimer().scheduleAtFixedRate(settingsWatcher, 10000, 10000); } } } catch (Exception e) { log.warn("Failed to load settings from [" + e.getMessage() + "], creating new"); settingsDocument = SoapuiSettingsDocumentConfig.Factory.newInstance(); lastSettingsLoad = 0; } if (settingsDocument.getSoapuiSettings() == null) { settingsDocument.addNewSoapuiSettings(); settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings()); initDefaultSettings(settings); } else { settings = new XmlBeansSettingsImpl(null, null, settingsDocument.getSoapuiSettings()); } this.settingsFile = settingsFile.getAbsolutePath(); if (!settings.isSet(WsdlSettings.EXCLUDED_TYPES)) { StringList list = new StringList(); list.add("schema@http://www.w3.org/2001/XMLSchema"); settings.setString(WsdlSettings.EXCLUDED_TYPES, list.toXml()); } if (settings .getString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1) .equals(HttpSettings.HTTP_VERSION_0_9)) { settings.setString(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1); } setIfNotSet(WsdlSettings.NAME_WITH_BINDING, true); setIfNotSet(WsdlSettings.NAME_WITH_BINDING, 500); setIfNotSet(HttpSettings.HTTP_VERSION, HttpSettings.HTTP_VERSION_1_1); setIfNotSet(HttpSettings.MAX_TOTAL_CONNECTIONS, 2000); setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true); setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true); setIfNotSet(UISettings.AUTO_SAVE_PROJECTS_ON_EXIT, true); setIfNotSet(UISettings.SHOW_DESCRIPTIONS, true); setIfNotSet(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true); setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true); setIfNotSet(UISettings.GC_INTERVAL, "60"); setIfNotSet(WsdlSettings.CACHE_WSDLS, true); setIfNotSet(WsdlSettings.PRETTY_PRINT_RESPONSE_MESSAGES, true); setIfNotSet(HttpSettings.RESPONSE_COMPRESSION, true); setIfNotSet(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, true); setIfNotSet(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, true); setIfNotSet(HttpSettings.LEAVE_MOCKENGINE, true); setIfNotSet(HttpSettings.START_MOCK_SERVICE, true); setIfNotSet(UISettings.AUTO_SAVE_INTERVAL, "0"); setIfNotSet(UISettings.GC_INTERVAL, "60"); setIfNotSet(UISettings.SHOW_STARTUP_PAGE, true); setIfNotSet(WsaSettings.SOAP_ACTION_OVERRIDES_WSA_ACTION, false); setIfNotSet(WsaSettings.USE_DEFAULT_RELATIONSHIP_TYPE, true); setIfNotSet(WsaSettings.USE_DEFAULT_RELATES_TO, true); setIfNotSet(WsaSettings.OVERRIDE_EXISTING_HEADERS, false); setIfNotSet(WsaSettings.ENABLE_FOR_OPTIONAL, false); setIfNotSet(VersionUpdateSettings.AUTO_CHECK_VERSION_UPDATE, true); if (!settings.isSet(ProxySettings.AUTO_PROXY) && !settings.isSet(ProxySettings.ENABLE_PROXY)) { settings.setBoolean(ProxySettings.AUTO_PROXY, true); settings.setBoolean(ProxySettings.ENABLE_PROXY, true); } boolean setWsiDir = false; String wsiLocationString = settings.getString(WSISettings.WSI_LOCATION, null); if (StringUtils.isNullOrEmpty(wsiLocationString)) { setWsiDir = true; } else { File wsiFile = new File(wsiLocationString); if (!wsiFile.exists()) { setWsiDir = true; } } if (setWsiDir) { String wsiDir = System.getProperty("wsi.dir", new File(".").getAbsolutePath()); settings.setString(WSISettings.WSI_LOCATION, wsiDir); } HttpClientSupport.addSSLListener(settings); return settings; }
public String getPassword() { return new String(pass.getPassword()); }
protected void enterLogin() { char[] password = m_passwordField.getPassword(); String strUser = (String) m_cmbUser.getSelectedItem(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); boolean blogin = WUserUtil.isOperatorNameok(strUser, false); if (blogin) { blogin = vnmrjPassword(strUser, password); if (!blogin) blogin = unixPassword(strUser, password); } if (blogin) { m_lblLogin.setForeground(Color.black); m_lblLogin.setText("Login Successful"); m_lblLogin.setVisible(true); // Get the Email column string for access to the operator data String emStr = vnmr.util.Util.getLabel("_admin_Email"); String stremail = WUserUtil.getOperatordata(strUser, emStr); // Get the Panel Level column string for access to the operator data String plStr = vnmr.util.Util.getLabel("_admin_Panel_Level"); String strPanel = WUserUtil.getOperatordata(strUser, plStr); if (stremail == null || stremail.equals("null")) stremail = ""; try { Integer.parseInt(strPanel); } catch (Exception e) { strPanel = WGlobal.PANELLEVEL; } m_trayTimer.stop(); Messages.postDebug(" Login: "******"appdir('reset','") .append(strUser) .append("','") .append(stremail) .append("',") .append(strPanel) .append(")") .toString()); exp.sendToVnmr("vnmrjcmd('util', 'bgReady')\n"); } setVisible(false); // Save the current position and size of this panel in case it // was changed Dimension size = getSize(); width = size.width; height = size.height; position = getLocation(); writePersistence(); // Call the macro to update this operator's // ExperimentSelector_operatorName.xml file // from the protocols themselves. This macro will // cause an update of the ES when it is finished // Util.getAppIF().sendToVnmr("updateExpSelector"); // I am not sure why we need to force updates since updateExpSelector // should have caused an update by writing to ES_op.xml file. // However, it works better if we do the force update. // ExpSelector.setForceUpdate(true); } else { m_lblLogin.setForeground(DisplayOptions.getColor("Error")); // m_lblLogin.setText("<HTML>Incorrect username/password <p> Please try again </HTML>"); m_lblLogin.setVisible(true); } setCursor(Cursor.getDefaultCursor()); }