我正在使用 SVNKit
(1.8.4) 从不同的存储库、不同的服务器上、使用不同的协议(protocol)检索日志(仅日志)。整个过程在 Tomcat
服务器上运行,并且每 2 分钟查询一次每个 SVN
服务器以进行更改。
经过反复试验,我想出了一个方案,我为每个 SVN
客户端实例创建一个文件夹,这样它就可以将所有凭据等存储在自己独立的地方.
下面是创建 SVNRepository
对象的相关代码:
SVNRepository getRepository(String url,
String authFolder,
String username,
String password)
throws SVNException {
SVNRepository repository =
SVNRepositoryFactory.create( SVNURL.parseURIEncoded(url) );
ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager(
authFolder, username, password, true);
repository.setAuthenticationManager(authManager);
return repository;
}
有更好的方法吗?
最佳答案
我建议使用轻量级 BasicAuthenticationManager 实例代替 DefaultSVNAuthenticationManager 实例。 BasicAuthenticationManager 仅使用内存中的凭据,不使用本地设置或配置文件。
代码看起来像这样:
ISVNAuthenticationManager authManager =
new BasicAuthenticationManager(new SVNAuthentication[] {
new SVNPasswordAuthentication(userName, password,
false, url, false),
});
repository.setAuthenticationManager(authManager);
关于java - SVNKit 使用 auth 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24403997/