Search in sources :

Example 1 with Broker

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

the class BrokerFileLoggerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    Model model = BrokerModel.getInstance();
    EventLogger eventLogger = mock(EventLogger.class);
    SystemConfig<?> systemConfig = mock(SystemConfig.class);
    when(systemConfig.getModel()).thenReturn(model);
    when(systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
    when(systemConfig.getEventLogger()).thenReturn(eventLogger);
    doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(model);
    when(_broker.getChildExecutor()).thenReturn(_taskExecutor);
    when(_broker.getParent()).thenReturn(systemConfig);
    doReturn(Broker.class).when(_broker).getCategoryClass();
    _baseFolder = new File(TMP_FOLDER, "test-sub-folder");
    _logFile = new File(_baseFolder, "tmp-broker-host.log." + System.currentTimeMillis());
    if (_baseFolder.exists()) {
        FileUtils.delete(_baseFolder, true);
    }
}
Also used : TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) File(java.io.File)

Example 2 with Broker

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

the class BrokerMemoryLoggerTest method testCreateDeleteBrokerMemoryLogger.

public void testCreateDeleteBrokerMemoryLogger() {
    final String brokerLoggerName = "TestBrokerLogger";
    ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Broker broker = _systemConfig.getContainer(Broker.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, brokerLoggerName);
    attributes.put(ConfiguredObject.TYPE, BrokerMemoryLogger.TYPE);
    BrokerLogger brokerLogger = (BrokerLogger) broker.createChild(BrokerLogger.class, attributes);
    assertEquals("Created BrokerLogger has unexpected name", brokerLoggerName, brokerLogger.getName());
    assertTrue("BrokerLogger has unexpected type", brokerLogger instanceof BrokerMemoryLogger);
    assertNotNull("Appender not attached to root logger after BrokerLogger creation", rootLogger.getAppender(brokerLoggerName));
    brokerLogger.delete();
    assertNull("Appender should be no longer attached to root logger after BrokerLogger deletion", rootLogger.getAppender(brokerLoggerName));
}
Also used : Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) Logger(org.slf4j.Logger) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) EventLogger(org.apache.qpid.server.logging.EventLogger) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 3 with Broker

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

the class OAuth2InteractiveAuthenticatorTest method createMockOAuth2AuthenticationProvider.

private OAuth2AuthenticationProvider<?> createMockOAuth2AuthenticationProvider(final HttpPort mockPort) throws URISyntaxException {
    OAuth2AuthenticationProvider authenticationProvider = mock(OAuth2AuthenticationProvider.class);
    Broker mockBroker = mock(Broker.class);
    SubjectCreator mockSubjectCreator = mock(SubjectCreator.class);
    when(_mockPort.getSubjectCreator(anyBoolean(), anyString())).thenReturn(mockSubjectCreator);
    SubjectAuthenticationResult mockSuccessfulSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
    SubjectAuthenticationResult mockUnauthorizedSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
    final Subject successfulSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_AUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
    final Subject unauthorizedSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_UNAUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
    AuthenticationResult mockSuccessfulAuthenticationResult = mock(AuthenticationResult.class);
    AuthenticationResult mockUnauthorizedAuthenticationResult = mock(AuthenticationResult.class);
    AuthenticationResult failedAuthenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, new Exception("authentication failed"));
    SubjectAuthenticationResult failedSubjectAuthenticationResult = new SubjectAuthenticationResult(failedAuthenticationResult);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final Subject subject = Subject.getSubject(AccessController.getContext());
            if (!subject.getPrincipals().iterator().next().getName().equals(TEST_AUTHORIZED_USER)) {
                throw new AccessControlException("access denied");
            }
            return null;
        }
    }).when(mockBroker).authorise(eq(Operation.PERFORM_ACTION("manage")));
    when(authenticationProvider.getAuthorizationEndpointURI(any())).thenReturn(new URI(TEST_AUTHORIZATION_ENDPOINT));
    when(authenticationProvider.getClientId()).thenReturn(TEST_CLIENT_ID);
    when(authenticationProvider.getScope()).thenReturn(TEST_OAUTH2_SCOPE);
    when(authenticationProvider.getParent()).thenReturn(mockBroker);
    when(authenticationProvider.authenticateViaAuthorizationCode(matches(TEST_VALID_AUTHORIZATION_CODE), matches(TEST_REQUEST_HOST), any())).thenReturn(mockSuccessfulAuthenticationResult);
    when(authenticationProvider.authenticateViaAuthorizationCode(matches(TEST_INVALID_AUTHORIZATION_CODE), matches(TEST_REQUEST_HOST), any())).thenReturn(failedAuthenticationResult);
    when(authenticationProvider.authenticateViaAuthorizationCode(matches(TEST_UNAUTHORIZED_AUTHORIZATION_CODE), matches(TEST_REQUEST_HOST), any())).thenReturn(mockUnauthorizedAuthenticationResult);
    when(mockSuccessfulSubjectAuthenticationResult.getSubject()).thenReturn(successfulSubject);
    when(mockUnauthorizedSubjectAuthenticationResult.getSubject()).thenReturn(unauthorizedSubject);
    when(mockSubjectCreator.createResultWithGroups(mockSuccessfulAuthenticationResult)).thenReturn(mockSuccessfulSubjectAuthenticationResult);
    when(mockSubjectCreator.createResultWithGroups(mockUnauthorizedAuthenticationResult)).thenReturn(mockUnauthorizedSubjectAuthenticationResult);
    when(mockSubjectCreator.createResultWithGroups(failedAuthenticationResult)).thenReturn(failedSubjectAuthenticationResult);
    return authenticationProvider;
}
Also used : Broker(org.apache.qpid.server.model.Broker) AccessControlException(java.security.AccessControlException) HttpURI(org.eclipse.jetty.http.HttpURI) URI(java.net.URI) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) Subject(javax.security.auth.Subject) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) AccessControlException(java.security.AccessControlException) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OAuth2AuthenticationProvider(org.apache.qpid.server.security.auth.manager.oauth2.OAuth2AuthenticationProvider) SubjectCreator(org.apache.qpid.server.security.SubjectCreator)

Example 4 with Broker

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

the class ProtocolEngine_1_0_0Test method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(_broker.getNetworkBufferSize()).thenReturn(256 * 1026);
    final TaskExecutor taskExecutor = new TaskExecutorImpl();
    taskExecutor.start();
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getId()).thenReturn(UUID.randomUUID());
    when(_broker.getEventLogger()).thenReturn(new EventLogger());
    when(((Broker) _broker).getCategoryClass()).thenReturn(Broker.class);
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    final SubjectCreator subjectCreator = mock(SubjectCreator.class);
    _authenticationProvider = mock(AuthenticationProvider.class);
    when(_port.getAuthenticationProvider()).thenReturn(_authenticationProvider);
    _virtualHost = mock(VirtualHost.class);
    when(_virtualHost.getChildExecutor()).thenReturn(taskExecutor);
    when(_virtualHost.getModel()).thenReturn(BrokerModel.getInstance());
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    final ArgumentCaptor<AMQPConnection> connectionCaptor = ArgumentCaptor.forClass(AMQPConnection.class);
    final ArgumentCaptor<ConnectionEstablishmentPolicy> establishmentPolicyCaptor = ArgumentCaptor.forClass(ConnectionEstablishmentPolicy.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            return null;
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.capture(), establishmentPolicyCaptor.capture());
    when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
    when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(subjectCreator);
    final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
    when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then(new Answer<Subject>() {

        @Override
        public Subject answer(final InvocationOnMock invocation) throws Throwable {
            Subject subject = new Subject();
            subject.getPrincipals().add(userCaptor.getValue());
            return subject;
        }
    });
    final ByteBufferSender sender = mock(ByteBufferSender.class);
    when(_networkConnection.getSender()).thenReturn(sender);
    AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer().registerTransactionLayer().registerSecurityLayer();
    _frameWriter = new FrameWriter(registry, new ByteBufferSender() {

        @Override
        public boolean isDirectBufferPreferred() {
            return false;
        }

        @Override
        public void send(final QpidByteBuffer msg) {
            _protocolEngine_1_0_0.received(msg);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() {
        }
    });
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) InetSocketAddress(java.net.InetSocketAddress) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) ConnectionEstablishmentPolicy(org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) VirtualHost(org.apache.qpid.server.model.VirtualHost) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 5 with Broker

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

the class BrokerQueryServlet method getAllObjects.

@Override
protected List<ConfiguredObject<?>> getAllObjects(final Broker<?> broker, final Class<? extends ConfiguredObject> category, final HttpServletRequest request) {
    if (category == Broker.class) {
        return Collections.<ConfiguredObject<?>>singletonList(broker);
    } else {
        final Model brokerModel = broker.getModel();
        List<Class<? extends ConfiguredObject>> hierarchy = new ArrayList<>();
        Class<? extends ConfiguredObject> element = category;
        while (element != null && element != Broker.class) {
            hierarchy.add(element);
            Class<? extends ConfiguredObject> parentType = brokerModel.getParentType(element);
            if (parentType == null) {
                break;
            } else {
                element = parentType;
            }
        }
        Collections.reverse(hierarchy);
        Collection<ConfiguredObject<?>> parents = Collections.<ConfiguredObject<?>>singletonList(broker);
        Collection<ConfiguredObject<?>> children = Collections.emptyList();
        for (Class<? extends ConfiguredObject> childClass : hierarchy) {
            children = new HashSet<>();
            for (ConfiguredObject<?> parent : parents) {
                children.addAll((Collection<? extends ConfiguredObject<?>>) parent.getChildren(childClass));
            }
            parents = children;
        }
        return new ArrayList<>(children);
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) Model(org.apache.qpid.server.model.Model) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Aggregations

Broker (org.apache.qpid.server.model.Broker)31 EventLogger (org.apache.qpid.server.logging.EventLogger)13 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)11 HashMap (java.util.HashMap)7 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)7 Subject (javax.security.auth.Subject)5 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)5 Model (org.apache.qpid.server.model.Model)5 Principal (java.security.Principal)4 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)4 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)4 VirtualHost (org.apache.qpid.server.model.VirtualHost)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)3 ConfiguredObjectFactoryImpl (org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)3 SystemConfig (org.apache.qpid.server.model.SystemConfig)3 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)3 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2