How to store, update and use credentials?

Dear all,
I’m writing a script for which I need to provide some sort of authentication capabilities. I thought that using svnkit for this purpose would be ideal as - to my understanding - it can use SVN credentials and also store them to disk. Sadly It appears I’m unable to understand how svnkit works.

Can someone be so kind and help me out with code snippets that are capable of storing credentials, updating them and actually using them?

After reading the documentation, I tried to write code for storing credentials and came up with this:

SVNWCUtil.createDefaultAuthenticationManager(new File("path/to/where/i/want/credentials"), "username", "password".toCharArray(), true)

However, the behavior of this code is different between svnkit 1.10.2 and 1.8.9. For the older version, there actually is an svn file structure created on disk, however without any credential files. For the newer version there is no file structure.

At the same time, if I try to get back the credentials using this code:

SVNPasswordAuthentication svnCredentials = SVNWCUtil.createDefaultAuthenticationManager(new File("path/to/where/i/want/credentials"), "username", "password".toCharArray(), true).getFirstAuthentication(ISVNAuthenticationManager.PASSWORD, 'some_authentication_realm', SVNURL.parseURIEncoded('some_svn_url'))

I can easily print the credentials regardless of svnkit version using:

println svnCredentials.userName
println svnCredentials.passwordValue

So It would seem the credentials do get created in memory, but do not get stored despite using storeAuth=true

Thank you in advance for your time and effort :)

Hello,
you’re absolutely right, this snippet is correct:

SVNWCUtil.createDefaultAuthenticationManager(new File("path/to/where/i/want/credentials"), "username", "password".toCharArray(), true)

You can also have a look at ‘jsvn’ command line utility, at SVNCommandEnvironment#createClientAuthenticationManager method. It implements the same behaviour as native ‘svn’.

However, the behavior of this code is different between svnkit 1.10.2 and 1.8.9. For the older version, there actually is an svn file structure created on disk, however without any credential files. For the newer version there is no file structure.

That’s strange, I don’t remember changing anything in this logic between these two versions. Do you have a possibility to set breakpoints? If yes, set one at
DefaultSVNPersistentAuthenticationProvider#saveAuthentication

It’s the place where credentials are saved. Probably this should explain why the credentials are not saved in your case.

Dmitry,
thank you for your response. I’m not sure about the breakpoints. I never needed to write anything that would require using them for debugging.

The script is written in groovy and I’m using IntelliJ Idea to write it and execute it for testing. I do have a breakpoint option but I’m merely including svnkit as a jar in my project, not adding the whole source code. Also, the script is just run, not compiled, so I’m not sure if I can simply open up a file from the jar in the editor and search for what you have suggested. Any suggestions?

Edit:
I think I got it - I navigated through the project structure in intellij, went to svnkit.jar > org.tmatesoft.svn>core>internal>wc>DefaultSVNPersistentAuthenticationProvider and opened the saveAuthentication method. Then I put a breakpoint in the line where saveAuthentication starts:

public void saveAuthentication(SVNAuthentication auth, String kind, String realm) throws SVNException {

Sadly the code snippet you said is propper, did not reach this breakpoint