if(Preferences.getBoolean("xmpp", "anonymousLogin", false))
{
if(mechanisms.getMechanisms().contains("ANONYMOUS"))
{
System.out.println("sending anon");
connect.sendWhileConnecting(new SaslPacket("ANONYMOUS"));
}
else connect.sendLoginError("No Anonymous login possible");
}
else if(Utils.isAtleastJava(5))
{
String[] m = mechanisms.getMechanisms().toArray(
new String[mechanisms.getMechanisms().size()]);
try {
SaslClient sc = new SaslClient(javax.security.sasl.Sasl.createSaslClient(m
, null, "xmpp", loginInfo.getServer(), null,this));
byte[] response = (sc.hasInitialResponse()
? sc.evaluateChallenge(new byte[0]) : null);
String res = null;
System.out.println("res made");
if(response!=null)res =Base64.encodeBytes(response);
saslClient = sc;
System.out.println("ready to send");
connect.sendWhileConnecting(new SaslPacket(sc.getMechanismName(),res));
System.out.println("auth packet send");
}catch(Exception e)
{
e.printStackTrace();
connect.sendLoginError(e.getMessage());
}
}
else if(mechanisms.getMechanisms().contains("PLAIN"))
{
System.out.println("secure read" + secure);
if(!secure)
{
int option = JOptionPane.showConfirmDialog(null
,I18N.gettext("main.loginstatus.Sending_password_as_plain_text_over_an_unencrypted_connection,_continue?"),"Plain text",JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.NO_OPTION)
{
connect.sendLoginError("Sending password in plain not allowed");
return;
}
}
String ret = loginInfo.getUsername() + "@" + loginInfo.getServer() +
'\0' +loginInfo.getUsername()+'\0'+loginInfo.getPassword();
connect.sendWhileConnecting(new SaslPacket("PLAIN",Base64.encodeBytes(ret.getBytes())));
}
}