简体   繁体   中英

How to use Java JMS Authentication only on ConnectionFactory

I am currently deploying a REST application to publish messages to JMS but in order to connect thru the QueueConnectionFactory we are creating the context but we want to use the username and password which was defined on layer of Webpshere and JMS, bypassing the authentication on java code for createContext().

I do not want to pass the authentication on java code, once the user and password was connected on JMS .

Below is the code used:

    try {

        javax.naming.Context ctx = new InitialContext();

        QueueConnectionFactory jmsCF =  (QueueConnectionFactory) ctx.lookup("jms/bapssdEE/iwszQCF");

        Queue jmsQ = (Queue) ctx.lookup("jms/bapssdEE/iwszQ");

        // This part we are bypassing the authentication
        try (JMSContext context = jmsCF.createContext()) {


}

When the program runs we are getting the following sysout on log :

[12/4/18 22:00:31:170 BRST] 0000017d SibMessage W
[BAP_BUS:productionbackupNode01.server1-BAP_BUS] CWSII0212W: The bus BAP_BUS denied an anonymous user access to the bus. [12/4/18 22:00:31:249 BRST] 0000017d SystemOut O <<<--- AutosysExecProvider.putRequestInJMSQueue method.

I have setup the Username and password on Webpshere using the WAS path: Resources \\ JMS \\ Connection Factories \\ New

Good news, issue resolved after using the annotations below and changing the method to post the message thru the JMS:

@Resource(lookup = "jms/bapssdEE/autosysCF")
ConnectionFactory connectionFactory;

@Resource(lookup = "jms/bapssdEE/autosysQ")
Queue demoQueue;

private void putRequestInJMSQueue(String envelope) {
try (JMSContext context = connectionFactory.createContext();){
context.createProducer().send(demoQueue, envelope);

Also important thing we just defined the user created on Webpshere at the field Mapping-configuraiton alias and then the messages were posted to JMS without expose the username and password on code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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