CertInfoProducer { @Produces @Singleton public CertInfo produceCertInfo() { if (generateSelfCertificate.get()) { if (SwarmInfo.isProduct()) { throw SwarmMessages.MESSAGES.generateSelfSignedCertificateNotSupported(); } checkDataDir(); return new CertInfo(selfCertificateHost.get(), JBOSS_DATA_DIR); } else { String keystorePath = undertow.keystorePath(); if (embeddedKeystore.get()) { checkDataDir(); Path dataDir = Paths.get(System.getProperty(JBOSS_DATA_DIR)); Path certDestination = dataDir.resolve(keystorePath); try { URL jks = ClassLoader.getSystemClassLoader().getResource(keystorePath); if (jks == null) { Module appModule = Module.getCallerModuleLoader().loadModule("thorntail.application"); jks = appModule.getClassLoader().getResource(keystorePath); } if (jks == null) { throw new RuntimeException(String.format("Unable to locate embedded keystore %s in classpath", keystorePath)); } Files.copy(jks.openStream(), certDestination); keystorePath = certDestination.toString(); } catch (Exception ie) { throw new RuntimeException("Error copying embedded certificate", ie); } } String keystorePassword = undertow.keystorePassword(); String keyPassword = undertow.keyPassword(); String keystoreAlias = undertow.alias(); return new CertInfo(keystorePath, keystorePassword, keyPassword, keystoreAlias); } }  @Produces @Singleton CertInfo produceCertInfo(); static final String JBOSS_DATA_DIR; }
@Test public void testDefaults() { CertInfoProducer producer = new CertInfoProducer(); producer.undertow = new UndertowFraction(); CertInfo certInfo = producer.produceCertInfo(); assertThat(certInfo).isNotNull(); assertThat( certInfo.generateSelfSignedCertificateHost()).isNull(); }
@Test @Category(CommunityOnly.class) public void testGenerateWithDefaults() { CertInfoProducer producer = new CertInfoProducer(); producer.undertow = new UndertowFraction(); producer.generateSelfCertificate.set(true); CertInfo certInfo = producer.produceCertInfo(); assertThat(certInfo).isNotNull(); assertThat( certInfo.generateSelfSignedCertificateHost()).isEqualTo( "localhost" ); }
@Test @Category(CommunityOnly.class) public void testGenerateWithExplicitHost() { CertInfoProducer producer = new CertInfoProducer(); producer.undertow = new UndertowFraction(); producer.generateSelfCertificate.set(true); producer.selfCertificateHost.set( "www.mycorp.com" ); CertInfo certInfo = producer.produceCertInfo(); assertThat(certInfo).isNotNull(); assertThat( certInfo.generateSelfSignedCertificateHost()).isEqualTo( "www.mycorp.com" ); }