Adds anonymous login strategy to XMPP provider.

fix-message-formatting
paweldomas 12 years ago
parent 965f6b6f59
commit 527417062c

@ -0,0 +1,84 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.protocol.*;
import org.jivesoftware.smack.*;
import javax.net.ssl.*;
import java.security.*;
/**
* Implements anonymous login strategy for the purpose of some server side
* technologies. This makes not much sense to be used with Jitsi directly.
*
* @see JabberAccountIDImpl#ANONYMOUS_AUTH
*
* @author Pawel Domas
*/
public class AnonymousLoginStrategy
implements JabberLoginStrategy
{
/**
* <tt>UserCredentials</tt> used by accompanying services.
*/
private final UserCredentials credentials;
/**
* Creates new anonymous login strategy instance.
* @param login user login only for the purpose of returning
* <tt>UserCredentials</tt> that are used by accompanying
* services.
*/
public AnonymousLoginStrategy(String login)
{
this.credentials = new UserCredentials();
credentials.setUserName(login);
//FIXME: consider including password for TURN authentication ?
credentials.setPassword(new char[]{});
}
@Override
public UserCredentials prepareLogin(SecurityAuthority authority,
int reasonCode)
{
return credentials;
}
@Override
public boolean loginPreparationSuccessful()
{
return true;
}
@Override
public boolean login(XMPPConnection connection, String userName,
String resource)
throws XMPPException
{
connection.loginAnonymously();
return true;
}
@Override
public boolean isTlsRequired()
{
return false;
}
@Override
public SSLContext createSslContext(CertificateService certificateService,
X509TrustManager trustManager)
throws GeneralSecurityException
{
return null;
}
}

@ -789,6 +789,12 @@ private void initializeConnectAndLogin(SecurityAuthority authority,
*/
private JabberLoginStrategy createLoginStrategy()
{
if (((JabberAccountIDImpl)getAccountID()).isAnonymousAuthUsed())
{
return new AnonymousLoginStrategy(
getAccountID().getAuthorizationName());
}
String clientCertId = getAccountID().getAccountPropertyString(
ProtocolProviderFactory.CLIENT_TLS_CERTIFICATE);
if(clientCertId != null)

@ -27,6 +27,11 @@ public class JabberAccountID
private static final String JBR_DEFAULTS_PREFIX
= AccountID.DEFAULTS_PREFIX +"jabber.";
/**
* Uses anonymous XMPP login if set to <tt>true</tt>.
*/
public static final String ANONYMOUS_AUTH = "ANONYMOUS_AUTH";
/**
* Account suffix for Google service.
*/
@ -142,6 +147,15 @@ public String getTelephonyDomainBypassCaps()
return getAccountPropertyString(TELEPHONY_BYPASS_GTALK_CAPS);
}
/**
* Indicates whether anonymous authorization method is used by this account.
* @return <tt>true</tt> if anonymous login is enabled on this account.
*/
public boolean isAnonymousAuthUsed()
{
return getAccountPropertyBoolean(ANONYMOUS_AUTH, false);
}
/**
* Gets if Jingle is disabled for this account.
*
@ -188,6 +202,15 @@ public boolean isGoogleContactsEnabled()
return getAccountPropertyBoolean(GOOGLE_CONTACTS_ENABLED, true);
}
/**
* Enables anonymous authorization mode on this XMPP account.
* @param useAnonymousAuth <tt>true</tt> to use anonymous login.
*/
public void setUseAnonymousAuth(boolean useAnonymousAuth)
{
putAccountProperty(ANONYMOUS_AUTH, useAnonymousAuth);
}
/**
* Sets the override value of the phone suffix.
*

Loading…
Cancel
Save