gpt4 book ai didi

spring - 针对dockerized和链接的ActiveMQ对dockerized Spring Boot应用进行身份验证

转载 作者:行者123 更新时间:2023-12-02 18:24:59 26 4
gpt4 key购买 nike

我正在像这样启动我的activemq容器:

docker run -p 61616:61616 -p 8161:8161 --name='activemq' -d \
-e 'ACTIVEMQ_LOGLEVEL=DEBUG' \
-e 'ACTIVEMQ_ADMIN_USER=bot' \
-e 'ACTIVEMQ_ADMIN_PASSWORD=blahblah' \
-e 'ACTIVEMQ_OWNER_LOGIN=bot' \
-e 'ACTIVEMQ_OWNER_PASSWORD=blahblah' \
-e 'ACTIVEMQ_JMX_LOGIN=bot' \
-e 'ACTIVEMQ_JMX_PASSWORD=blahblah' \
-v /data/activemq:/data/activemq \
-v /var/log/activemq:/var/log/activemq \
webcenter/activemq:latest

我的应用程序的application.yml具有以下内容:
spring:
activemq:
broker-url: ${ACTIVEMQ_PORT_61616_TCP}
user: bot
password: blahblah

我像这样启动我的应用程序容器:
docker run --name='myapp' \
-w /app/ -v /home/ubuntu/myapp/logs:/app/logs \
-v /home/ubuntu/myapp/config:/app/config \
-v /tmp:/tmp -p 4980:4980 \
--link activemq:activemq \
-d myapp

请注意,我将应用程序的容器与activemq容器链接在一起。

最后,当我尝试从我的应用程序(通过 Camel 路线)向ActiveMQ发送消息时,但我认为这无关紧要,我在日志中看到了这一点:
javax.jms.JMSSecurityException: User name [bot] or password is invalid.
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:52)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1417)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1522)
at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:527)
at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:400)
at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:907)
at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:882)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1053)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.SecurityException: User name [bot] or password is invalid.
at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:80)
at org.apache.activemq.broker.BrokerFilter.addConnection(BrokerFilter.java:92)
at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97)
at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:764)
at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)
at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)
at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:294)
at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:148)
at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)
at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)
at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:270)
at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:214)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
... 1 common frames omitted
Caused by: javax.security.auth.login.LoginException: No LoginModules configured for activemq-domain
at javax.security.auth.login.LoginContext.init(LoginContext.java:264)
at javax.security.auth.login.LoginContext.<init>(LoginContext.java:417)
at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:72)
... 14 common frames omitted

不用说,在我的开发机器上本地运行这些组件(即未进行dockerized)时,这一切都“正常”。只是在EC2实例上的docker容器内不起作用。

任何和所有帮助表示赞赏!

谢谢。

最佳答案

我最终通过自定义docker镜像使其工作,如下所示:

  • 克隆git仓库:git clone https://github.com/disaster37/activemq.git
  • 修复传递给该文件中curl的URL:assets/setup/install(该文件中的当前URL不再起作用)
  • 编辑此文件:assets/config/activemq.xml,并使用以下命令替换<jaasAuthenticationPlugin><authorizationPlugin>元素:
  • <simpleAuthenticationPlugin anonymousAccessAllowed="false">
    <users>
    <authenticationUser username="system" password="blubblub" groups="users,admins"/>
    <authenticationUser username="bot" password="blahblah" groups="users"/>
    </users>
    </simpleAuthenticationPlugin>
  • 构建我自己的docker镜像:docker build --tag="zackattack/activemq"
  • 运行它:docker logs -f $(docker run --name='activemq' -d zackattack/activemq)

  • 它不是很漂亮-但可以!

    关于spring - 针对dockerized和链接的ActiveMQ对dockerized Spring Boot应用进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29704157/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com