Search in sources :

Example 1 with DestinationSpi

use of com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi in project openmq by eclipse-ee4j.

the class PacketHandler method checkServiceRestriction.

public void checkServiceRestriction(Packet msg, IMQConnection con, ErrHandler defhandler) throws BrokerException, IOException, ClassNotFoundException {
    Service service = con.getService();
    if (service.getServiceType() != ServiceType.NORMAL) {
        return;
    }
    int id = msg.getPacketType();
    if (id != PacketType.CREATE_DESTINATION && id != PacketType.ADD_CONSUMER && id != PacketType.ADD_PRODUCER) {
        return;
    }
    ServiceRestriction[] srs = service.getServiceRestrictions();
    if (srs == null) {
        return;
    }
    ServiceRestriction sr = null;
    for (int i = 0; i < srs.length; i++) {
        sr = srs[i];
        if (sr == ServiceRestriction.NO_SYNC_WITH_MASTERBROKER) {
            Hashtable prop = msg.getProperties();
            String dest = (String) prop.get("JMQDestination");
            int dtype = ((Integer) prop.get("JMQDestType")).intValue();
            if (id == PacketType.CREATE_DESTINATION) {
                if (!checkForAutoCreate(dtype)) {
                    return;
                }
                DestinationUID duid = DestinationUID.getUID(dest, DestType.isQueue(dtype));
                DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), duid);
                DestinationSpi d = ds[0];
                if (d != null) {
                    return;
                }
                if (DestType.isQueue(dtype) && DestType.isTemporary(dtype)) {
                    return;
                }
                String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
                String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_AUTO_CREATE_DEST, args);
                logger.log(logger.WARNING, emsg);
                waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
                return;
            } else if (DestType.isTopic(dtype)) {
                if (id == PacketType.ADD_PRODUCER) {
                    String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
                    String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_TOPIC_PRODUCER, args);
                    logger.log(logger.WARNING, emsg);
                    waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
                    return;
                } else {
                    String[] args = { Thread.currentThread().getName(), dest, service.toString(), sr.toString(true) };
                    String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_SERVICE_RESTRICTION_TOPIC_CONSUMER, args);
                    logger.log(logger.WARNING, emsg);
                    waitForMasterBrokerSync(con, msg, emsg, emsg, defhandler);
                    return;
                }
            }
        } else {
            throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.E_INTERNAL_BROKER_ERROR, "Unknown service restriction " + sr + " on service " + service));
        }
    }
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Hashtable(java.util.Hashtable) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi)

Example 2 with DestinationSpi

use of com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi in project openmq by eclipse-ee4j.

the class VerifyDestinationHandler method handle.

/**
 * Method to handle Destination (create or delete) messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    int status = Status.OK;
    String reason = null;
    assert msg.getPacketType() == PacketType.VERIFY_DESTINATION;
    Packet pkt = new Packet(con.useDirectBuffers());
    pkt.setConsumerID(msg.getConsumerID());
    pkt.setPacketType(PacketType.VERIFY_DESTINATION_REPLY);
    Hashtable hash = new Hashtable();
    Hashtable props = null;
    String selectorstr = null;
    int type = 0;
    try {
        props = msg.getProperties();
        String destination = (String) props.get("JMQDestination");
        Integer inttype = (Integer) props.get("JMQDestType");
        // destination & type required
        assert destination != null;
        type = (inttype == null) ? 0 : inttype.intValue();
        selectorstr = (String) props.get("JMQSelector");
        if (selectorstr != null) {
            Selector.compile(selectorstr);
        }
        boolean notFound = false;
        DestinationSpi d = null;
        if (DestinationUID.isWildcard(destination)) {
            // retrieve the list of destinations
            pkt.setWildcard(true);
            // see if there are any destinations that match
            DestinationUID duid = DestinationUID.getUID(destination, type);
            List[] ll = coreLifecycle.findMatchingIDs(con.getPartitionedStore(), duid);
            List l = ll[0];
            if (l.isEmpty()) {
                notFound = true;
            }
        } else {
            DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), destination, DestType.isQueue(type));
            d = ds[0];
            notFound = (d == null);
        }
        if (notFound) {
            // not found
            status = Status.NOT_FOUND;
            reason = "destination not found";
            hash.put("JMQCanCreate", Boolean.valueOf(coreLifecycle.canAutoCreate(DestType.isQueue(type))));
        } else {
            if (d != null) {
                hash.put("JMQDestType", Integer.valueOf(d.getType()));
            }
        }
    } catch (SelectorFormatException ex) {
        reason = ex.getMessage();
        status = Status.BAD_REQUEST;
        logger.log(Logger.WARNING, BrokerResources.W_SELECTOR_PARSE, selectorstr, ex);
    } catch (IOException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination - no properties", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (ClassNotFoundException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination -bad class", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (BrokerException ex) {
        reason = ex.getMessage();
        status = ex.getStatusCode();
        logger.logStack(Logger.DEBUG, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination ", ex);
    } catch (SecurityException ex) {
        reason = ex.getMessage();
        status = Status.FORBIDDEN;
        logger.log(Logger.WARNING, ex.toString(), ex);
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (reason != null) {
        hash.put("JMQReason", reason);
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    con.sendControlMessage(pkt);
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID)

Example 3 with DestinationSpi

use of com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi in project openmq by eclipse-ee4j.

the class PacketHandler method checkPermission.

public void checkPermission(int id, String op, String destination, int destTypeInt, IMQConnection con) throws AccessControlException, BrokerException {
    // Temporary destination should return null
    String destTypeStr = DestType.queueOrTopic(destTypeInt);
    if (destTypeStr == null) {
        return;
    }
    Service service = con.getService();
    int serviceType = service.getServiceType();
    if (!checkIsNonAdminDest(con, service, serviceType, destination)) {
        return;
    }
    String acdestination = destination;
    // if autocreate false, return to normal path
    if (id == PacketType.CREATE_DESTINATION) {
        if (!checkForAutoCreate(destTypeInt)) {
            return;
        }
        DestinationUID duid = DestinationUID.getUID(destination, DestType.isQueue(destTypeInt));
        DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), duid);
        DestinationSpi d = ds[0];
        if (d != null && !d.isAutoCreated()) {
            return;
        }
        acdestination = null;
    }
    checkPermission(con, service, serviceType, op, acdestination, destTypeStr, destination);
    // audit logging for destination authorization
    Globals.getAuditSession().destinationAuth(con.getUserName(), con.remoteHostString(), destTypeStr, acdestination, op, true);
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi)

Example 4 with DestinationSpi

use of com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi in project openmq by eclipse-ee4j.

the class DestinationHandler method handle.

/**
 * Method to handle Destination (create or delete) messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    int status = Status.OK;
    String reason = null;
    // XXX - REVISIT 2/25/00 racer
    // do we need to create a reply packet each time ?
    Packet pkt = new Packet(con.useDirectBuffers());
    pkt.setConsumerID(msg.getConsumerID());
    Hashtable hash = new Hashtable();
    Hashtable props = null;
    try {
        props = msg.getProperties();
    } catch (Exception ex) {
        assert false;
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to create/destroy destination - no properties", ex);
        throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "Can not handle create/destroy destination"));
    }
    String destination = (String) props.get("JMQDestination");
    Integer inttype = (Integer) props.get("JMQDestType");
    int type = (inttype == null) ? 0 : inttype.intValue();
    pkt.setPacketType(msg.getPacketType() + 1);
    if (msg.getPacketType() == PacketType.CREATE_DESTINATION) {
        if (DEBUG) {
            logger.log(Logger.DEBUGHIGH, "ConsumerHandler: handle() [ Received AddDestination message {0}]", msg.toString());
        }
        assert destination != null;
        assert inttype != null;
        if (con.isAdminConnection()) {
            type |= DestType.DEST_ADMIN | DestType.DEST_LOCAL | DestType.DEST_AUTO;
        }
        assert pkt.getPacketType() == PacketType.CREATE_DESTINATION_REPLY;
        try {
            DestinationSpi d = null;
            if (DestType.isTemporary(type)) {
                // deal w/ versioning .. only store
                // 3.5 or later
                boolean storeTemps = con.getConnectionUID().getCanReconnect();
                long reconnectTime = con.getReconnectInterval();
                DestinationSpi[] ds = Globals.getCoreLifecycle().createTempDestination(con.getPartitionedStore(), destination, type, con.getConnectionUID(), storeTemps, reconnectTime);
                d = ds[0];
                if (con.getConnectionUID().equals(d.getConnectionUID())) {
                    con.attachTempDestination(d.getDestinationUID());
                }
            } else if (destination.startsWith(Globals.INTERNAL_PREFIX)) {
            // do nothing
            } else if (DestinationUID.isWildcard(destination)) {
                pkt.setWildcard(true);
            // dont create a destination
            } else {
                DestinationSpi[] ds = Globals.getCoreLifecycle().getDestination(con.getPartitionedStore(), destination, type, true, !con.isAdminConnection());
                d = ds[0];
            }
            hash.put("JMQDestType", Integer.valueOf(type));
            hash.put("JMQDestUID", destination);
            /*
                 * Set XML Schema validation properties
                 */
            hash.put("JMQValidateXMLSchema", Boolean.valueOf(isXMLSchemaValidationOn(d)));
            String uris = getXMLSchemaURIList(d);
            if (uris != null) {
                hash.put("JMQXMLSchemaURIList", uris);
            }
            hash.put("JMQReloadXMLSchemaOnFailure", Boolean.valueOf(getReloadXMLSchemaOnFailure(d)));
        } catch (BrokerException ex) {
            status = ex.getStatusCode();
            reason = ex.getMessage();
            if (status != Status.CONFLICT) {
                logger.log(Logger.WARNING, BrokerResources.W_CREATE_DEST_FAILED, destination, ex);
            } else if (DEBUG) {
                logger.log(Logger.DEBUG, BrokerResources.W_CREATE_DEST_FAILED, destination, ex);
            }
        } catch (IOException ex) {
            status = Status.ERROR;
            reason = ex.getMessage();
            logger.log(Logger.WARNING, BrokerResources.W_CREATE_DEST_FAILED, destination, ex);
        }
    } else {
        // removing
        assert msg.getPacketType() == PacketType.DESTROY_DESTINATION;
        assert pkt.getPacketType() == PacketType.DESTROY_DESTINATION_REPLY;
        DestinationSpi d = null;
        try {
            DestinationUID rmuid = DestinationUID.getUID(destination, DestType.isQueue(type));
            if (destination == null) {
                throw new BrokerException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "protocol error,  destination is null"), Status.NOT_FOUND);
            }
            DestinationSpi[] ds = Globals.getCoreLifecycle().getDestination(con.getPartitionedStore(), rmuid);
            d = ds[0];
            assert (d != null);
            Globals.getCoreLifecycle().removeDestination(con.getPartitionedStore(), rmuid, true, Globals.getBrokerResources().getString(BrokerResources.M_CLIENT_REQUEST, con.getConnectionUID()));
            con.detachTempDestination(rmuid);
        } catch (BrokerException ex) {
            status = ex.getStatusCode();
            reason = ex.getMessage();
            logger.log(Logger.WARNING, BrokerResources.W_DESTROY_DEST_FAILED, destination, ex);
        } catch (IOException ex) {
            status = Status.ERROR;
            reason = ex.getMessage();
            logger.log(Logger.WARNING, BrokerResources.W_DESTROY_DEST_FAILED, destination, ex);
        }
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (reason != null) {
        hash.put("JMQReason", reason);
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    con.sendControlMessage(pkt);
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID)

Aggregations

DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)4 DestinationSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi)4 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)2 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)1 Hashtable (java.util.Hashtable)1