Search in sources :

Example 1 with HonoSaslAuthenticatorFactory

use of org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory in project hono by eclipse.

the class StandaloneEventApiTest method prepareHonoServer.

/**
 * Sets up Hono Messaging service.
 *
 * @param ctx The test context.
 */
@BeforeClass
public static void prepareHonoServer(final TestContext ctx) {
    vertx = Vertx.vertx();
    downstreamAdapter = new MessageDiscardingDownstreamAdapter(vertx);
    final HonoMessagingConfigProperties configProperties = new HonoMessagingConfigProperties();
    configProperties.setInsecurePort(0);
    final EventEndpoint eventEndpoint = new EventEndpoint(vertx);
    eventEndpoint.setMetrics(mock(MessagingMetrics.class));
    eventEndpoint.setEventAdapter(downstreamAdapter);
    eventEndpoint.setRegistrationAssertionValidator(assertionHelper);
    eventEndpoint.setConfiguration(configProperties);
    server = new HonoMessaging();
    server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(TestSupport.createAuthenticationService(createUser())));
    server.setConfig(configProperties);
    server.addEndpoint(eventEndpoint);
    Future<String> serverTracker = Future.future();
    vertx.deployVerticle(server, serverTracker.completer());
    serverTracker.compose(s -> {
        final ClientConfigProperties clientProps = new ClientConfigProperties();
        clientProps.setName("test");
        clientProps.setHost(server.getInsecurePortBindAddress());
        clientProps.setPort(server.getInsecurePort());
        clientProps.setUsername(USER);
        clientProps.setPassword(PWD);
        client = new HonoClientImpl(vertx, clientProps);
        return client.connect(new ProtonClientOptions());
    }).setHandler(ctx.asyncAssertSuccess());
}
Also used : EventEndpoint(org.eclipse.hono.event.impl.EventEndpoint) HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) TestContext(io.vertx.ext.unit.TestContext) AuthoritiesImpl(org.eclipse.hono.auth.AuthoritiesImpl) HonoUserAdapter(org.eclipse.hono.auth.HonoUserAdapter) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ClientErrorException(org.eclipse.hono.client.ClientErrorException) HonoUser(org.eclipse.hono.auth.HonoUser) Constants(org.eclipse.hono.util.Constants) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) MessageSender(org.eclipse.hono.client.MessageSender) Message(org.apache.qpid.proton.message.Message) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) ProtonHelper(io.vertx.proton.ProtonHelper) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Activity(org.eclipse.hono.auth.Activity) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TestSupport(org.eclipse.hono.TestSupport) Authorities(org.eclipse.hono.auth.Authorities) HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) Mockito.mock(org.mockito.Mockito.mock) EventEndpoint(org.eclipse.hono.event.impl.EventEndpoint) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BeforeClass(org.junit.BeforeClass)

Example 2 with HonoSaslAuthenticatorFactory

use of org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory in project hono by eclipse.

the class StandaloneTelemetryApiTest method prepareHonoServer.

/**
 * Sets up the fixture common to all test cases.
 *
 * @param ctx The vert.x test context.
 */
@BeforeClass
public static void prepareHonoServer(final TestContext ctx) {
    vertx = Vertx.vertx();
    downstreamAdapter = new MessageDiscardingDownstreamAdapter(vertx);
    final HonoMessagingConfigProperties configProperties = new HonoMessagingConfigProperties();
    configProperties.setInsecurePort(0);
    final TelemetryEndpoint telemetryEndpoint = new TelemetryEndpoint(vertx);
    telemetryEndpoint.setMetrics(mock(MessagingMetrics.class));
    telemetryEndpoint.setTelemetryAdapter(downstreamAdapter);
    telemetryEndpoint.setRegistrationAssertionValidator(assertionHelper);
    telemetryEndpoint.setConfiguration(configProperties);
    server = new HonoMessaging();
    server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(TestSupport.createAuthenticationService(createUser())));
    server.setConfig(configProperties);
    server.addEndpoint(telemetryEndpoint);
    final Future<String> serverTracker = Future.future();
    vertx.deployVerticle(server, serverTracker.completer());
    serverTracker.compose(s -> {
        final ClientConfigProperties clientProps = new ClientConfigProperties();
        clientProps.setName("test");
        clientProps.setHost(server.getInsecurePortBindAddress());
        clientProps.setPort(server.getInsecurePort());
        clientProps.setUsername(USER);
        clientProps.setPassword(PWD);
        client = new HonoClientImpl(vertx, clientProps);
        return client.connect(new ProtonClientOptions());
    }).setHandler(ctx.asyncAssertSuccess());
}
Also used : HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) TestContext(io.vertx.ext.unit.TestContext) AuthoritiesImpl(org.eclipse.hono.auth.AuthoritiesImpl) HonoUserAdapter(org.eclipse.hono.auth.HonoUserAdapter) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Activity(org.eclipse.hono.auth.Activity) HonoUser(org.eclipse.hono.auth.HonoUser) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) Future(io.vertx.core.Future) TelemetryEndpoint(org.eclipse.hono.telemetry.impl.TelemetryEndpoint) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) TestSupport(org.eclipse.hono.TestSupport) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) MessageSender(org.eclipse.hono.client.MessageSender) Authorities(org.eclipse.hono.auth.Authorities) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) Mockito.mock(org.mockito.Mockito.mock) HonoClientImpl(org.eclipse.hono.client.impl.HonoClientImpl) TelemetryEndpoint(org.eclipse.hono.telemetry.impl.TelemetryEndpoint) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BeforeClass(org.junit.BeforeClass)

Example 3 with HonoSaslAuthenticatorFactory

use of org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory in project hono by eclipse.

the class StandaloneAuthServerTest method prepareServer.

/**
 * Sets up the server.
 *
 * @param ctx The vertx test context.
 */
@BeforeClass
public static void prepareServer(final TestContext ctx) {
    AuthTokenHelper tokenHelper = AuthTokenHelperImpl.forSharedSecret(SIGNING_SECRET, 5);
    ServiceConfigProperties props = new ServiceConfigProperties();
    props.setInsecurePortEnabled(true);
    props.setInsecurePort(0);
    server = new SimpleAuthenticationServer();
    server.setConfig(props);
    server.setSaslAuthenticatorFactory(new HonoSaslAuthenticatorFactory(vertx, tokenHelper));
    server.addEndpoint(new AuthenticationEndpoint(vertx));
    AuthenticationServerConfigProperties serviceProps = new AuthenticationServerConfigProperties();
    serviceProps.getSigning().setTokenExpiration(5);
    serviceProps.getSigning().setSharedSecret(SIGNING_SECRET);
    serviceProps.setPermissionsPath(new ClassPathResource("authentication-service-test-permissions.json"));
    FileBasedAuthenticationService authServiceImpl = new FileBasedAuthenticationService();
    authServiceImpl.setConfig(serviceProps);
    authServiceImpl.setTokenFactory(tokenHelper);
    Async startup = ctx.async();
    Future<String> serverTracker = Future.future();
    serverTracker.setHandler(ctx.asyncAssertSuccess(s -> startup.complete()));
    Future<String> serviceTracker = Future.future();
    vertx.deployVerticle(authServiceImpl, serviceTracker.completer());
    serviceTracker.compose(s -> {
        vertx.deployVerticle(server, ctx.asyncAssertSuccess(d -> serverTracker.complete(d)));
    }, serverTracker);
    startup.await(2000);
    AuthenticationServerClientConfigProperties clientProps = new AuthenticationServerClientConfigProperties();
    clientProps.setHost("127.0.0.1");
    clientProps.setName("test-client");
    clientProps.setPort(server.getInsecurePort());
    clientProps.getValidation().setSharedSecret(SIGNING_SECRET);
    ConnectionFactory clientFactory = new ConnectionFactoryImpl(vertx, clientProps);
    client = new AuthenticationServerClient(vertx, clientFactory);
}
Also used : HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) AuthTokenHelper(org.eclipse.hono.service.auth.AuthTokenHelper) TestContext(io.vertx.ext.unit.TestContext) ConnectionFactoryImpl(org.eclipse.hono.connection.ConnectionFactoryImpl) Async(io.vertx.ext.unit.Async) AuthTokenHelperImpl(org.eclipse.hono.service.auth.AuthTokenHelperImpl) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ClassPathResource(org.springframework.core.io.ClassPathResource) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) Future(io.vertx.core.Future) ConnectionFactory(org.eclipse.hono.connection.ConnectionFactory) AuthenticationServerClientConfigProperties(org.eclipse.hono.service.auth.delegating.AuthenticationServerClientConfigProperties) HonoSaslAuthenticatorFactory(org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory) AuthenticationServerClient(org.eclipse.hono.service.auth.delegating.AuthenticationServerClient) AuthTokenHelper(org.eclipse.hono.service.auth.AuthTokenHelper) AuthenticationServerClient(org.eclipse.hono.service.auth.delegating.AuthenticationServerClient) ClassPathResource(org.springframework.core.io.ClassPathResource) ConnectionFactory(org.eclipse.hono.connection.ConnectionFactory) Async(io.vertx.ext.unit.Async) ServiceConfigProperties(org.eclipse.hono.config.ServiceConfigProperties) AuthenticationServerClientConfigProperties(org.eclipse.hono.service.auth.delegating.AuthenticationServerClientConfigProperties) ConnectionFactoryImpl(org.eclipse.hono.connection.ConnectionFactoryImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

Future (io.vertx.core.Future)3 Vertx (io.vertx.core.Vertx)3 TestContext (io.vertx.ext.unit.TestContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 HonoSaslAuthenticatorFactory (org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory)3 BeforeClass (org.junit.BeforeClass)3 RunWith (org.junit.runner.RunWith)3 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)2 TestSupport (org.eclipse.hono.TestSupport)2 Activity (org.eclipse.hono.auth.Activity)2 Authorities (org.eclipse.hono.auth.Authorities)2 AuthoritiesImpl (org.eclipse.hono.auth.AuthoritiesImpl)2 HonoUser (org.eclipse.hono.auth.HonoUser)2 HonoUserAdapter (org.eclipse.hono.auth.HonoUserAdapter)2 MessageSender (org.eclipse.hono.client.MessageSender)2 HonoClientImpl (org.eclipse.hono.client.impl.HonoClientImpl)2 ClientConfigProperties (org.eclipse.hono.config.ClientConfigProperties)2 Test (org.junit.Test)2 Mockito.mock (org.mockito.Mockito.mock)2 Async (io.vertx.ext.unit.Async)1