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();
}
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);
}
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;
}
Aggregations