Search in sources :

Example 36 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class QueueReportServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException, ServletException {
    List<String> pathInfoElements = HttpManagementUtil.getPathInfoElements(request.getServletPath(), request.getPathInfo());
    Queue<?> queue;
    String reportName;
    if (managedObject instanceof Broker && pathInfoElements.size() == 3) {
        queue = getQueueFromRequest(pathInfoElements);
        reportName = pathInfoElements.get(2);
    } else if (managedObject instanceof VirtualHost && pathInfoElements.size() == 2) {
        queue = getQueueFromVirtualHost(pathInfoElements.get(0), (VirtualHost<?>) managedObject);
        reportName = pathInfoElements.get(1);
    } else {
        queue = null;
        reportName = null;
    }
    if (queue != null) {
        ReportRunner<?> reportRunner = ReportRunner.createRunner(reportName, request.getParameterMap());
        Object output = reportRunner.runReport(queue);
        response.setContentType(reportRunner.getContentType());
        if (reportRunner.isBinaryReport()) {
            response.getOutputStream().write((byte[]) output);
        } else {
            response.getWriter().write((String) output);
        }
    } else {
        throw new IllegalArgumentException("Invalid path is specified");
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHost(org.apache.qpid.server.model.VirtualHost)

Example 37 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class ContentServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws IOException {
    ConfiguredObject root = managedObject;
    String pathInfo = request.getPathInfo();
    if (managedObject instanceof Broker && null != pathInfo && !pathInfo.isEmpty()) {
        final ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
        final ConfiguredObject virtualHost = finder.findObjectFromPath(pathInfo.substring(1), VirtualHost.class);
        if (null == virtualHost) {
            sendError(response, HttpServletResponse.SC_NOT_FOUND);
            return;
        } else {
            root = virtualHost;
        }
    } else if (managedObject instanceof VirtualHost && null != pathInfo && !pathInfo.isEmpty()) {
        sendError(response, HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    final Map<String, String[]> parameters = request.getParameterMap();
    Content content = _contentFactory.createContent(root, parameters);
    try {
        writeContent(content, request, response);
    } finally {
        content.release();
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) Content(org.apache.qpid.server.model.Content) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) VirtualHost(org.apache.qpid.server.model.VirtualHost)

Example 38 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class TCPandSSLTransportTest method checkSSLExcluded.

private void checkSSLExcluded(String clientProtocol, final Transport... transports) throws Exception {
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new ByteArrayInputStream(DatatypeConverter.parseBase64Binary(keystoreString)), "password".toCharArray());
    final SSLContext sslContext = SSLContext.getInstance("TLS");
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    kmf.init(keyStore, "password".toCharArray());
    sslContext.init(kmf.getKeyManagers(), null, null);
    final AmqpPort<?> port = mock(AmqpPort.class);
    when(port.getPort()).thenReturn(0);
    when(port.getName()).thenReturn("testAmqp");
    when(port.getNetworkBufferSize()).thenReturn(64 * 1024);
    when(port.canAcceptNewConnection(any(SocketAddress.class))).thenReturn(true);
    when(port.getThreadPoolSize()).thenReturn(2);
    when(port.getNumberOfSelectors()).thenReturn(1);
    when(port.getSSLContext()).thenReturn(sslContext);
    when(port.getContextValue(Long.class, AmqpPort.PORT_AMQP_THREAD_POOL_KEEP_ALIVE_TIMEOUT)).thenReturn(1L);
    when(port.getContextValue(Integer.class, AmqpPort.PORT_AMQP_ACCEPT_BACKLOG)).thenReturn(AmqpPort.DEFAULT_PORT_AMQP_ACCEPT_BACKLOG);
    when(port.getProtocolHandshakeTimeout()).thenReturn(AmqpPort.DEFAULT_PROTOCOL_HANDSHAKE_TIMEOUT);
    ObjectMapper mapper = new ObjectMapper();
    JavaType type = mapper.getTypeFactory().constructCollectionType(List.class, String.class);
    List<String> whiteList = mapper.readValue(Broker.DEFAULT_SECURITY_TLS_PROTOCOL_WHITE_LIST, type);
    List<String> blackList = mapper.readValue(Broker.DEFAULT_SECURITY_TLS_PROTOCOL_BLACK_LIST, type);
    when(port.getTlsProtocolBlackList()).thenReturn(blackList);
    when(port.getTlsProtocolWhiteList()).thenReturn(whiteList);
    final Broker broker = mock(Broker.class);
    when(broker.getEventLogger()).thenReturn(mock(EventLogger.class));
    when(port.getParent()).thenReturn(broker);
    TCPandSSLTransport transport = new TCPandSSLTransport(new HashSet<>(Arrays.asList(transports)), port, new HashSet<>(Arrays.asList(Protocol.AMQP_0_8, Protocol.AMQP_0_9, Protocol.AMQP_0_9_1, Protocol.AMQP_0_10, Protocol.AMQP_1_0)), Protocol.AMQP_0_9_1);
    transport.start();
    SSLContext clientContext = SSLContext.getInstance("TLS");
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    tmf.init(keyStore);
    clientContext.init(null, tmf.getTrustManagers(), null);
    try (SSLSocket sslSocket = (SSLSocket) clientContext.getSocketFactory().createSocket(InetAddress.getLoopbackAddress(), transport.getAcceptingPort())) {
        sslSocket.setEnabledProtocols(new String[] { clientProtocol });
        sslSocket.startHandshake();
    } finally {
        transport.close();
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) SSLSocket(javax.net.ssl.SSLSocket) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) JavaType(com.fasterxml.jackson.databind.JavaType) ByteArrayInputStream(java.io.ByteArrayInputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SocketAddress(java.net.SocketAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Broker (org.apache.qpid.server.model.Broker)38 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)15 EventLogger (org.apache.qpid.server.logging.EventLogger)13 Before (org.junit.Before)11 Test (org.junit.Test)8 Subject (javax.security.auth.Subject)7 HashMap (java.util.HashMap)6 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)6 VirtualHost (org.apache.qpid.server.model.VirtualHost)6 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)6 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)5 Model (org.apache.qpid.server.model.Model)5 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)4 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AccessControlException (java.security.AccessControlException)3 Principal (java.security.Principal)3 SSLContext (javax.net.ssl.SSLContext)3 BrokerModel (org.apache.qpid.server.model.BrokerModel)3 Queue (org.apache.qpid.server.model.Queue)3