@Test public void resolvePath() throws IOException { try { SecuritySupport.resolvePath("classpath:cer"); fail("exception expected for unknown classpath"); } catch (Exception ignored) { } try { SecuritySupport.resolvePath("file: fail("exception expected for file uri component"); } catch (Exception ignored) { } try { SecuritySupport.resolvePath("file: fail("exception expected for missing path"); } catch (Exception ignored) { } Path pathC = SecuritySupport.resolvePath("classpath:certs"); assertTrue(pathC != null); String fPath = "file: Path pathF = SecuritySupport.resolvePath(fPath); assertTrue(pathF != null); }
@VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new NakadiException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (isClasspath(certificatePath)) { logger.info("using classpath resolver for {}", certificatePath); return Paths.get(getResourceUrl(classpathBareName(certificatePath)).getPath()); } throw new NakadiException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); }
SecuritySupport { @VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new NakadiException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (isClasspath(certificatePath)) { logger.info("using classpath resolver for {}", certificatePath); return Paths.get(getResourceUrl(classpathBareName(certificatePath)).getPath()); } throw new NakadiException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); } }
SecuritySupport { @VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new NakadiException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (isClasspath(certificatePath)) { logger.info("using classpath resolver for {}", certificatePath); return Paths.get(getResourceUrl(classpathBareName(certificatePath)).getPath()); } throw new NakadiException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); } SecuritySupport(String certificatePath); }
SecuritySupport { @VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new NakadiException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (isClasspath(certificatePath)) { logger.info("using classpath resolver for {}", certificatePath); return Paths.get(getResourceUrl(classpathBareName(certificatePath)).getPath()); } throw new NakadiException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); } SecuritySupport(String certificatePath); SSLContext sslContext(); X509TrustManager trustManager(); }
SecuritySupport { @VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new NakadiException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (isClasspath(certificatePath)) { logger.info("using classpath resolver for {}", certificatePath); return Paths.get(getResourceUrl(classpathBareName(certificatePath)).getPath()); } throw new NakadiException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); } SecuritySupport(String certificatePath); SSLContext sslContext(); X509TrustManager trustManager();  }