Search in sources :

Example 1 with AuthenticationException

use of com.swiftmq.swiftlet.auth.AuthenticationException in project swiftmq-client by iitsoftware.

the class ReplyNE method createException.

private void createException(String className, String msg) throws Exception {
    if (className.equals("com.swiftmq.swiftlet.queue.QueueException"))
        exception = new QueueException(msg);
    else if (className.equals("com.swiftmq.swiftlet.queue.QueueLimitException"))
        exception = new QueueLimitException(msg);
    else if (className.equals("com.swiftmq.swiftlet.queue.UnknownQueueException"))
        exception = new InvalidDestinationException(msg);
    else if (className.equals("com.swiftmq.swiftlet.auth.ResourceLimitException"))
        exception = new ResourceLimitException(msg);
    else if (className.equals("com.swiftmq.swiftlet.auth.AuthenticationException"))
        exception = new AuthenticationException(msg);
    else if (className.equals("javax.jms.InvalidDestinationException"))
        exception = new InvalidDestinationException(msg);
    else
        exception = new Exception(className + ": " + msg);
}
Also used : QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) QueueException(com.swiftmq.swiftlet.queue.QueueException) InvalidDestinationException(javax.jms.InvalidDestinationException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueException(com.swiftmq.swiftlet.queue.QueueException) QueueLimitException(com.swiftmq.swiftlet.queue.QueueLimitException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 2 with AuthenticationException

use of com.swiftmq.swiftlet.auth.AuthenticationException in project swiftmq-ce by iitsoftware.

the class SourceLink method verifyLocalAddress.

public void verifyLocalAddress() throws AuthenticationException, QueueException, TopicException, InvalidSelectorException {
    if (!dynamic) {
        // This is for the case of reconnecting to a Durable Subscriber without specifying a Source in the attach frame.
        if (localAddress == null) {
            String topicName = ctx.topicManager.getDurableTopicName(getName(), mySessionHandler.getVersionedConnection().getActiveLogin());
            if (topicName != null)
                localAddress = new AddressString(topicName);
            durability = TerminusDurability.CONFIGURATION;
        }
        super.verifyLocalAddress();
    }
    if (receiver == null) {
        MessageSelector msel = null;
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (dynamic) {
            expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
            durability = TerminusDurability.NONE;
            // sndSettleMode = SenderSettleMode.SETTLED.getValue();       // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
            queueName = ctx.queueManager.createTemporaryQueue();
            receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
        } else {
            if (isQueue) {
                expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                durability = TerminusDurability.CONFIGURATION;
                // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                receiver = ctx.queueManager.createQueueReceiver(getLocalAddress().getValueString(), mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
            } else {
                if (durability.getValue() == TerminusDurability.CONFIGURATION.getValue() || durability.getValue() == TerminusDurability.UNSETTLED_STATE.getValue()) {
                    if (!expiryPolicy.getValue().equals(TerminusExpiryPolicy.LINK_DETACH.getValue()))
                        expiryPolicy = TerminusExpiryPolicy.NEVER;
                    durability = TerminusDurability.CONFIGURATION;
                    // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                    queueName = ctx.topicManager.subscribeDurable(name, (TopicImpl) getLocalDestination(), msel, noLocal, mySessionHandler.getVersionedConnection().getActiveLogin());
                } else {
                    expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                    queueName = ctx.queueManager.createTemporaryQueue();
                    // sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
                    subscriberId = ctx.topicManager.subscribe((TopicImpl) localDestination, msel, noLocal, queueName, mySessionHandler.getVersionedConnection().getActiveLogin());
                }
                receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), null);
            }
        }
    }
    if (remoteUnsettled != null) {
        final AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(receiver.getQueueName());
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, abstractQueue=" + aq);
        DataByteArrayInputStream dbis = new DataByteArrayInputStream();
        for (Iterator iter = remoteUnsettled.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            AMQPBinary deliveryTag = (AMQPBinary) entry.getKey();
            DeliveryStateIF deliveryStateIF = null;
            try {
                deliveryStateIF = DeliveryStateFactory.create((AMQPList) entry.getValue());
            } catch (Exception e) {
                throw new QueueException("Unable to create delivery tag");
            }
            final MessageIndex messageIndex = new MessageIndex();
            dbis.setBuffer(deliveryTag.getValue());
            try {
                messageIndex.readContent(dbis);
            } catch (IOException e) {
                throw new QueueException("Unable to convert delivery tag into a message index");
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", deliveryStateIF=" + deliveryStateIF);
            if (deliveryStateIF != null) {
                deliveryStateIF.accept(new DeliveryStateVisitorAdapter() {

                    public void visit(Accepted accepted) {
                        try {
                            if (aq != null) {
                                MessageIndex indexEntry = aq.getIndexEntry(messageIndex);
                                if (indexEntry != null) {
                                    aq.removeMessageByIndex(indexEntry);
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + indexEntry + ", removed");
                                } else {
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", NOT FOUND!");
                                }
                            }
                        } catch (QueueException e) {
                            e.printStackTrace();
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", exception=" + e);
                        }
                    }
                });
            }
        }
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException) Iterator(java.util.Iterator) MessageSelector(com.swiftmq.ms.MessageSelector) TopicImpl(com.swiftmq.jms.TopicImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with AuthenticationException

use of com.swiftmq.swiftlet.auth.AuthenticationException in project swiftmq-ce by iitsoftware.

the class MQTTConnection method visit.

@Override
public void visit(POConnect po) {
    if (closed || protocolInvalid)
        return;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    if (nConnectPackets > 0) {
        protocolInvalid = true;
        initiateClose("protocol error, multiple connect packets");
        return;
    }
    nConnectPackets++;
    connectMessage = po.getMessage();
    MqttConnectVariableHeader variableConnectHeader = connectMessage.variableHeader();
    MqttConnectPayload payload = connectMessage.payload();
    clientId = payload.clientIdentifier();
    if (clientId == null || clientId.length() == 0) {
        if (!variableConnectHeader.isCleanSession())
            rc = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED;
        else
            clientId = UUID.randomUUID().toString();
    }
    if (rc == null) {
        String password = null;
        if (variableConnectHeader.hasUserName())
            username = payload.userName();
        if (variableConnectHeader.hasPassword())
            password = new String(payload.passwordInBytes());
        try {
            ctx.authSwiftlet.verifyHostLogin(username, remoteHostname);
            String pwd = ctx.authSwiftlet.getPassword(username);
            if (password == pwd || password != null && password.equals(pwd)) {
                rc = MqttConnectReturnCode.CONNECTION_ACCEPTED;
                activeLogin = ctx.authSwiftlet.createActiveLogin(username, "MQTT");
                activeLogin.setClientId(clientId);
                authenticated = true;
            } else
                throw new AuthenticationException("invalid password");
            keepaliveInterval = (long) ((double) (variableConnectHeader.keepAliveTimeSeconds() * 1000.0) * 1.5);
            if (keepaliveInterval > 0) {
                ctx.timerSwiftlet.addTimerListener(keepaliveInterval, this);
            }
            if (variableConnectHeader.isWillFlag())
                will = new Will(payload.willTopic(), variableConnectHeader.willQos(), variableConnectHeader.isWillRetain(), payload.willMessageInBytes());
            cleanSession = variableConnectHeader.isCleanSession();
            if (!cleanSession) {
                ctx.sessionRegistry.associateSession(clientId, this);
            } else {
                ctx.sessionRegistry.removeSession(clientId);
                MQTTSession session = new MQTTSession(ctx, clientId, false);
                session.associate(this);
                associated(session);
            }
            hasLastWill = variableConnectHeader.isWillFlag();
            lastWillRetain = variableConnectHeader.isWillRetain();
            lastWillQoS = MqttQoS.valueOf(variableConnectHeader.willQos());
            lastWillTopic = payload.willTopic();
            lastWillPayload = new ByteBuf(payload.willMessageInBytes());
            try {
                usage.getProperty("client-id").setValue(clientId);
                usage.getProperty("username").setValue(username);
                usage.getProperty("mqtt-protlevel").setValue(variableConnectHeader.version());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (AuthenticationException e) {
            rc = MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD;
        } catch (ResourceLimitException e) {
            rc = MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED;
        }
    }
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, connectMessage.fixedHeader().isDup(), connectMessage.fixedHeader().qosLevel(), connectMessage.fixedHeader().isRetain(), 2);
    MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(rc, false);
    connAckMessage = new MqttConnAckMessage(fixedHeader, variableHeader);
    if (rc != MqttConnectReturnCode.CONNECTION_ACCEPTED) {
        protocolInvalid = true;
        initiateClose("not authenticated");
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : MQTTSession(com.swiftmq.impl.mqtt.session.MQTTSession) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

Example 4 with AuthenticationException

use of com.swiftmq.swiftlet.auth.AuthenticationException in project swiftmq-ce by iitsoftware.

the class TopicManagerImpl method subscribeDurable.

private synchronized String subscribeDurable(String durableName, TopicImpl topic, Selector selector, boolean noLocal, ActiveLogin activeLogin, Entity newEntity, boolean verifyAuth) throws AuthenticationException, QueueException, QueueAlreadyDefinedException, UnknownQueueException, TopicException {
    String topicName = null;
    try {
        topicName = topic.getTopicName();
    } catch (JMSException ignored) {
    }
    if (verifyAuth)
        ctx.authSwiftlet.verifyTopicDurableSubscriberCreation(topicName, activeLogin.getLoginId());
    String durableQueueName = DurableSubscription.createDurableQueueName(activeLogin.getClientId(), durableName);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(getName(), "subscribeDurable: topic = " + topicName + ", durableQueueName = " + durableQueueName);
    DurableSubscription durable = (DurableSubscription) durableSubscriptions.get(durableQueueName);
    if (durable != null && durable.hasChanged(topicName, selector, noLocal)) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "subscribeDurable: durable has changed, deleting ...");
        unsubscribe(durable.getTopicSubscription().getSubscriberId());
        ctx.queueManager.purgeQueue(durableQueueName);
        ctx.queueManager.deleteQueue(durableQueueName, false);
        durableSubscriptions.remove(durableQueueName);
        try {
            durableStore.deleteDurableStoreEntry(durable.getClientId(), durable.getDurableName());
        } catch (Exception e) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "subscribeDurable: error deleting durable subscription: " + e);
            throw new TopicException("error deleting durable subscription: " + e);
        }
        durable = null;
        ctx.activeDurableList.removeDynamicEntity(durable);
    }
    if (durable == null) {
        durable = new DurableSubscription(activeLogin.getClientId(), durableName, topicName, selector, noLocal);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(getName(), "subscribeDurable: creating new durable = " + durable);
        durableSubscriptions.put(durableQueueName, durable);
        try {
            durableStore.insertDurableStoreEntry(durable.getDurableStoreEntry());
        } catch (Exception e) {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(getName(), "subscribeDurable: error saving durable subscription: " + e);
            throw new TopicException("error saving durable subscription: " + e);
        }
        ctx.queueManager.createQueue(durableQueueName, (ActiveLogin) null);
        int id = subscribe(topic, selector, noLocal, durableQueueName, activeLogin);
        durable.setTopicSubscription((TopicSubscription) topicSubscriptions.get(id));
        try {
            if (newEntity == null) {
                Entity durEntity = ctx.activeDurableList.createEntity();
                durEntity.setName(durableQueueName);
                durEntity.setDynamicObject(durable);
                durEntity.createCommands();
                Property prop = durEntity.getProperty("clientid");
                prop.setValue(activeLogin.getClientId());
                prop.setReadOnly(true);
                prop = durEntity.getProperty("durablename");
                prop.setValue(durableName);
                prop.setReadOnly(true);
                prop = durEntity.getProperty("topic");
                prop.setValue(topicName);
                prop.setReadOnly(true);
                prop = durEntity.getProperty("boundto");
                prop.setValue(durableQueueName);
                prop.setReadOnly(true);
                prop = durEntity.getProperty("nolocal");
                prop.setValue(new Boolean(noLocal));
                prop.setReadOnly(true);
                prop = durEntity.getProperty("selector");
                if (selector != null) {
                    prop.setValue(selector.getConditionString());
                }
                prop.setReadOnly(true);
                programmaticDurableInProgress = true;
                ctx.activeDurableList.addEntity(durEntity);
                programmaticDurableInProgress = false;
            } else {
                newEntity.setDynamicObject(durable);
                Property prop = newEntity.getProperty("boundto");
                prop.setValue(durableQueueName);
                prop.setReadOnly(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return durableQueueName;
}
Also used : TopicException(com.swiftmq.swiftlet.topic.TopicException) JMSException(javax.jms.JMSException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) SwiftletException(com.swiftmq.swiftlet.SwiftletException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) TopicException(com.swiftmq.swiftlet.topic.TopicException)

Aggregations

AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)4 IOException (java.io.IOException)3 ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)2 TopicException (com.swiftmq.swiftlet.topic.TopicException)2 InvalidDestinationException (javax.jms.InvalidDestinationException)2 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 MQTTSession (com.swiftmq.impl.mqtt.session.MQTTSession)1 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 TopicImpl (com.swiftmq.jms.TopicImpl)1 MessageSelector (com.swiftmq.ms.MessageSelector)1 SwiftletException (com.swiftmq.swiftlet.SwiftletException)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)1 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 InvalidSelectorException (javax.jms.InvalidSelectorException)1 JMSException (javax.jms.JMSException)1