Search in sources :

Example 1 with TaskExecutor

use of org.apache.qpid.server.configuration.updater.TaskExecutor in project qpid-broker-j by apache.

the class BDBVirtualHostImplTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    Broker broker = BrokerTestHelper.createBrokerMock();
    TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    when(broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(broker.getChildExecutor()).thenReturn(taskExecutor);
    _storePath = TestFileUtils.createTestDirectory();
    _node = mock(VirtualHostNode.class);
    when(_node.getParent()).thenReturn(broker);
    when(_node.getModel()).thenReturn(BrokerModel.getInstance());
    when(_node.getTaskExecutor()).thenReturn(taskExecutor);
    when(_node.getChildExecutor()).thenReturn(taskExecutor);
    when(_node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
    when(_node.getId()).thenReturn(UUID.randomUUID());
}
Also used : CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) Broker(org.apache.qpid.server.model.Broker) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode)

Example 2 with TaskExecutor

use of org.apache.qpid.server.configuration.updater.TaskExecutor in project qpid-broker-j by apache.

the class OAuth2AuthenticationProviderImplTest method setUp.

@Before
public void setUp() throws Exception {
    Path keyStore = TLS_RESOURCE.createSelfSignedKeyStore("CN=foo");
    _server = new OAuth2MockEndpointHolder(keyStore.toFile().getAbsolutePath(), TLS_RESOURCE.getSecret(), TLS_RESOURCE.getKeyStoreType());
    _server.start();
    Broker broker = BrokerTestHelper.createBrokerMock();
    TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    when(broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(broker.getChildExecutor()).thenReturn(taskExecutor);
    final Map<String, Object> authProviderAttributes = new HashMap<>();
    authProviderAttributes.put(ConfiguredObject.NAME, "testOAuthProvider");
    authProviderAttributes.put("clientId", TEST_CLIENT_ID);
    authProviderAttributes.put("clientSecret", TEST_CLIENT_SECRET);
    authProviderAttributes.put("identityResolverType", TEST_IDENTITY_RESOLVER_TYPE);
    authProviderAttributes.put("authorizationEndpointURI", String.format(TEST_AUTHORIZATION_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_AUTHORIZATION_ENDPOINT_PATH));
    authProviderAttributes.put("tokenEndpointURI", String.format(TEST_TOKEN_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_TOKEN_ENDPOINT_PATH));
    authProviderAttributes.put("tokenEndpointNeedsAuth", TEST_AUTHORIZATION_ENDPOINT_NEEDS_AUTH);
    authProviderAttributes.put("identityResolverEndpointURI", String.format(TEST_IDENTITY_RESOLVER_ENDPOINT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_IDENTITY_RESOLVER_ENDPOINT_PATH));
    authProviderAttributes.put("postLogoutURI", String.format(TEST_POST_LOGOUT_URI_PATTERN, TEST_ENDPOINT_HOST, _server.getPort(), TEST_POST_LOGOUT_PATH));
    authProviderAttributes.put("scope", TEST_SCOPE);
    authProviderAttributes.put("trustStore", TEST_TRUST_STORE_NAME);
    setTestSystemProperty(CachingAuthenticationProvider.AUTHENTICATION_CACHE_MAX_SIZE, "0");
    _authProvider = new OAuth2AuthenticationProviderImpl(authProviderAttributes, broker);
    _authProvider.open();
    assertEquals("Could not successfully open authProvider", State.ACTIVE, _authProvider.getState());
    final TrustManager[] trustingTrustManager = new TrustManager[] { new TrustingTrustManager() };
    final SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustingTrustManager, new java.security.SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HttpsURLConnection.setDefaultHostnameVerifier(new BlindHostnameVerifier());
}
Also used : Path(java.nio.file.Path) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) SSLContext(javax.net.ssl.SSLContext) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Before(org.junit.Before)

Example 3 with TaskExecutor

use of org.apache.qpid.server.configuration.updater.TaskExecutor in project qpid-broker-j by apache.

the class AbstractDurableConfigurationStoreTestCase method createTestExchange.

private Exchange<?> createTestExchange() {
    Exchange exchange = mock(Exchange.class);
    Map<String, Object> actualAttributes = new HashMap<>();
    actualAttributes.put("name", getTestName());
    actualAttributes.put("type", getTestName() + "Type");
    actualAttributes.put("lifetimePolicy", LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
    when(exchange.getName()).thenReturn(getTestName());
    when(exchange.getType()).thenReturn(getTestName() + "Type");
    when(exchange.isAutoDelete()).thenReturn(true);
    when(exchange.getId()).thenReturn(_exchangeId);
    when(exchange.getCategoryClass()).thenReturn(Exchange.class);
    when(exchange.isDurable()).thenReturn(true);
    when(exchange.getObjectFactory()).thenReturn(_factory);
    when(exchange.getModel()).thenReturn(_factory.getModel());
    TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    when(exchange.getTaskExecutor()).thenReturn(taskExecutor);
    when(exchange.getChildExecutor()).thenReturn(taskExecutor);
    ConfiguredObjectRecord exchangeRecord = mock(ConfiguredObjectRecord.class);
    when(exchangeRecord.getId()).thenReturn(_exchangeId);
    when(exchangeRecord.getType()).thenReturn(Exchange.class.getSimpleName());
    when(exchangeRecord.getAttributes()).thenReturn(actualAttributes);
    when(exchangeRecord.getParents()).thenReturn(Collections.singletonMap(_rootRecord.getType(), _rootRecord.getId()));
    when(exchange.asObjectRecord()).thenReturn(exchangeRecord);
    when(exchange.getEventLogger()).thenReturn(new EventLogger());
    return exchange;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EventLogger(org.apache.qpid.server.logging.EventLogger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 4 with TaskExecutor

use of org.apache.qpid.server.configuration.updater.TaskExecutor in project qpid-broker-j by apache.

the class BDBVirtualHostNodeTest method setUp.

@Before
public void setUp() throws Exception {
    assumeThat(getVirtualHostNodeStoreType(), is(equalTo(VirtualHostNodeStoreType.BDB)));
    _broker = BrokerTestHelper.createBrokerMock();
    TaskExecutor taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    _storePath = TestFileUtils.createTestDirectory();
}
Also used : CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) Before(org.junit.Before)

Example 5 with TaskExecutor

use of org.apache.qpid.server.configuration.updater.TaskExecutor in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Before
public void setUp() throws Exception {
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    when(_networkConnection.getSelectedHost()).thenReturn("localhost");
    _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);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            throw new SoleConnectionEnforcementPolicyException(null, Collections.emptySet(), "abc1");
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.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) SoleConnectionEnforcementPolicyException(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicyException) 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) 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) Before(org.junit.Before)

Aggregations

TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)15 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)11 Before (org.junit.Before)10 EventLogger (org.apache.qpid.server.logging.EventLogger)9 Broker (org.apache.qpid.server.model.Broker)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)6 Principal (java.security.Principal)4 ConfiguredObjectFactoryImpl (org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)4 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 HashMap (java.util.HashMap)3 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)3 ConfiguredObjectFactory (org.apache.qpid.server.model.ConfiguredObjectFactory)3 QueueManagingVirtualHost (org.apache.qpid.server.virtualhost.QueueManagingVirtualHost)3 Subject (javax.security.auth.Subject)2 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)2 Exchange (org.apache.qpid.server.model.Exchange)2 Queue (org.apache.qpid.server.model.Queue)2 SystemConfig (org.apache.qpid.server.model.SystemConfig)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)2