Search in sources :

Example 1 with AuthenticationServerClient

use of org.eclipse.hono.service.auth.delegating.AuthenticationServerClient 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)1 Vertx (io.vertx.core.Vertx)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)1 ConnectionFactory (org.eclipse.hono.connection.ConnectionFactory)1 ConnectionFactoryImpl (org.eclipse.hono.connection.ConnectionFactoryImpl)1 AuthTokenHelper (org.eclipse.hono.service.auth.AuthTokenHelper)1 AuthTokenHelperImpl (org.eclipse.hono.service.auth.AuthTokenHelperImpl)1 HonoSaslAuthenticatorFactory (org.eclipse.hono.service.auth.HonoSaslAuthenticatorFactory)1 AuthenticationServerClient (org.eclipse.hono.service.auth.delegating.AuthenticationServerClient)1 AuthenticationServerClientConfigProperties (org.eclipse.hono.service.auth.delegating.AuthenticationServerClientConfigProperties)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1