ARTEMIS-2846 Cannot define hawtio.role with whitespace

Move the `hawtio.role` property definition to avoid the word splitting.
This commit is contained in:
brusdev 2020-07-24 17:01:12 +02:00 committed by Clebert Suconic
parent 1ebfc8f982
commit 3ce9e2e0dc
7 changed files with 50 additions and 4 deletions

View File

@ -634,6 +634,7 @@ public class Create extends InputAbstract {
filters.put("${user}", getUser());
filters.put("${password}", getPassword());
filters.put("${role}", role);
filters.put("${encoded.role}", role.replaceAll(" ", "\\\\ "));
if (globalMaxSize == null || globalMaxSize.trim().equals("")) {

View File

@ -119,6 +119,7 @@ fi
exec "$JAVACMD" \
$JAVA_ARGS \
-Dhawtio.role="$HAWTIO_ROLE" \
-Xbootclasspath/a:"$LOG_MANAGER:$WILDFLY_COMMON" \
-Djava.security.auth.login.config="$ARTEMIS_INSTANCE_ETC/login.config" \
$ARTEMIS_CLUSTER_PROPS \

View File

@ -15,4 +15,4 @@
## limitations under the License.
## ---------------------------------------------------------------------------
${role} = ${user}
${encoded.role} = ${user}

View File

@ -31,9 +31,13 @@ ARTEMIS_INSTANCE_ETC_URI='${artemis.instance.etc.uri}'
#ARTEMIS_CLUSTER_PROPS="-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446"
# Hawtio Properties
HAWTIO_ROLE='${role}'
# Java Opts
if [ -z "$JAVA_ARGS" ]; then
JAVA_ARGS="${java-opts} -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx2G -Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.role=${role} -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml"
JAVA_ARGS="${java-opts} -XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx2G -Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=${ARTEMIS_INSTANCE_ETC_URI}jolokia-access.xml"
fi
#

View File

@ -779,6 +779,29 @@ public class ArtemisTest extends CliTestBase {
assertTrue(checkPassword("user3", "newpassword3", userFile));
}
@Test
public void testRoleWithSpaces() throws Exception {
String roleWithSpaces = "amq with spaces";
Run.setEmbedded(true);
File instanceRole = new File(temporaryFolder.getRoot(), "instance_role");
System.setProperty("java.security.auth.login.config", instanceRole.getAbsolutePath() + "/etc/login.config");
Artemis.main("create", instanceRole.getAbsolutePath(), "--silent", "--no-autotune", "--role", roleWithSpaces);
System.setProperty("artemis.instance", instanceRole.getAbsolutePath());
File roleFile = new File(instanceRole.getAbsolutePath() + "/etc/artemis-roles.properties");
ListUser listCmd = new ListUser();
TestActionContext context = new TestActionContext();
listCmd.execute(context);
String result = context.getStdout();
log.debug("output1:\n" + result);
assertTrue(result.contains("\"admin\"(" + roleWithSpaces + ")"));
checkRole("admin", roleFile, roleWithSpaces);
}
@Test
public void testUserCommandResetViaManagementPlaintext() throws Exception {
internalTestUserCommandResetViaManagement(true);

View File

@ -23,6 +23,14 @@ rm -rf target
mkdir target
mkdir target/"$1"
if [ -z "$2" ]
then
export ARTEMIS_ROLE=amq
else
export ARTEMIS_ROLE=$2
fi
echo with the role $ARTEMIS_ROLE
# Setting the script to fail if anything goes wrong
set -e
@ -39,7 +47,7 @@ echo artemis instance is $ARTEMIS_HOME
cd "$ARTEMIS_HOME/bin"
./artemis create --silent --force "$ARTEMIS_INSTANCE"
./artemis create --silent --force --role "$ARTEMIS_ROLE" "$ARTEMIS_INSTANCE"
cd "$ARTEMIS_INSTANCE/bin"
pwd
@ -66,6 +74,15 @@ sleep 5
./artemis producer
./artemis consumer --receive-timeout 10000 --break-on-null
export HTTP_CODE=$(curl -H "Origin:http://localhost" -u admin:admin --write-out '%{http_code}' --silent --output /dev/null http://localhost:8161/console/jolokia/read/org.apache.activemq.artemis:broker=%220.0.0.0%22/Version)
if [[ "$HTTP_CODE" -ne 200 ]]
then
echo "Artemis Jolokia REST API check failed: " $HTTP_CODE
else
echo "Artemis Jolokia REST API check passed"
fi
./artemis-service stop
cd $CURRENT_DIR

View File

@ -18,4 +18,4 @@
# This script will validate the distribution works with folders with spaces on Linux machines
./validate-instalation.sh with\ spaces\ And\ Weird\ %26\ Characters\ Čeština\ 漢字\ водка\ 昨夜のコ\ ﷹ‬ﷸ‬
./validate-instalation.sh with\ spaces\ And\ Weird\ %26\ Characters\ Čeština\ 漢字\ водка\ 昨夜のコ\ ﷹ‬ﷸ‬ amq\ with\ spaces