diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedSecuritySetting.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedSecuritySetting.java index 02c4f45d96..b858573f84 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedSecuritySetting.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/config/PersistedSecuritySetting.java @@ -252,8 +252,12 @@ public class PersistedSecuritySetting implements EncodingSupport { browseRoles = buffer.readNullableSimpleString(); createAddressRoles = buffer.readNullableSimpleString(); deleteAddressRoles = buffer.readNullableSimpleString(); - viewRoles = buffer.readNullableSimpleString(); - editRoles = buffer.readNullableSimpleString(); + if (buffer.readableBytes() > 0) { + viewRoles = buffer.readNullableSimpleString(); + } + if (buffer.readableBytes() > 0) { + editRoles = buffer.readNullableSimpleString(); + } } /* (non-Javadoc) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/PersistedSecuritySettingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/PersistedSecuritySettingTest.java index 3d82b592cc..a6f557b592 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/PersistedSecuritySettingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/security/PersistedSecuritySettingTest.java @@ -19,9 +19,14 @@ package org.apache.activemq.artemis.tests.integration.security; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.persistence.config.PersistedSecuritySetting; +import org.apache.activemq.artemis.tests.util.RandomUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + public class PersistedSecuritySettingTest { @Test @@ -43,4 +48,31 @@ public class PersistedSecuritySettingTest { persistedSecuritySetting.getViewRoles(); persistedSecuritySetting.getEditRoles(); } + + @Test + public void testUpgradeAfterARTEMIS_4582() { + // this buffer simulates a PersistedSecuritySetting journal entry from *before* ARTEMIS-4582 + SimpleString match = RandomUtil.randomSimpleString(); + ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer((SimpleString.sizeofNullableString(match)) + 10); + buffer.writeSimpleString(match); + for (int i = 0; i < 10; i++) { + buffer.writeNullableSimpleString(null); + } + + PersistedSecuritySetting persistedSecuritySetting = new PersistedSecuritySetting(); + persistedSecuritySetting.decode(buffer); + assertEquals(match, persistedSecuritySetting.getAddressMatch()); + assertNull(persistedSecuritySetting.getBrowseRoles()); + assertNull(persistedSecuritySetting.getConsumeRoles()); + assertNull(persistedSecuritySetting.getCreateAddressRoles()); + assertNull(persistedSecuritySetting.getCreateDurableQueueRoles()); + assertNull(persistedSecuritySetting.getCreateNonDurableQueueRoles()); + assertNull(persistedSecuritySetting.getDeleteAddressRoles()); + assertNull(persistedSecuritySetting.getDeleteDurableQueueRoles()); + assertNull(persistedSecuritySetting.getDeleteNonDurableQueueRoles()); + assertNull(persistedSecuritySetting.getManageRoles()); + assertNull(persistedSecuritySetting.getSendRoles()); + assertNull(persistedSecuritySetting.getViewRoles()); + assertNull(persistedSecuritySetting.getEditRoles()); + } }