in log4j-catalog/log4j-catalog-editor/src/main/java/org/apache/logging/log4j/catalog/config/WebMvcAppContext.java [168:251]
public CatalogDao catalogDao() {
GitCatalogDao dataSource = new GitCatalogDao();
if (isNotBlank(gitUserName) && isNotBlank(gitPassword)) {
dataSource.setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitUserName, gitPassword));
}
if (isNotBlank(remoteRepoUrl)) {
try {
URI uri = new URI(remoteRepoUrl);
if (uri.getScheme().equalsIgnoreCase("SSH")) {
TransportConfigCallback transportConfigCallback = new TransportConfigCallback() {
final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected JSch createDefaultJSch( FS fs ) throws JSchException {
JSch defaultJSch = super.createDefaultJSch( fs );
if (isNotBlank(privateKeyPath)) {
defaultJSch.addIdentity(privateKeyPath);
}
return defaultJSch;
}
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
if (isNotBlank(gitPassPhrase)) {
session.setUserInfo(new UserInfo() {
@Override
public String getPassphrase() {
return gitPassPhrase;
}
@Override
public String getPassword() {return null;}
@Override
public boolean promptPassword(String message) {return false;}
@Override
public boolean promptPassphrase(String message) {return true;}
@Override
public boolean promptYesNo(String message) {return false;}
@Override
public void showMessage(String message) {}
});
}
}
};
@Override
public void configure(Transport transport) {
SshTransport sshTransport = ( SshTransport )transport;
sshTransport.setSshSessionFactory( sshSessionFactory );
}
};
dataSource.setTransportConfigCallback(transportConfigCallback);
}
} catch (URISyntaxException ex) {
LOGGER.error("Invalid URI {}:", remoteRepoUrl, ex);
}
} else {
LOGGER.error("No remote repo URL provided.");
}
if (isNotBlank(branch)) {
dataSource.setBranch(branch);
}
if (isNotBlank(localRepoUrl)) {
dataSource.setLocalRepoPath(localRepoUrl);
} else {
String localRepoPath = System.getProperty("java.io.tmpdir") + "/audit/catalog";
File file = new File(localRepoPath);
File parent = file.getParentFile();
parent.mkdirs();
dataSource.setLocalRepoPath(localRepoPath);
}
dataSource.setRemoteRepoUri(remoteRepoUrl);
if (isNotBlank(remoteRepoCatalogPath)) {
dataSource.setCatalogPath(remoteRepoCatalogPath);
}
return dataSource;
}