Search in sources :

Example 46 with ResourceLimitException

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

the class NontransactedQueueSession method visit.

public void visit(CreateProducerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
    CreateProducerReply reply = (CreateProducerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    try {
        int producerId;
        QueueProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new QueueProducer(ctx, queue.getQueueName());
        producerList.set(producerId, producer);
        reply.setQueueProducerId(producerId);
        reply.setOk(true);
        if (senderEntityList != null) {
            Entity senderEntity = senderEntityList.createEntity();
            senderEntity.setName(queue.getQueueName() + "-" + producerId);
            senderEntity.setDynamicObject(producer);
            senderEntity.createCommands();
            Property prop = senderEntity.getProperty("queue");
            prop.setValue(queue.getQueueName());
            prop.setReadOnly(true);
            senderEntityList.addEntity(senderEntity);
        }
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 47 with ResourceLimitException

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

the class TransactedQueueSession method visit.

public void visit(CreateProducerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateProducerRequest");
    CreateProducerReply reply = (CreateProducerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incProducers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    try {
        int producerId;
        QueueProducer producer;
        producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
        producer = new QueueProducer(ctx, queue.getQueueName());
        producerList.set(producerId, producer);
        reply.setQueueProducerId(producerId);
        reply.setOk(true);
        if (senderEntityList != null) {
            Entity senderEntity = senderEntityList.createEntity();
            senderEntity.setName(queue.getQueueName() + "-" + producerId);
            senderEntity.setDynamicObject(producer);
            senderEntity.createCommands();
            Property prop = senderEntity.getProperty("queue");
            prop.setValue(queue.getQueueName());
            prop.setReadOnly(true);
            senderEntityList.addEntity(senderEntity);
        }
        // enlist it at the transaction manager
        transactionManager.addTransactionFactory(producer);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating producer: " + e.getMessage());
        reply.setOk(false);
        reply.setException(e);
        ctx.activeLogin.getResourceLimitGroup().decProducers();
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) JMSException(javax.jms.JMSException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException)

Example 48 with ResourceLimitException

use of com.swiftmq.swiftlet.auth.ResourceLimitException 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 49 with ResourceLimitException

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

the class NontransactedQueueSession method visitCreateConsumerRequest.

public void visitCreateConsumerRequest(CreateConsumerRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateConsumerRequest");
    CreateConsumerReply reply = (CreateConsumerReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incConsumers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    QueueImpl queue = req.getQueue();
    String messageSelector = req.getMessageSelector();
    String queueName = null;
    try {
        queueName = queue.getQueueName();
    } catch (JMSException ignored) {
    }
    try {
        if (!queueName.endsWith('@' + SwiftletManager.getInstance().getRouterName()))
            throw new InvalidDestinationException("Queue '" + queueName + "' is not local! Can't create a Consumer on it!");
        int consumerId = 0;
        QueueConsumer consumer = null;
        consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
        consumer = new QueueConsumer(ctx, queueName, messageSelector);
        consumerList.set(consumerId, consumer);
        consumer.createReadTransaction();
        consumer.createTransaction();
        reply.setOk(true);
        reply.setQueueConsumerId(consumerId);
        if (receiverEntityList != null) {
            Entity consEntity = receiverEntityList.createEntity();
            consEntity.setName(queueName + "-" + consumerId);
            consEntity.setDynamicObject(consumer);
            consEntity.createCommands();
            Property prop = consEntity.getProperty("queue");
            prop.setValue(queueName);
            prop.setReadOnly(true);
            prop = consEntity.getProperty("selector");
            if (messageSelector != null) {
                prop.setValue(messageSelector);
            }
            prop.setReadOnly(true);
            receiverEntityList.addEntity(consEntity);
        }
    } catch (InvalidSelectorException e) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateConsumer has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e1) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create consumer: " + e1);
        reply.setOk(false);
        reply.setException((e1 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) QueueImpl(com.swiftmq.jms.QueueImpl) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) InvalidDestinationException(javax.jms.InvalidDestinationException) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

Example 50 with ResourceLimitException

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

the class NontransactedTopicSession method visitCreateDurableRequest.

public void visitCreateDurableRequest(CreateDurableRequest req) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateDurableRequest");
    CreateDurableReply reply = (CreateDurableReply) req.createReply();
    try {
        ctx.activeLogin.getResourceLimitGroup().incConsumers();
    } catch (ResourceLimitException e) {
        reply.setOk(false);
        reply.setException(new JMSException(e.toString()));
        reply.send();
        return;
    }
    TopicImpl topic = req.getTopic();
    String messageSelector = req.getMessageSelector();
    boolean noLocal = req.isNoLocal();
    String durableName = req.getDurableName();
    try {
        int consumerId = 0;
        TopicDurableConsumer consumer = null;
        consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
        consumer = new TopicDurableConsumer(ctx, durableName, topic, messageSelector, noLocal);
        consumerList.set(consumerId, consumer);
        consumer.createReadTransaction();
        consumer.createTransaction();
        reply.setOk(true);
        reply.setTopicSubscriberId(consumerId);
        reply.setQueueName(((TopicDurableConsumer) consumer).getQueueName() + '@' + SwiftletManager.getInstance().getRouterName());
        if (durableEntityList != null) {
            Entity durEntity = durableEntityList.createEntity();
            durEntity.setName(ctx.activeLogin.getClientId() + "$" + durableName);
            durEntity.createCommands();
            Property prop = durEntity.getProperty("clientid");
            prop.setValue(ctx.activeLogin.getClientId());
            prop.setReadOnly(true);
            prop = durEntity.getProperty("durablename");
            prop.setValue(durableName);
            prop.setReadOnly(true);
            prop = durEntity.getProperty("topic");
            prop.setValue(topic.getTopicName());
            prop.setReadOnly(true);
            prop = durEntity.getProperty("boundto");
            prop.setValue(consumer.getQueueName());
            prop.setReadOnly(true);
            prop = durEntity.getProperty("nolocal");
            prop.setValue(new Boolean(noLocal));
            prop.setReadOnly(true);
            prop = durEntity.getProperty("selector");
            if (messageSelector != null) {
                prop.setValue(messageSelector);
            }
            prop.setReadOnly(true);
            durableEntityList.addEntity(durEntity);
        }
    } catch (InvalidSelectorException e) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
        reply.setOk(false);
        reply.setException(e);
    } catch (Exception e1) {
        ctx.activeLogin.getResourceLimitGroup().decConsumers();
        ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
        reply.setOk(false);
        reply.setException((e1 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
    }
    reply.send();
}
Also used : Entity(com.swiftmq.mgmt.Entity) InvalidSelectorException(javax.jms.InvalidSelectorException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicImpl(com.swiftmq.jms.TopicImpl) Property(com.swiftmq.mgmt.Property) ResourceLimitException(com.swiftmq.swiftlet.auth.ResourceLimitException)

Aggregations

ResourceLimitException (com.swiftmq.swiftlet.auth.ResourceLimitException)142 Entity (com.swiftmq.mgmt.Entity)140 Property (com.swiftmq.mgmt.Property)140 InvalidSelectorException (javax.jms.InvalidSelectorException)140 JMSException (javax.jms.JMSException)140 InvalidDestinationException (javax.jms.InvalidDestinationException)99 TopicImpl (com.swiftmq.jms.TopicImpl)42 QueueImpl (com.swiftmq.jms.QueueImpl)28 com.swiftmq.jms (com.swiftmq.jms)16 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2 MQTTSession (com.swiftmq.impl.mqtt.session.MQTTSession)1 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1 QueueLimitException (com.swiftmq.swiftlet.queue.QueueLimitException)1 IOException (java.io.IOException)1