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.

2
  • You are creating an SVNRepository object, setting an authentication driver on that, and then throwing it away. How do you use the repository? Commented Feb 3, 2015 at 11:49
  • I'm using it to checkout a svn directory in my local machine. For authentication i'm using the above code. Commented Feb 3, 2015 at 12:00

2 Answers 2

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(..)
Sign up to request clarification or add additional context in comments.

2 Comments

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
@ DmitryPavlenko Could you please suggest a solution to this problem??
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.