protected static KeyManager[] createKeyManagers() throws NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, FileNotFoundException, IOException, CertificateException, UnrecoverableKeyException, URISyntaxException { KeyStore ks = KeyStore.getInstance(DEFAULT_CETRS_STORE_TYPE); // get user password and file input stream char[] password = DEFAULT_KEYSTORE_PASSWORD.toCharArray(); File keyStoreFile = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY, "keystore")); if (!keyStoreFile.exists()) { File keyPath = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY)); keyPath.mkdirs(); keyStoreFile.createNewFile(); try (OutputStream keyOut = new FileOutputStream(keyStoreFile); InputStream keyIn = PlatypusConnection.class.getResourceAsStream("defaultKeystore")) { byte[] resData = BinaryUtils.readStream(keyIn, -1); keyOut.write(resData); } } if (keyStoreFile.exists()) { try (InputStream is = new FileInputStream(keyStoreFile)) { ks.load(is, password); } final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); keyManagerFactory.init(ks, password); return keyManagerFactory.getKeyManagers(); } else { throw new FileNotFoundException(KEYSTORE_MISING_MSG); } }
public static String v(Object aValue) throws Exception { if (aValue != null) { if (aValue instanceof Boolean) { return aValue.toString(); } else if (aValue instanceof Number) { return StringUtils.formatDouble(((Number) aValue).doubleValue()); } else if (aValue instanceof String) { return JsonUtils.s((String) aValue).toString(); } else if (aValue instanceof Date) { SimpleDateFormat sdf = new SimpleDateFormat(RowsetJsonConstants.DATE_FORMAT); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return JsonUtils.s(sdf.format((Date) aValue)).toString(); } else { throw new Exception("Value of unknown or unsupported type found! It's class is: " + aValue.getClass().getName()); } } else { return "null"; } }
if (value != null) { try (Reader reader = ((Clob) value).getCharacterStream()) { value = StringUtils.readReader(reader, -1); if (value != null) { try (Reader reader = ((NClob) value).getCharacterStream()) { value = StringUtils.readReader(reader, -1);
private int riddleStatements(List<StatementsGenerator.StatementsLogEntry> aStatements, Connection aConnection) throws Exception { int rowsAffected = 0; if (!aStatements.isEmpty()) { List<StatementsGenerator.StatementsLogEntry> errorStatements = new ArrayList<>(); List<String> errors = new ArrayList<>(); for (StatementsGenerator.StatementsLogEntry entry : aStatements) { try { rowsAffected += entry.apply(aConnection); } catch (Exception ex) { errorStatements.add(entry); errors.add(ex.getMessage()); Logger.getLogger(DatabasesClient.class.getName()).log(Level.WARNING, ex.getMessage()); } } if (errorStatements.size() == aStatements.size()) { throw new SQLException(StringUtils.join(System.getProperty(ClientConstants.LINE_SEPARATOR_PROP_NAME), errors.toArray(new String[]{}))); } else if (errorStatements.size() < aStatements.size()) { rowsAffected += riddleStatements(errorStatements, aConnection); } } return rowsAffected; }
protected static TrustManager[] createTrustManagers() throws NoSuchAlgorithmException, NoSuchProviderException, KeyStoreException, FileNotFoundException, IOException, CertificateException, URISyntaxException { KeyStore ks = KeyStore.getInstance(DEFAULT_CETRS_STORE_TYPE); char[] password = getTrustStorePassword(); File trustStore = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY, "truststore")); if (!trustStore.exists()) { File trustPath = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY)); trustPath.mkdirs(); trustStore.createNewFile(); try (OutputStream trustOut = new FileOutputStream(trustStore); InputStream trustIn = PlatypusConnection.class.getResourceAsStream("emptyTruststore")) { byte[] resData = BinaryUtils.readStream(trustIn, -1); trustOut.write(resData); } } if (trustStore.exists()) { try (InputStream is = new FileInputStream(trustStore)) { ks.load(is, password); } final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(DEFAULT_TRUST_ALGORITHM); trustManagerFactory.init(ks); return wrapTrustManagers(ks, trustManagerFactory.getTrustManagers()); } else { throw new FileNotFoundException(TRUSTSTORE_MISSING_MSG); } }
String tokensStr = StringUtils.join(" ", tokens) + rightPadding; if (!"*".equals(tokensStr.trim())) { list.add(tokensStr); list.add(list.size() > 2 ? 2 : 1, " * " + aAnnotationName + " " + aValue); //NOI18N docComment = StringUtils.join(System.getProperty(ClientConstants.LINE_SEPARATOR_PROP_NAME), list.toArray(new String[]{})); //NOI18N return matcher.replaceFirst(docComment); list.add(" * " + aAnnotationName + " " + aValue); //NOI18N list.add(" */" + System.getProperty(ClientConstants.LINE_SEPARATOR_PROP_NAME)); //NOI18N String docComment = StringUtils.join(System.getProperty(ClientConstants.LINE_SEPARATOR_PROP_NAME), list.toArray(new String[]{})); return docComment + aContent;
File trustStore = new File(StringUtils.join(File.separator, System.getProperty(ClientConstants.USER_HOME_PROP_NAME), ClientConstants.USER_HOME_PLATYPUS_DIRECTORY_NAME, SECURITY_SUBDIRECTORY, "truststore")); if (trustStore.exists()) { try (FileOutputStream out = new FileOutputStream(trustStore)) {