1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Merge Smack 4.1.0-rc2

Conflicts:
	smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
	smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java
	version.gradle
This commit is contained in:
Florian Schmaus 2015-02-21 18:07:45 +01:00
commit fbf0ba13ce
48 changed files with 650 additions and 166 deletions

View file

@ -176,11 +176,8 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
this.collector = collector;
}
public InputStream call() throws XMPPErrorException, InterruptedException, SmackException {
Stanza streamInitiation = collector.nextResult();
if (streamInitiation == null) {
throw new NoResponseException(connection);
}
public InputStream call() throws XMPPErrorException, InterruptedException, NoResponseException, SmackException {
Stanza streamInitiation = collector.nextResultOrThrow();
StreamNegotiator negotiator = determineNegotiator(streamInitiation);
return negotiator.negotiateIncomingStream(streamInitiation);
}

View file

@ -32,6 +32,7 @@ import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
@ -128,14 +129,11 @@ public class Socks5TransferNegotiator extends StreamNegotiator {
*/
private static class BytestreamSIDFilter extends PacketTypeFilter {
private String sessionID;
private final String sessionID;
public BytestreamSIDFilter(String sessionID) {
super(Bytestream.class);
if (sessionID == null) {
throw new IllegalArgumentException("StreamID cannot be null");
}
this.sessionID = sessionID;
this.sessionID = Objects.requireNonNull(sessionID, "SessionID cannot be null");
}
@Override

View file

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Logger;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.PacketCollector;
@ -31,7 +32,7 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.iqregister.packet.Registration;
@ -41,6 +42,9 @@ import org.jivesoftware.smackx.iqregister.packet.Registration;
* @author Matt Tucker
*/
public class AccountManager extends Manager {
private static final Logger LOGGER = Logger.getLogger(AccountManager.class.getName());
private static final Map<XMPPConnection, AccountManager> INSTANCES = new WeakHashMap<XMPPConnection, AccountManager>();
/**
@ -58,6 +62,35 @@ public class AccountManager extends Manager {
return accountManager;
}
private static boolean allowSensitiveOperationOverInsecureConnectionDefault = false;
/**
* The default value used by new account managers for <code>allowSensitiveOperationOverInsecureConnection</code>.
*
* @param allow
* @see #sensitiveOperationOverInsecureConnection(boolean)
* @since 4.1
*/
public static void sensitiveOperationOverInsecureConnectionDefault(boolean allow) {
AccountManager.allowSensitiveOperationOverInsecureConnectionDefault = allow;
}
private boolean allowSensitiveOperationOverInsecureConnection = allowSensitiveOperationOverInsecureConnectionDefault;
/**
* Set to <code>true</code> to allow sensitive operation over insecure connection.
* <p>
* Set to true to allow sensitive operations like account creation or password changes over an insecure (e.g.
* unencrypted) connections.
* </p>
*
* @param allow
* @since 4.1
*/
public void sensitiveOperationOverInsecureConnection(boolean allow) {
this.allowSensitiveOperationOverInsecureConnection = allow;
}
private Registration info = null;
/**
@ -231,6 +264,11 @@ public class AccountManager extends Manager {
*/
public void createAccount(String username, String password, Map<String, String> attributes)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
// TODO throw exception in newer Smack versions
LOGGER.warning("Creating account over insecure connection. "
+ "This will throw an exception in future versions of Smack if AccountManager.sensitiveOperationOverInsecureConnection(true) is not set");
}
attributes.put("username", username);
attributes.put("password", password);
Registration reg = new Registration(attributes);
@ -251,6 +289,11 @@ public class AccountManager extends Manager {
* @throws InterruptedException
*/
public void changePassword(String newPassword) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
// TODO throw exception in newer Smack versions
LOGGER.warning("Changing password over insecure connection. "
+ "This will throw an exception in future versions of Smack if AccountManager.sensitiveOperationOverInsecureConnection(true) is not set");
}
Map<String, String> map = new HashMap<String, String>();
map.put("username", connection().getUser().getLocalpart().toString());
map.put("password",newPassword);
@ -298,7 +341,7 @@ public class AccountManager extends Manager {
}
private PacketCollector createPacketCollectorAndSend(IQ req) throws NotConnectedException, InterruptedException {
PacketCollector collector = connection().createPacketCollectorAndSend(new PacketIDFilter(req.getStanzaId()), req);
PacketCollector collector = connection().createPacketCollectorAndSend(new StanzaIdFilter(req.getStanzaId()), req);
return collector;
}
}

View file

@ -27,26 +27,6 @@ import org.jxmpp.jid.Jid;
* A Version IQ packet, which is used by XMPP clients to discover version information
* about the software running at another entity's JID.<p>
*
* An example to discover the version of the server:
* <pre>
* // Request the version from the server.
* Version versionRequest = new Version();
* timeRequest.setType(IQ.Type.get);
* timeRequest.setTo("example.com");
*
* // Create a packet collector to listen for a response.
* PacketCollector collector = con.createPacketCollector(
* new PacketIDFilter(versionRequest.getStanzaId()));
*
* con.sendPacket(versionRequest);
*
* // Wait up to 5 seconds for a result.
* IQ result = (IQ)collector.nextResult(5000);
* if (result != null && result.getType() == IQ.Type.result) {
* Version versionResult = (Version)result;
* // Do something with result...
* }</pre><p>
*
* @author Gaston Dombiak
*/
public class Version extends IQ {

View file

@ -57,14 +57,15 @@ public class ItemProvider extends PacketExtensionProvider<Item>
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
if (ProviderManager.getExtensionProvider(payloadElemName, payloadNS) == null)
final PacketExtensionProvider<PacketExtension> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
if (extensionProvider == null)
{
CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText));
}
else
{
return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
return new PayloadItem<PacketExtension>(id, node, extensionProvider.parse(parser));
}
}
}

View file

@ -51,7 +51,7 @@ import org.jivesoftware.smack.packet.Stanza;
* <code>
* public void methodToTest() {
* Packet packet = new Packet(); // create an XMPP packet
* PacketCollector collector = connection.createPacketCollector(new PacketIDFilter());
* PacketCollector collector = connection.createPacketCollector(new StanzaIdFilter());
* connection.sendPacket(packet);
* Packet reply = collector.nextResult();
* }