This is an automated email from the ASF dual-hosted git repository.
ralaoui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-vysper.git
The following commit(s) were added to refs/heads/master by this push:
new 4a94400 StateAwareProtocolWorker logic prevents StanzaHandler
proxying (#8)
4a94400 is described below
commit 4a944000381ae1b46945de5ba673c0a717405626
Author: Réda Housni Alaoui <[email protected]>
AuthorDate: Sat Aug 17 09:16:51 2019 +0200
StateAwareProtocolWorker logic prevents StanzaHandler proxying (#8)
---
.../org/apache/vysper/xmpp/protocol/ProtocolWorker.java | 2 +-
.../org/apache/vysper/xmpp/protocol/StanzaHandler.java | 11 +++++++++++
.../xmpp/protocol/worker/AuthenticatedProtocolWorker.java | 2 +-
.../xmpp/protocol/worker/EncryptedProtocolWorker.java | 15 ++++++++-------
.../xmpp/protocol/worker/InitiatedProtocolWorker.java | 5 +++--
.../xmpp/protocol/worker/StartedProtocolWorker.java | 11 ++++++-----
6 files changed, 30 insertions(+), 16 deletions(-)
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
index 9f98c12..f9a229d 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
@@ -108,7 +108,7 @@ public class ProtocolWorker implements StanzaProcessor {
if (sessionStateHolder.getState() != SessionState.AUTHENTICATED) {
// is not authenticated...
if (XMPPCoreStanza.getWrapper(stanza) != null
- && !(stanzaHandler instanceof InBandRegistrationHandler)) {
+ &&
!(InBandRegistrationHandler.class.isAssignableFrom(stanzaHandler.unwrapType())))
{
// ... and is a IQ/PRESENCE/MESSAGE stanza!
responseWriter.handleNotAuthorized(sessionContext, stanza);
return;
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
index 12d2ede..1640bf8 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
@@ -39,6 +39,17 @@ public interface StanzaHandler {
public String getName();
/**
+ * Allows to check the type of the handler by maintaining compatibility
with
+ * delegating handlers. Delegating handlers are expected to delegate this
call
+ * to their delegates.
+ *
+ * @return The type wrapped by this handler
+ */
+ default Class<?> unwrapType() {
+ return getClass();
+ }
+
+ /**
* verifies if the stanza is processed by this handler
* @param stanza
* @return true, if it is processed, false otherwise
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/AuthenticatedProtocolWorker.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/AuthenticatedProtocolWorker.java
index 2100203..8181185 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/AuthenticatedProtocolWorker.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/AuthenticatedProtocolWorker.java
@@ -36,7 +36,7 @@ public class AuthenticatedProtocolWorker extends
AbstractStateAwareProtocolWorke
@Override
protected boolean checkState(SessionContext sessionContext,
SessionStateHolder sessionStateHolder, Stanza stanza,
StanzaHandler stanzaHandler) {
- if (stanzaHandler instanceof StreamStartHandler)
+ if
(StreamStartHandler.class.isAssignableFrom(stanzaHandler.unwrapType()))
return true;
if (stanzaHandler.verify(stanza))
return true;
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
index 9cb7f5b..9a47003 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/EncryptedProtocolWorker.java
@@ -47,17 +47,18 @@ public class EncryptedProtocolWorker extends
AbstractStateAwareProtocolWorker {
protected boolean checkState(SessionContext sessionContext,
SessionStateHolder sessionStateHolder, Stanza stanza,
StanzaHandler stanzaHandler) {
- if (stanzaHandler instanceof StreamStartHandler) {
+ Class<?> handlerUnwrappedType = stanzaHandler.unwrapType();
+ if (StreamStartHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (stanzaHandler instanceof AbstractSASLHandler) {
+ } else if
(AbstractSASLHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (stanzaHandler instanceof XMLPrologHandler) {
- return true; // PSI client sends that.
- } else if (stanzaHandler instanceof InBandRegistrationHandler) {
+ } else if
(XMLPrologHandler.class.isAssignableFrom(handlerUnwrappedType)) {
+ return true; // PSI client sends that.
+ } else if
(InBandRegistrationHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (sessionContext.isServerToServer() && stanzaHandler
instanceof DbResultHandler) {
+ } else if (sessionContext.isServerToServer() &&
DbResultHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (sessionContext.isServerToServer() && stanzaHandler
instanceof DbVerifyHandler) {
+ } else if (sessionContext.isServerToServer() &&
DbVerifyHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
}
ResponseWriter.writeUnsupportedStanzaError(sessionContext);
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/InitiatedProtocolWorker.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/InitiatedProtocolWorker.java
index 9add8aa..5ace273 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/InitiatedProtocolWorker.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/InitiatedProtocolWorker.java
@@ -42,9 +42,10 @@ public class InitiatedProtocolWorker extends
AbstractStateAwareProtocolWorker {
@Override
protected boolean checkState(SessionContext sessionContext,
SessionStateHolder sessionStateHolder, Stanza stanza,
StanzaHandler stanzaHandler) {
- if (stanzaHandler instanceof XMLPrologHandler)
+ Class<?> handlerUnwrappedType = stanzaHandler.unwrapType();
+ if (XMLPrologHandler.class.isAssignableFrom(handlerUnwrappedType))
return true;
- if (stanzaHandler instanceof StreamStartHandler)
+ if (StreamStartHandler.class.isAssignableFrom(handlerUnwrappedType))
return true;
ResponseWriter.writeUnsupportedStanzaError(sessionContext);
return false;
diff --git
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/StartedProtocolWorker.java
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/StartedProtocolWorker.java
index 920df40..c8073db 100644
---
a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/StartedProtocolWorker.java
+++
b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/worker/StartedProtocolWorker.java
@@ -45,14 +45,15 @@ public class StartedProtocolWorker extends
AbstractStateAwareProtocolWorker {
protected boolean checkState(SessionContext sessionContext,
SessionStateHolder sessionStateHolder, Stanza stanza,
StanzaHandler stanzaHandler) {
- if (stanzaHandler instanceof StartTLSHandler) {
+ Class<?> handlerUnwrappedType = stanzaHandler.unwrapType();
+ if (StartTLSHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (stanzaHandler instanceof AbstractSASLHandler &&
-
!sessionContext.getServerRuntimeContext().getServerFeatures().isStartTLSRequired())
{
+ } else if
(AbstractSASLHandler.class.isAssignableFrom(handlerUnwrappedType)
+ &&
!sessionContext.getServerRuntimeContext().getServerFeatures().isStartTLSRequired())
{
return true;
- } else if (sessionContext.isServerToServer() && stanzaHandler
instanceof DbVerifyHandler) {
+ } else if (sessionContext.isServerToServer() &&
DbVerifyHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
- } else if (sessionContext.isServerToServer() && stanzaHandler
instanceof DbResultHandler) {
+ } else if (sessionContext.isServerToServer() &&
DbResultHandler.class.isAssignableFrom(handlerUnwrappedType)) {
return true;
}
ResponseWriter.writeUnsupportedStanzaError(sessionContext);