javax.jms.JMSSecurityException:用户名[null]或密码无效

时间:2016-07-12 12:35:00

标签: java jms activemq jndi jboss-amq

我有一个简单的JMS发送者和接收者 我使用jboss-amq作为经纪人 他们使用jndi来查找值。

jndi.properties

    java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
    java.naming.provider.url = tcp://localhost:61616
    java.naming.security.principal  = admin
    java.naming.security.credentials = admin
    connectionFactoryNames = ConnectionFactory
    queue.TRADE.Q = TRADE.Q

使用这些值我得到以下异常:

    Exception in thread "main" javax.jms.JMSSecurityException: User name [null] or password is invalid.
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:52)
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1393)
    at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1496)
    at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:523)
    at examples.JMSSender.main(JMSSender.java:26)
Caused by: java.lang.SecurityException: User name [null] or password is invalid.
    at org.apache.activemq.security.JaasAuthenticationBroker.authenticate(JaasAuthenticationBroker.java:89)
    at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:68)
    at org.apache.activemq.broker.BrokerFilter.addConnection(BrokerFilter.java:97)
    at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:102)
    at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:817)
    at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:77)
    at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)
    at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:338)
    at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:188)
    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:300)
    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)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.security.auth.login.LoginException: Username can not be null
    at org.apache.karaf.jaas.modules.properties.PropertiesLoginModule.login(PropertiesLoginModule.java:90)
    at org.apache.karaf.jaas.boot.ProxyLoginModule.login(ProxyLoginModule.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at javax.security.auth.login.LoginContext.invoke(LoginContext.java:755)
    at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
    at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
    at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
    at org.apache.activemq.security.JaasAuthenticationBroker.authenticate(JaasAuthenticationBroker.java:84)
    ... 15 more

我注意到如果我将以下内容添加到jndi文件

    userName=admin
    password=admin

这两个程序运行没有错误

那么,第一种方法有什么问题?

1 个答案:

答案 0 :(得分:1)

activemqconnectionfactory类是与connectionFactoryNames = ConnectionFactory属性一起使用的默认工厂,它设置IntrospectionSupport类以设置专门查找userName和Password属性而不是creds和principal

的属性。