Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Better credentials verification
Better credentials verification [message #782621] Mon, 23 January 2012 23:15
Eclipse UserFriend
HI JGit team!

I was looking for a way to verify credentials, I scrapped some code that seems to be working, but of course, I don't know the code, so I am sure, there is a better way to do this.

Thanks,
LC

public static boolean verifyCredentials(String remoteName, CredentialsProvider cred)
throws Exception {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
File temp = File.createTempFile("temp", null);
Repository repository = builder.setGitDir(temp).readEnvironment().findGitDir().build();
for (WeakReference<TransportProtocol> ref : protocols) {
TransportProtocol proto = ref.get();
if (proto.canHandle(new URIish(remoteName), null, remoteName)) {
try {
Transport tx = proto.open(new URIish(remoteName), repository, remoteName);
tx.setCredentialsProvider(cred);
tx.openFetch().close();
return true;
} catch (Exception e) {
return false;
}

}
}
return false;
}
Previous Topic:Compare with HEAD revision and .gitignore
Next Topic:Fetch
Goto Forum:
  


Current Time: Sat Jun 21 08:15:26 EDT 2025

Powered by FUDForum. Page generated in 0.05110 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top