This commit is contained in:
Clebert Suconic 2020-11-20 10:08:39 -05:00
commit 4f208ef4b1
4 changed files with 76 additions and 22 deletions

View File

@ -34,6 +34,8 @@ public final class DataConstants {
public static final int SIZE_CHAR = 2; public static final int SIZE_CHAR = 2;
public static final int SIZE_NULL = 1;
public static final byte TRUE = 1; public static final byte TRUE = 1;
public static final byte FALSE = 0; public static final byte FALSE = 0;

View File

@ -20,6 +20,9 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.journal.EncodingSupport; import org.apache.activemq.artemis.core.journal.EncodingSupport;
import static org.apache.activemq.artemis.utils.DataConstants.SIZE_INT;
import static org.apache.activemq.artemis.utils.DataConstants.SIZE_NULL;
public class PersistedSecuritySetting implements EncodingSupport { public class PersistedSecuritySetting implements EncodingSupport {
// Constants ----------------------------------------------------- // Constants -----------------------------------------------------
@ -116,74 +119,77 @@ public class PersistedSecuritySetting implements EncodingSupport {
* @return the sendRoles * @return the sendRoles
*/ */
public String getSendRoles() { public String getSendRoles() {
return sendRoles.toString(); return sendRoles != null ? sendRoles.toString() : null;
} }
/** /**
* @return the consumeRoles * @return the consumeRoles
*/ */
public String getConsumeRoles() { public String getConsumeRoles() {
return consumeRoles.toString(); return consumeRoles != null ? consumeRoles.toString() : null;
} }
/** /**
* @return the createDurableQueueRoles * @return the createDurableQueueRoles
*/ */
public String getCreateDurableQueueRoles() { public String getCreateDurableQueueRoles() {
return createDurableQueueRoles.toString(); return createDurableQueueRoles != null ? createDurableQueueRoles.toString() : null;
} }
/** /**
* @return the deleteDurableQueueRoles * @return the deleteDurableQueueRoles
*/ */
public String getDeleteDurableQueueRoles() { public String getDeleteDurableQueueRoles() {
return deleteDurableQueueRoles.toString(); return deleteDurableQueueRoles != null ? deleteDurableQueueRoles.toString() : null;
} }
/** /**
* @return the createNonDurableQueueRoles * @return the createNonDurableQueueRoles
*/ */
public String getCreateNonDurableQueueRoles() { public String getCreateNonDurableQueueRoles() {
return createNonDurableQueueRoles.toString(); return createNonDurableQueueRoles != null ? createNonDurableQueueRoles.toString() : null;
} }
/** /**
* @return the deleteNonDurableQueueRoles * @return the deleteNonDurableQueueRoles
*/ */
public String getDeleteNonDurableQueueRoles() { public String getDeleteNonDurableQueueRoles() {
return deleteNonDurableQueueRoles.toString(); return deleteNonDurableQueueRoles != null ? deleteNonDurableQueueRoles.toString() : null;
} }
/** /**
* @return the manageRoles * @return the manageRoles
*/ */
public String getManageRoles() { public String getManageRoles() {
return manageRoles.toString(); return manageRoles != null ? manageRoles.toString() : null;
} }
/** /**
* @return the browseRoles * @return the browseRoles
*/ */
public String getBrowseRoles() { public String getBrowseRoles() {
return browseRoles.toString(); return browseRoles != null ? browseRoles.toString() : null;
} }
/** /**
* @return the createAddressRoles * @return the createAddressRoles
*/ */
public String getCreateAddressRoles() { public String getCreateAddressRoles() {
return createAddressRoles.toString(); return createAddressRoles != null ? createAddressRoles.toString() : null;
} }
/** /**
* @return the deleteAddressRoles * @return the deleteAddressRoles
*/ */
public String getDeleteAddressRoles() { public String getDeleteAddressRoles() {
return deleteAddressRoles.toString(); return deleteAddressRoles != null ? deleteAddressRoles.toString() : null;
} }
@Override @Override
public void encode(final ActiveMQBuffer buffer) { public void encode(final ActiveMQBuffer buffer) {
if (addressMatch == null) {
addressMatch = new SimpleString("");
}
buffer.writeSimpleString(addressMatch); buffer.writeSimpleString(addressMatch);
buffer.writeNullableSimpleString(sendRoles); buffer.writeNullableSimpleString(sendRoles);
buffer.writeNullableSimpleString(consumeRoles); buffer.writeNullableSimpleString(consumeRoles);
@ -199,16 +205,18 @@ public class PersistedSecuritySetting implements EncodingSupport {
@Override @Override
public int getEncodeSize() { public int getEncodeSize() {
return addressMatch.sizeof() + SimpleString.sizeofNullableString(sendRoles) + return
SimpleString.sizeofNullableString(consumeRoles) + (addressMatch == null ? SIZE_INT : addressMatch.sizeof()) +
SimpleString.sizeofNullableString(createDurableQueueRoles) + (sendRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(sendRoles)) +
SimpleString.sizeofNullableString(deleteDurableQueueRoles) + (consumeRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(consumeRoles)) +
SimpleString.sizeofNullableString(createNonDurableQueueRoles) + (createDurableQueueRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(createDurableQueueRoles)) +
SimpleString.sizeofNullableString(deleteNonDurableQueueRoles) + (deleteDurableQueueRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(deleteDurableQueueRoles)) +
SimpleString.sizeofNullableString(manageRoles) + (createNonDurableQueueRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(createNonDurableQueueRoles)) +
SimpleString.sizeofNullableString(browseRoles) + (deleteNonDurableQueueRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(deleteNonDurableQueueRoles)) +
SimpleString.sizeofNullableString(createAddressRoles) + (manageRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(manageRoles)) +
SimpleString.sizeofNullableString(deleteAddressRoles); (browseRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(browseRoles)) +
(createAddressRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(createAddressRoles)) +
(deleteAddressRoles == null ? SIZE_NULL : SimpleString.sizeofNullableString(deleteAddressRoles));
} }
@Override @Override

View File

@ -904,7 +904,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
String exactAddress = "test.whatever"; String exactAddress = "test.whatever";
assertEquals(1, serverControl.getRoles(addressMatch).length); assertEquals(1, serverControl.getRoles(addressMatch).length);
serverControl.addSecuritySettings(addressMatch, "foo", "foo, bar", "foo", "bar", "foo, bar", "", "", "bar", "foo", "foo"); serverControl.addSecuritySettings(addressMatch, "foo", "foo, bar", null, "bar", "foo, bar", "", "", "bar", "foo", "foo");
// Restart the server. Those settings should be persisted // Restart the server. Those settings should be persisted
@ -926,7 +926,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
} }
assertTrue(fooRole.isSend()); assertTrue(fooRole.isSend());
assertTrue(fooRole.isConsume()); assertTrue(fooRole.isConsume());
assertTrue(fooRole.isCreateDurableQueue()); assertFalse(fooRole.isCreateDurableQueue());
assertFalse(fooRole.isDeleteDurableQueue()); assertFalse(fooRole.isDeleteDurableQueue());
assertTrue(fooRole.isCreateNonDurableQueue()); assertTrue(fooRole.isCreateNonDurableQueue());
assertFalse(fooRole.isDeleteNonDurableQueue()); assertFalse(fooRole.isDeleteNonDurableQueue());

View File

@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <br>
* http://www.apache.org/licenses/LICENSE-2.0
* <br>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.core.persistence.config.PersistedSecuritySetting;
import org.junit.Test;
public class PersistedSecuritySettingTest {
@Test
public void testNPE() {
PersistedSecuritySetting persistedSecuritySetting = new PersistedSecuritySetting();
ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(persistedSecuritySetting.getEncodeSize());
persistedSecuritySetting.encode(buffer);
persistedSecuritySetting.decode(buffer);
persistedSecuritySetting.getBrowseRoles();
persistedSecuritySetting.getConsumeRoles();
persistedSecuritySetting.getCreateAddressRoles();
persistedSecuritySetting.getCreateDurableQueueRoles();
persistedSecuritySetting.getCreateNonDurableQueueRoles();
persistedSecuritySetting.getDeleteAddressRoles();
persistedSecuritySetting.getDeleteDurableQueueRoles();
persistedSecuritySetting.getDeleteNonDurableQueueRoles();
persistedSecuritySetting.getManageRoles();
persistedSecuritySetting.getSendRoles();
}
}