FileBasedAuthenticationService extends AbstractHonoAuthenticationService<AuthenticationServerConfigProperties> { @Override public void verifyPlain(final String authzid, final String username, final String password, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) { if (username == null || username.isEmpty()) { authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "missing username"))); } else if (password == null || password.isEmpty()) { authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "missing password"))); } else { final JsonObject user = getUser(username, AuthenticationConstants.MECHANISM_PLAIN); if (user == null) { log.debug("no such user [{}]", username); authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_UNAUTHORIZED, UNAUTHORIZED))); } else if (password.equals(user.getString("password"))) { verify(username, user, authzid, authenticationResultHandler); } else { log.debug("password mismatch"); authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_UNAUTHORIZED, UNAUTHORIZED))); } } }  @Autowired @Override void setConfig(final AuthenticationServerConfigProperties configuration); @Override String[] getSupportedSaslMechanisms(); @Autowired @Qualifier("signing") void setTokenFactory(final AuthTokenHelper tokenFactory); @Override void verifyPlain(final String authzid, final String username, final String password,
            final Handler<AsyncResult<HonoUser>> authenticationResultHandler); @Override void verifyExternal(final String authzid, final String subjectDn, final Handler<AsyncResult<HonoUser>> authenticationResultHandler);  }
@Test public void testVerifyPlainFailsForMissingUsername(final VertxTestContext ctx) { authService.verifyPlain(null, null, "pwd", ctx.failing(t -> ctx.completeNow())); }
@Test public void testVerifyPlainFailsForMissingPassword(final VertxTestContext ctx) { authService.verifyPlain(null, "user", null, ctx.failing(t -> ctx.completeNow())); }
@Test public void testVerifyPlainSucceedsForMatchingPassword(final VertxTestContext ctx) { authService.verifyPlain(null, "hono-client@HONO", "secret", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "hono-client@HONO", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyPlainGrantsAuthorizationId(final VertxTestContext ctx) { authService.verifyPlain("userB", "http-adapter@HONO", "secret", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "userB", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyPlainRefusesAuthorizationId(final VertxTestContext ctx) { authService.verifyPlain("userB", "hono-client@HONO", "secret", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "hono-client@HONO", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyPlainRefusesNonExistingAuthorizationId(final VertxTestContext ctx) { authService.verifyPlain("userC", "http-adapter@HONO", "secret", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "http-adapter@HONO", TOKEN); ctx.completeNow(); })); }