1

I'm trying to authenticate username, password entered by the user using svnkit 1.7.8. Currently I'm using "DefaultAuthenticationManager" in method "authenticate" to achieve this. The problem I'm facing is that even when i enter incorrect credentials the method doesn't throw any errors and continues with code execution.

My code..

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

Is this error due to usage of "DefaultAuthenticationManager" instead of "BasicAuthenticationManager" ?? Please Help

NOTE:

I'm checking out a svn directory from https url. I already have the working code for checking out a directory from SVN to local machine, Just need help with the Authentication part.

Lucy
  • 1,812
  • 15
  • 55
  • 93
  • You are creating an `SVNRepository` object, setting an authentication driver on that, and then throwing it away. How do you use the repository? – Asa Feb 03 '15 at 11:49
  • I'm using it to checkout a svn directory in my local machine. For authentication i'm using the above code. – Lucy Feb 03 '15 at 12:00

2 Answers2

3

As I mentioned in my comment, you are throwing away the instance of the SVNRepository that you have initialized with the AuthmenticationManager.

If you remember this answer that you commented on, and if you would have read the documentation, it's not hard to come up with something like this:

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

EDIT: If you really need to use the SVNRepository

just do:

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(..)
Community
  • 1
  • 1
Asa
  • 1,624
  • 15
  • 19
  • The problem i'm facing with "DefaultAuthenticationManager" is that even when i enter wrong credentials on windows machine the code execution continues while it stops on linux machine even if the credentials are correct..Will your code solve the problem? Please see my note in the question – Lucy Feb 03 '15 at 12:21
  • @ DmitryPavlenko Could you please suggest a solution to this problem?? – Lucy Mar 23 '15 at 14:11
1

You can test with below code snippet: I was facing the same issue and this is how I fixed.

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

}

Just change your method signature as per requirement.

MonsterJava
  • 423
  • 7
  • 23