Search in sources :

Example 6 with JMSSecurityException

use of jakarta.jms.JMSSecurityException in project openmq by eclipse-ee4j.

the class DirectConnectionFactory method _createConnectionId.

// ///////////////////////////////////////////////////////////////////////
// end jakarta.jms.TopicConnectionFactory
// ///////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////
// MQ methods
// ///////////////////////////////////////////////////////////////////////
/**
 * Create a connection with the jmsservice and return a connectionId. Used by the methods implementing
 * jakarta.jms.Connection, jakarta.jms.QueueConnection, and jakarta.jms.TopicConnection
 *
 * @param username The username that should be used to authenticate the creation of the connection with the jmsservice
 * @param password The password that should be used to authenticate the creation of the connection with the jmsservice
 *
 * @return The connectionId to be used by the DirectConnection object that is returned by the JMS API method
 *
 * @throws JMSSecurityException if the specified user identity does not authenticate successfully with the JMS server
 * @throws JMSException if any JMS server error occurred
 */
private long _createConnectionId(String username, String password) throws JMSException {
    JMSServiceReply reply;
    long connectionId = 0L;
    if (this.jmsservice == null) {
        if (this.ra != null) {
            this.jmsservice = this.ra._getJMSService();
        }
        if (this.jmsservice == null) {
            // Ultimate fallback :)
            this.jmsservice = ResourceAdapter._getRAJMSService();
        }
    }
    assert (this.jmsservice != null);
    try {
        reply = jmsservice.createConnection(username, password);
        try {
            connectionId = reply.getJMQConnectionID();
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConnectionID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJF.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        JMSException jmsse;
        String failure_cause;
        boolean security_exception = true;
        switch(status) {
            case INVALID_LOGIN:
                failure_cause = "authentication failure.";
                break;
            case FORBIDDEN:
                failure_cause = "authorization failure.";
                break;
            default:
                failure_cause = "unkown JMSService server error.";
                security_exception = false;
        }
        String exerrmsg = "createConnection on JMSService:" + jmsservice.getJMSServiceID() + " failed for username:" + username + " due to " + failure_cause;
        _loggerJF.severe(exerrmsg);
        jmsse = (security_exception ? new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode()) : new JMSException(exerrmsg, jse.getJMSServiceReply().getErrorCode()));
        jmsse.initCause(jse);
        throw jmsse;
    }
    return connectionId;
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Aggregations

JMSSecurityException (jakarta.jms.JMSSecurityException)6 JMSException (jakarta.jms.JMSException)5 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)4 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)4 InvalidSelectorException (jakarta.jms.InvalidSelectorException)2 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 IllegalStateException (com.sun.messaging.jms.IllegalStateException)1 Connection (jakarta.jms.Connection)1 InvalidClientIDException (jakarta.jms.InvalidClientIDException)1 XAConnection (jakarta.jms.XAConnection)1 XAConnectionFactory (jakarta.jms.XAConnectionFactory)1 IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1