Hi,
+-From: prakash babu <[email protected]> --
|_Date: Wed, 4 Aug 2010 15:09:12 +0530 (IST) _____
|
|In my application I want to determine if public key authentication
|is enabled in the remote node. So I set the logger first and
|connect to the target machine and check the log for
|"Authentications that can continue: publickey" as shown below
...
|The issue with this method is in a multi threaded scenario the log
|information is messed up, since the jsch Logger is static.
|So is there a better way to determine if public key authentication
|is enabled in the remote node or is there a way to make above
|method thread safe.
Yes, there is not a better way in the current implementation.
If I need to do in the current code, I will define the following
AuthCheck class, for example,
class AuthCheck implements com.jcraft.jsch.Logger {
static { JSch.setLogger(new AuthCheck()); }
private static ThreadLocal host = new ThreadLocal();
private static JSch jsch=new JSch();
public boolean isEnabled(int level){ return true; }
public void log(int level, String message){
if(message.equals("Next authentication method: publickey")){
System.out.println(host.get()+" supports the publickey authentication
method.");
}
}
public void check(String _host){
try{
host.set(_host);
Session session=jsch.getSession("foo", _host, 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("PreferredAuthentications", "publickey");
session.connect(10000);
session.disconnect();
}
catch(JSchException e){
}
finally{
host.remove();
}
}
}
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users