Hello Daniel,

> The repositories contains two differents evolutions  of the ProjectX, so i
> want to do a diff of a fileX1 from svn1 to a fileX2 from svn2. In order to
> do this, i have to provide two credentials for my authentication manager
> (one for svn1 and other for svn2), right?
>
> Then i could do the following:
>
> SvnOperationFactory opF = new SvnOperationFactory();
>
> opF.setAuthenticationManager(<here my authentication manager with two
> credentials>)

When asked for credentials, SVNKit calls its ISVNAuthenticationManager
object that is responsible for providing credentials. There are two
built-in implementation of ISVNAuthenticationManager and of course you
may implement your own.

First and most frequently used is DefaultSVNAuthenticationManager - it
supports credentials caching and user's credentials callback
(ISVNAuthenticationProvider). It works like this:

1) First it attempts to use explicitly configured credentials
2) Then, if there are none or if explicit credentials have been
rejected, it looks for credentials in runtime storage
3) Then, if there are none or if in-memory cached credentials have
been rejected, it looks in on-disk credentials cache
4) Finally, if there are none on disk or on-disk cached credentials
have been rejected, it calls users ISVNAuthenticationProvider (if
set); provider may return "null" to cancel authentication or provide
credentials for repository it was asked for.
5) Whenever credentials are accepted, they are saved into runtime
cache and, in case it is allowed by configuration, into on-disk cache.

So, this is how DefaultSVNAuthenticationManager works. For you that
means that if you use it, you should implement and set
ISVNAuthenticationProvider callback that will provide either first or
second user's credentials depending on the repository URL:

        DefaultSVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager();
        authManager.setAuthenticationProvider(new ISVNAuthenticationProvider() {
            public SVNAuthentication
requestClientAuthentication(String kind, SVNURL url, String realm,
SVNErrorMessage errorMessage, SVNAuthentication previousAuth, boolean
authMayBeStored) {
                if (url.equals(URL1)) {
                    return new SVNPasswordAuthentication(userName1,
password2, false, url, false);
                } else if (url.equals(URL2)) {
                    return new SVNPasswordAuthentication(userName2,
password2, false, url, false);
                }
                return null;
            }
            public int acceptServerAuthentication(SVNURL url, String
realm, Object certificate, boolean resultMayBeStored) {
                return ACCEPTED_TEMPORARY;
            }
        });
        SvnOperationFactory of = new SvnOperationFactory();
        of.setAuthenticationManager(authManager);


Another authentication manager is BasicAuthenticationManager. When
asked for credentials it simply provides all it has been configured
with and you may use it too:

        BasicAuthenticationManager authManager = new
BasicAuthenticationManager(new SVNAuthentication[] {user1Auth,
user2Auth});
        SvnOperationFactory of = new SvnOperationFactory();
        of.setAuthenticationManager(authManager);

When asked for credentials by repository2, first user1Auth will be
used. In case these credentials are rejected, user2Auth will be used.
This probably not exactly what you want in case for instance both
user1 and user2 are in both repositories and you'd like to have
control over user account being used with each repository.

Finally, another simple approach is to keep two
BasicAuthenticationManager objects each configured for certain user.
Then set corresponding manager on SvnOperationFactory before running
an operation.

Alexander Kitaev,
TMate Software,
http://subgit.com/ - Svn to Git Migration!
http://svnkit.com/ - Java [Sub]Versioning Library!
http://hg4j.com/ - Java Mercurial Library!
http://sqljet.com/ - Java SQLite Library!


On 10 March 2013 20:47, Daniel Alencar <daniel.calen...@gmail.com> wrote:
> Hi Everybody,
>
> Is there a way to store two or more credentials in one
> SVNAuthenticationManager?
>
> Background:
>
> I have two different SVN repositories
>
> svn1: svn://192.169.0.10/svn/projectX1
> svn2: svn://192.169.0.10/svn/projectX2
>
> The repositories contains two differents evolutions  of the ProjectX, so i
> want to do a diff of a fileX1 from svn1 to a fileX2 from svn2. In order to
> do this, i have to provide two credentials for my authentication manager
> (one for svn1 and other for svn2), right?
>
> Then i could do the following:
>
> SvnOperationFactory opF = new SvnOperationFactory();
>
> opF.setAuthenticationManager(<here my authentication manager with two
> credentials>)
>
> Is this the solution? how do i do this?
>
> I'm thankful for any help you can provide,
>
> --
> Daniel Alencar da Costa

Reply via email to