简体   繁体   English

通过 Spring Boot 连接到 Tibco 主题时身份验证失败

[英]Authentication failure while connecting to Tibco topic through Spring Boot

I am trying to listen to messages coming through a Tibco topic in my spring boot application.我正在尝试在我的 spring 启动应用程序中收听来自 Tibco 主题的消息。 My config looks like this -我的配置看起来像这样 -

@Configuration
@EnableJms
public class TibcoConfig {

    @Bean
    public ConnectionFactory connectionFactory() {
        TopicConnectionFactory factory = new TibjmsTopicConnectionFactory("TIBCO_BROKER_URL");
        return factory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setClientId("client1");
        factory.setPubSubDomain(true);
        factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
        return factory;
    }

    @Bean
    public UserCredentialsConnectionFactoryAdapter authenticationConnectionFactory() {
        UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
        userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(connectionFactory());
        userCredentialsConnectionFactoryAdapter.setUsername("USERNAME");
        userCredentialsConnectionFactoryAdapter.setPassword("PASSWORD");
        return userCredentialsConnectionFactoryAdapter;
    }
}

And my listener looks like this -我的听众看起来像这样 -

@Component
public class TibcoRequestListener {

    @JmsListener(destination = "TIBCO_TOPIC_NAME", containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(Message message) {
        try {
            TextMessage txtMsg = (TextMessage) message;
            System.out.println("Received response: " + txtMsg.getText());
            System.out.println("Message type: " + message.getJMSType());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Error log -错误日志 -

2020-07-08 18:28:37.711  WARN 3552 --- [)-10.110.74.130] o.s.boot.actuate.jms.JmsHealthIndicator  : JMS health check failed

javax.jms.JMSSecurityException: authentication failed
    at com.tibco.tibjms.Tibjmsx.buildException(Tibjmsx.java:575) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1330) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4115) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsTopicConnection.<init>(TibjmsTopicConnection.java:36) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsxCFImpl._createImpl(TibjmsxCFImpl.java:191) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsxCFImpl._createConnection(TibjmsxCFImpl.java:253) ~[tibjms-5.1.0.jar:5.1.0]
    at com.tibco.tibjms.TibjmsConnectionFactory.createConnection(TibjmsConnectionFactory.java:36) ~[tibjms-5.1.0.jar:5.1.0]
    at org.springframework.boot.actuate.jms.JmsHealthIndicator.doHealthCheck(JmsHealthIndicator.java:52) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:81) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:38) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:108) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:119) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:105) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:83) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:70) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:75) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:65) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:77) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) ~[spring-boot-actuator-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809) ~[na:na]
    at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) ~[na:na]
    at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827) ~[na:na]
    at java.base/jdk.internal.reflect.GeneratedMethodAccessor147.invoke(Unknown Source) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) ~[na:na]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:691) ~[na:na]
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705) ~[na:na]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) ~[na:na]
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

2020-07-08 18:28:39.955 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: authentication failed
2020-07-08 18:28:45.033 ERROR 3552 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'TIBCO_TOPIC_NAME' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: authentication failed
...
...
...

Why is the spring boot application unable to authenticate the connection to the tibco topic even though the username and password is provided via UserCredentialsConnectionFactoryAdapter?为什么即使通过 UserCredentialsConnectionFactoryAdapter 提供了用户名和密码,spring 引导应用程序也无法验证与 tibco 主题的连接? Do I need to configure anything else?我还需要配置什么吗?

I am able to connect to this topic and receive messages successfully using the same credentials in a different setup that doesn't use spring boot.我能够连接到该主题并在不使用 spring 引导的不同设置中使用相同的凭据成功接收消息。 And I need to make this work with an existing Spring boot application.我需要使用现有的 Spring 引导应用程序来完成这项工作。

Was able to figure out the solution in case anyone else is stuck.能够找出解决方案,以防其他人被卡住。 In spring boot, TopicConnectionFactory object is not required to specify that we need to connect to a Tibco Topic (and not a Queue), which is needed in standalone application.在 spring 引导中,TopicConnectionFactory object 不需要指定我们需要连接到独立应用程序中需要的 Tibco 主题(而不是队列)。 It is automatically done when PubSubDomain property is set to true.当 PubSubDomain 属性设置为 true 时,它会自动完成。 So, use TibjmsConnectionFactory instead which has methods to set credentials.因此,请改用具有设置凭据的方法的 TibjmsConnectionFactory。 UserCredentialsConnectionFactoryAdapter is not needed at all.根本不需要 UserCredentialsConnectionFactoryAdapter。

I changed my config code to below and it started working!我将我的配置代码更改为下面,它开始工作了!

@Configuration
@EnableJms
public class TibcoConfig {

    @Bean
    public ConnectionFactory connectionFactory() {
        TibjmsConnectionFactory factory = new TibjmsConnectionFactory("TIBCO_BROKER_URL");
        factory.setUserName("USERNAME");
        factory.setUserPassword("PASSWORD");
        return factory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setClientId("client1");
        factory.setPubSubDomain(true);
        factory.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
        return factory;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM