StringUtils { public static String sanitizeDbUri(String uri) { String result = uri; Matcher m = ORA_JDBC_URI_PATTERN.matcher(uri); if (m.matches()) { result = m.group(1) + "*/*" + m.group(4); } else if (uri.startsWith("jdbc:mysql:")) { Matcher m1 = MYSQL_JDBC_PATTERN1.matcher(result); Matcher m2 = MYSQL_JDBC_PATTERN2.matcher(result); if (m1.find()) { result = m1.replaceAll("($1*)"); } else if (m2.find()) { result = m2.replaceAll("$1*"); } } return result; }  static String bytesToString(byte[] bytes); static Reader createFileReader(File file); static Reader createFileReader(String fileName); static Writer createFileWriter(File file); static Writer createFileWriter(String fileName); static String hexdumpByteBufferContents(ByteBuffer buf, int bufOfs, int length); static String sanitizeDbUri(String uri); static final String DEFAULT_ENCODING_NAME; static final Charset DEFAULT_CHARSET; }
@Test public void testSanitizeDbUri() { String s = StringUtils.sanitizeDbUri("jdbc:oracle:thin:uSeR/p4ssw0rd@db.company.com:1521/SCHEMA"); Assert.assertEquals(s, "jdbc:oracle:thin:**@(DESCRIPTION=(LOAD_BALANCE=on)(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP)(HOST=db1.host.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=db2.host.com)(PORT=1521))(CONNECT_DATA=(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)(RETRIES=180)(DELAY=5))))"); s = StringUtils.sanitizeDbUri("jdbc:mysql: Assert.assertEquals(s, "jdbc:mysql: s = StringUtils.sanitizeDbUri("jdbc:mysql: Assert.assertEquals(s, "jdbc:mysql: s = StringUtils.sanitizeDbUri("jdbc:MySqL: Assert.assertEquals(s, "jdbc:MySqL: }