2015-02-03 2 views
1

svnkit 1.7.8을 사용하여 사용자가 입력 한 사용자 이름, 암호를 인증하려고합니다. 현재이 "인증"메서드에서 "DefaultAuthenticationManager"사용하고 있습니다. 내가 직면하고있는 문제는 잘못된 자격 증명을 입력해도 메서드가 오류를 throw하지 않고 코드 실행을 계속한다는 것입니다. Svn 인증 사용자 이름, Svn 키트를 사용한 암호

내 코드

..

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에서 로컬 머신으로 디렉토리를 체크 아웃하기위한 작업 코드가 이미 있습니다. 인증 부분에 대한 도움이 필요합니다.

+0

당신은'SVNRepository' 객체를 만들고, 그 위에 인증 드라이버를 설정 한 다음 버려두고 있습니다. 저장소를 어떻게 사용합니까? – Asa

+0

로컬 컴퓨터의 svn 디렉터리를 체크 아웃하는 데 사용하고 있습니다. 인증을 위해 위의 코드를 사용하고 있습니다. – Lucy

답변

3

제 의견에 언급했듯이 AuthmenticationManager으로 초기화 한 SVNRepository의 인스턴스를 버리고 있습니다.

당신이 기억하는 경우에 댓글을, 그리고 당신이 documentation을 읽고한다면, 그것은이 같은 것을 가지고 올 어렵지 않습니다이 answer :

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(..) 
+0

"DefaultAuthenticationManager"문제는 Windows 시스템에서 잘못된 자격 증명을 입력해도 자격 증명이 맞더라도 Linux 컴퓨터에서 코드 실행이 계속되는 경우입니다. 코드가 문제를 해결할 때까지? 질문에 내 노트를 참조하십시오 – Lucy

+0

@ DmitryPavlenko이 문제에 대한 해결책을 제안 해주시겠습니까 ?? – Lucy

1

다음 코드 스 니펫으로 테스트 할 수 있습니다. 동일한 문제에 직면했으며 이것이 수정 된 방법입니다.

사용 된 API :

svnkit-1.7.8.jar는

public boolean testSVNConnection(String svnURL,String svnUser,String svnPass){ 
DAVRepositoryFactory.setup(); 
String url="https://your_svn_host/path/"; 
String name="username"; 
String password="password"; 
SVNRepository repository = null; 
try { 
    repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url)); 
    ISVNAuthenticationManager authManager = 
        SVNWCUtil.createDefaultAuthenticationManager(name, password); 
    repository.setAuthenticationManager(authManager); 
    repository.testConnection(); 
    System.out.println("Connection done.."); 
    return true; 
} catch (SVNException e){ 
    System.out.println("Not connected"); 
    e.printStackTrace(); 
    return false; 
} 

} 

그냥 요구 사항에 따라 당신의 방법 서명을 변경합니다.