Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » Better credentials verification
Better credentials verification [message #782621] Tue, 24 January 2012 04:15
Luis Lara is currently offline Luis Lara
Messages: 5
Registered: January 2012
Junior Member
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: Mon Oct 20 11:32:52 GMT 2014

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

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