Search in sources :

Example 1 with AuthTokenHelper

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

the class FileBasedAuthenticationServiceTest method loadPermissions.

/**
 * Loads permissions from file.
 *
 * @throws IOException if the permissions cannot be loaded.
 */
@BeforeClass
public static void loadPermissions() throws IOException {
    AuthTokenHelper tokenFactory = mock(AuthTokenHelper.class);
    when(tokenFactory.createToken(anyString(), any(Authorities.class))).thenReturn(TOKEN);
    when(tokenFactory.getTokenLifetime()).thenReturn(TOKEN_LIFETIME);
    AuthenticationServerConfigProperties props = new AuthenticationServerConfigProperties();
    props.setPermissionsPath(new ClassPathResource("authentication-service-test-permissions.json"));
    authService = new FileBasedAuthenticationService();
    authService.setConfig(props);
    authService.setTokenFactory(tokenFactory);
    authService.loadPermissions();
}
Also used : AuthTokenHelper(org.eclipse.hono.service.auth.AuthTokenHelper) Authorities(org.eclipse.hono.auth.Authorities) ClassPathResource(org.springframework.core.io.ClassPathResource) BeforeClass(org.junit.BeforeClass)

Example 2 with AuthTokenHelper

use of org.eclipse.hono.service.auth.AuthTokenHelper 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)

Example 3 with AuthTokenHelper

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

the class FileBasedAuthenticationServiceTest method getService.

private FileBasedAuthenticationService getService(final String permissionsPath) {
    final AuthTokenHelper tokenFactory = mock(AuthTokenHelper.class);
    when(tokenFactory.createToken(anyString(), any(Authorities.class))).thenReturn(TOKEN);
    when(tokenFactory.getTokenLifetime()).thenReturn(TOKEN_LIFETIME);
    props.setPermissionsPath(permissionsPath);
    final var service = new FileBasedAuthenticationService();
    service.setConfig(props);
    service.setTokenFactory(tokenFactory);
    return service;
}
Also used : AuthTokenHelper(org.eclipse.hono.service.auth.AuthTokenHelper) Authorities(org.eclipse.hono.auth.Authorities)

Aggregations

AuthTokenHelper (org.eclipse.hono.service.auth.AuthTokenHelper)3 Authorities (org.eclipse.hono.auth.Authorities)2 BeforeClass (org.junit.BeforeClass)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 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 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 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1