|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +################################################################################ |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 5 | +# or more contributor license agreements. See the NOTICE file |
| 6 | +# distributed with this work for additional information |
| 7 | +# regarding copyright ownership. The ASF licenses this file |
| 8 | +# to you under the Apache License, Version 2.0 (the |
| 9 | +# "License"); you may not use this file except in compliance |
| 10 | +# with the License. You may obtain a copy of the License at |
| 11 | +# |
| 12 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +# |
| 14 | +# Unless required by applicable law or agreed to in writing, software |
| 15 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +# See the License for the specific language governing permissions and |
| 18 | +# limitations under the License. |
| 19 | +################################################################################ |
| 20 | + |
| 21 | +# Transport/connection security |
| 22 | +if [ -n "${ACTIVEMQ_CONNECTION_USER}" ]; then |
| 23 | + if [ -f "${ACTIVEMQ_HOME}/conf/connection.security.enabled" ]; then |
| 24 | + echo "ActiveMQ Connection Security enabled" |
| 25 | + else |
| 26 | + echo "Enabling ActiveMQ Connection Security" |
| 27 | + sed -i "s/activemq.username=system/activemq.username=${ACTIVEMQ_CONNECTION_USER}/" ${ACTIVEMQ_HOME}/conf/credentials.properties |
| 28 | + sed -i "s/activemq.password=manager/activemq.password=${ACTIVEMQ_CONNECTION_PASSWORD}/" ${ACTIVEMQ_HOME}/conf/credentials.properties |
| 29 | + read -r -d '' REPLACE << END |
| 30 | + <plugins> |
| 31 | + <simpleAuthenticationPlugin> |
| 32 | + <users> |
| 33 | + <authenticationUser username="$\{activemq.username}" password="$\{activemq.password}"/> |
| 34 | + </users> |
| 35 | + </simpleAuthenticationPlugin> |
| 36 | + </plugins> |
| 37 | + </broker> |
| 38 | +END |
| 39 | + REPLACE=${REPLACE//$\\/$} |
| 40 | + REPLACE=${REPLACE//\//\\\/} |
| 41 | + REPLACE=$(echo $REPLACE | tr '\n' ' ') |
| 42 | + sed -i "s/<\/broker>/$REPLACE/" ${ACTIVEMQ_HOME}/conf/activemq.xml |
| 43 | + touch "${ACTIVEMQ_HOME}/conf/connection.security.enabled" |
| 44 | + fi |
| 45 | +fi |
| 46 | + |
| 47 | +# JMX security |
| 48 | +if [ -n "${ACTIVEMQ_JMX_USER}" ]; then |
| 49 | + if [ -f "${ACTIVEMQ_HOME}/conf/jmx.security.enabled" ]; then |
| 50 | + echo "JMX Security already enabled" |
| 51 | + else |
| 52 | + echo "Enabling ActiveMQ JMX security" |
| 53 | + read -r -d '' REPLACE << END |
| 54 | + <managementContext> |
| 55 | + <managementContext createConnector="true" /> |
| 56 | + </managementContext> |
| 57 | + </broker> |
| 58 | +END |
| 59 | + REPLACE=${REPLACE//\//\\\/} |
| 60 | + REPLACE=${REPLACE//$\\/$} |
| 61 | + REPLACE=$(echo $REPLACE | tr '\n' ' ') |
| 62 | + sed -i "s/<\/broker>/$REPLACE/" ${ACTIVEMQ_HOME}/conf/activemq.xml |
| 63 | + sed -i "s/admin/${ACTIVEMQ_JMX_USER}/" ${ACTIVEMQ_HOME}/conf/jmx.access |
| 64 | + sed -i "s/admin/${ACTIVEMQ_JMX_USER}/" ${ACTIVEMQ_HOME}/conf/jmx.password |
| 65 | + if [ -n "${ACTIVEMQ_JMX_PASSWORD}" ]; then |
| 66 | + sed -i "s/\ activemq/\ ${ACTIVEMQ_JMX_PASSWORD}/" ${ACTIVEMQ_HOME}/conf/jmx.password |
| 67 | + fi |
| 68 | + touch "${ACTIVEMQ_HOME}/conf/jmx.security.enabled" |
| 69 | + fi |
| 70 | +fi |
| 71 | + |
| 72 | +# WebConsole security |
| 73 | +if [ -n "${ACTIVEMQ_WEB_USER}" ]; then |
| 74 | + echo "Enabling ActiveMQ WebConsole security" |
| 75 | + sed -i s/admin=/${ACTIVEMQ_WEB_USER}=/g ${ACTIVEMQ_HOME}/conf/users.properties |
| 76 | + if [ -n "${ACTIVEMQ_WEB_PASSWORD}" ]; then |
| 77 | + sed -i s/=admin/=${ACTIVEMQ_WEB_PASSWORD}/g ${ACTIVEMQ_HOME}/conf/users.properties |
| 78 | + fi |
| 79 | +fi |
| 80 | + |
| 81 | +if [ -z "${ACTIVEMQ_OPTS_MEMORY}" ]; then |
| 82 | + ACTIVEMQ_OPTS_MEMORY="-Xms64M -Xmx1G" |
| 83 | + export ACTIVEMQ_OPTS_MEMORY |
| 84 | +fi |
| 85 | + |
| 86 | +if [ -z "${ACTIVEMQ_OPTS}" ]; then |
| 87 | + # Make the Web console accesible from outside the container if not already set |
| 88 | + ACTIVEMQ_OPTS="${ACTIVEMQ_OPTS_MEMORY} -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=${ACTIVEMQ_CONF}/login.config -Djetty.host=0.0.0.0" |
| 89 | + export ACTIVEMQ_OPTS |
| 90 | +fi |
| 91 | + |
| 92 | +exec "$@" |
0 commit comments