本文介绍了SVNKit使用auth文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SVNKit (1.8.4)来检索来自不同存储库,不同服务器和不同协议的日志(仅日志)。整个过程在 Tomcat 服务器上运行,并且每2分钟查询一次 SVN 服务器以进行更改。

I'm using SVNKit (1.8.4) to retrieve logs (only the logs) from different repositories, on different servers, with different protocols. The whole thing runs on a Tomcat server and is querying each SVN server every 2 minutes for changes.

经过大量的试验和错误,我想出了一个方案,我为每个 SVN 客户端实例创建了一个文件夹,所以它可以将所有凭证等存储在自己隔离的地方。

After a lot of trial and error, I came up with a scheme where I make a folder for each SVN client instance, so that it can store all the credentials etc. in its own isolated place.

这是创建 SVNRepository object:

Here's the relevant code that creates the SVNRepository object:

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仅用户内存凭据,不使用本地设置或配置文件。

I'd suggest to use lightweight BasicAuthenticationManager instance in place of DefaultSVNAuthenticationManager one. BasicAuthenticationManager only users in-memory credentials and doesn't use local settings or configuration files.

代码如下所示:

ISVNAuthenticationManager authManager =
  new BasicAuthenticationManager(new SVNAuthentication[] {
        new SVNPasswordAuthentication(userName, password,
                                      false, url, false),
  });
repository.setAuthenticationManager(authManager);

这篇关于SVNKit使用auth文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 19:35