SVNKit use of auth folder

2019-06-04 07:19发布

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.

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.

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;
}

Is there a better way to do this?

标签: java svnkit
1条回答
戒情不戒烟
2楼-- · 2019-06-04 07:44

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.

The code would look like that:

ISVNAuthenticationManager authManager = 
  new BasicAuthenticationManager(new SVNAuthentication[] {
        new SVNPasswordAuthentication(userName, password, 
                                      false, url, false),
  });
repository.setAuthenticationManager(authManager);
查看更多
登录 后发表回答