Search in sources :

Example 11 with ServiceConfigProperties

use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.

the class ApplicationConfig method registrationAssertionFactory.

/**
 * Exposes a factory for JWTs asserting a device's registration status as a Spring bean.
 *
 * @return The bean.
 */
@Bean
@Qualifier("signing")
public RegistrationAssertionHelper registrationAssertionFactory() {
    ServiceConfigProperties amqpProps = amqpProperties();
    FileBasedRegistrationConfigProperties serviceProps = serviceProperties();
    if (!serviceProps.getSigning().isAppropriateForCreating() && amqpProps.getKeyPath() != null) {
        // fall back to TLS configuration
        serviceProps.getSigning().setKeyPath(amqpProps.getKeyPath());
    }
    return RegistrationAssertionHelperImpl.forSigning(vertx(), serviceProps.getSigning());
}
Also used : ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Bean(org.springframework.context.annotation.Bean) ObjectFactoryCreatingFactoryBean(org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean)

Example 12 with ServiceConfigProperties

use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.

the class AbstractServiceBaseTest method checkNoPortsSet.

/**
 * Verifies that a Hono server will not be able to start
 * when using a default configuration with not key store being set.
 */
@Test
public void checkNoPortsSet() {
    // GIVEN a default configuration with no key store being set
    ServiceConfigProperties configProperties = new ServiceConfigProperties();
    // WHEN using this configuration to determine the server's port configuration
    AbstractServiceBase<ServiceConfigProperties> server = createServer(configProperties);
    Future<Void> portConfigurationTracker = server.checkPortConfiguration();
    // THEN the port configuration fails
    assertTrue(portConfigurationTracker.failed());
}
Also used : ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Test(org.junit.Test)

Example 13 with ServiceConfigProperties

use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.

the class AbstractServiceBaseTest method checkBothPortsSetToSame.

/**
 * Verifies that a Hono server will only bind to the secure port
 * when using a default configuration with both secure and insecure ports being enabled and
 * set to the same port number.
 */
@Test
public void checkBothPortsSetToSame() {
    // GIVEN a default configuration with both the insecure port and the secure port
    // being set to the same value.
    ServiceConfigProperties configProperties = new ServiceConfigProperties();
    configProperties.setInsecurePortEnabled(true);
    configProperties.setKeyStorePath("/etc/hono/certs/honoKeyStore.p12");
    configProperties.setInsecurePort(8888);
    configProperties.setPort(8888);
    // WHEN using this configuration to determine the server's port configuration
    AbstractServiceBase<ServiceConfigProperties> server = createServer(configProperties);
    Future<Void> portConfigurationTracker = server.checkPortConfiguration();
    // THEN port configuration fails
    assertTrue(portConfigurationTracker.failed());
}
Also used : ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Test(org.junit.Test)

Example 14 with ServiceConfigProperties

use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.

the class AmqpServiceBaseTest method createServer.

private AmqpServiceBase<ServiceConfigProperties> createServer(final AmqpEndpoint amqpEndpoint, final Handler<ProtonConnection> onClientDisconnect) {
    final AmqpServiceBase<ServiceConfigProperties> server = new AmqpServiceBase<ServiceConfigProperties>() {

        @Override
        protected String getServiceName() {
            return "AmqpServiceBase";
        }

        @Override
        public void setConfig(final ServiceConfigProperties configuration) {
            setSpecificConfig(configuration);
        }

        @Override
        protected void publishConnectionClosedEvent(final ProtonConnection con) {
            if (onClientDisconnect != null) {
                onClientDisconnect.handle(con);
            }
        }
    };
    server.setConfig(new ServiceConfigProperties());
    if (amqpEndpoint != null) {
        server.addEndpoint(amqpEndpoint);
    }
    server.init(vertx, mock(Context.class));
    return server;
}
Also used : Context(io.vertx.core.Context) ProtonConnection(io.vertx.proton.ProtonConnection) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties)

Example 15 with ServiceConfigProperties

use of org.eclipse.hono.config.ServiceConfigProperties in project hono by eclipse.

the class AmqpServiceBaseTest method testHandleReceiverOpenForwardsToEndpoint.

/**
 * Verifies that the service notifies a registered endpoint about a client
 * that has established a link.
 */
@Test
public void testHandleReceiverOpenForwardsToEndpoint() {
    // GIVEN a server with an endpoint
    final ResourceIdentifier targetAddress = ResourceIdentifier.from(ENDPOINT, Constants.DEFAULT_TENANT, null);
    final AmqpEndpoint endpoint = mock(AmqpEndpoint.class);
    when(endpoint.getName()).thenReturn(ENDPOINT);
    final AuthorizationService authService = mock(AuthorizationService.class);
    when(authService.isAuthorized(Constants.PRINCIPAL_ANONYMOUS, targetAddress, Activity.WRITE)).thenReturn(Future.succeededFuture(Boolean.TRUE));
    final AmqpServiceBase<ServiceConfigProperties> server = createServer(endpoint);
    server.setAuthorizationService(authService);
    // WHEN a client connects to the server using this endpoint
    final Target target = getTarget(targetAddress);
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.getRemoteTarget()).thenReturn(target);
    when(receiver.attachments()).thenReturn(mock(Record.class));
    server.handleReceiverOpen(newConnection(Constants.PRINCIPAL_ANONYMOUS), receiver);
    // THEN the server delegates link establishment to the endpoint
    verify(endpoint).onLinkAttach(any(ProtonConnection.class), eq(receiver), eq(targetAddress));
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ProtonConnection(io.vertx.proton.ProtonConnection) Target(org.apache.qpid.proton.amqp.transport.Target) AuthorizationService(org.eclipse.hono.service.auth.AuthorizationService) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Record(org.apache.qpid.proton.engine.Record) Test(org.junit.Test)

Aggregations

ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)19 Test (org.junit.Test)15 ProtonConnection (io.vertx.proton.ProtonConnection)6 AuthorizationService (org.eclipse.hono.service.auth.AuthorizationService)4 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)4 ProtonDelivery (io.vertx.proton.ProtonDelivery)3 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)3 Message (org.apache.qpid.proton.message.Message)3 EventBusMessage (org.eclipse.hono.util.EventBusMessage)3 Qualifier (org.springframework.beans.factory.annotation.Qualifier)3 ObjectFactoryCreatingFactoryBean (org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean)3 Bean (org.springframework.context.annotation.Bean)3 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 Async (io.vertx.ext.unit.Async)2 TestContext (io.vertx.ext.unit.TestContext)2 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)2 ProtonReceiver (io.vertx.proton.ProtonReceiver)2 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)2