gpt4 book ai didi

java - Svn 身份验证用户名,密码使用 Svn Kit

转载 作者:行者123 更新时间:2023-11-29 03:13:00 26 4
gpt4 key购买 nike

我正在尝试验证用户使用 svnkit 1.7.8 输入的用户名和密码。目前我在方法“authenticate”中使用“DefaultAuthenticationManager”来实现这一点。我面临的问题是,即使我输入了不正确的凭据,该方法也不会抛出任何错误并继续执行代码。

我的代码..

 private void authenticate(String user, String password) throws SVNException {
SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(baseUrl));
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);
repository.setAuthenticationManager(authManager);
}

此错误是由于使用“DefaultAuthenticationManager”而不是“BasicAuthenticationManager”引起的吗??请帮忙

注意:

我正在从 https url 检查一个 svn 目录。我已经有了从 SVN check out 目录到本地机器的工作代码,只需要身份验证部分的帮助。

最佳答案

正如我在评论中提到的,您正在丢弃使用 AuthmenticationManager 初始化的 SVNRepository 实例。

如果你还记得这个answer你评论过的,如果你读过 documentation , 想出这样的东西并不难:

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);
svnOperationFactory.setAuthenticationManager(authManager);

try {
final SvnCheckout checkout = svnOperationFactory.createCheckout();
checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
checkout.setSource(SvnTarget.fromURL(url));
//... other options
checkout.run();
} finally {
svnOperationFactory.dispose();
}

编辑:如果你真的需要使用 SVNRepository

只是做:

SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(baseUrl));
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(user, password);
repository.setAuthenticationManager(authManager);

// now do any operation that you want with the *same* repository object
repository.checkout(..)

关于java - Svn 身份验证用户名,密码使用 Svn Kit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28298047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com