FileBasedAuthenticationService extends AbstractHonoAuthenticationService<AuthenticationServerConfigProperties> { @Override public void verifyExternal(final String authzid, final String subjectDn, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) { if (subjectDn == null || subjectDn.isEmpty()) { authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "missing subject DN"))); } else { final String commonName = AuthenticationConstants.getCommonName(subjectDn); if (commonName == null) { authenticationResultHandler .handle(Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "could not determine authorization ID for subject DN"))); } else { final JsonObject user = getUser(commonName, AuthenticationConstants.MECHANISM_EXTERNAL); if (user == null) { authenticationResultHandler.handle(Future .failedFuture(new ClientErrorException(HttpURLConnection.HTTP_UNAUTHORIZED, UNAUTHORIZED))); } else { verify(commonName, user, authzid, authenticationResultHandler); } } } }  @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 testVerifyExternalFailsForMissingSubjectDn(final VertxTestContext ctx) { authService.verifyExternal(null, null, ctx.failing(t -> ctx.completeNow())); }
@Test public void testVerifyExternalGrantsCommonName(final VertxTestContext ctx) { authService.verifyExternal(null, "CN=userB", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "userB", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyExternalGrantsAuthorizationId(final VertxTestContext ctx) { authService.verifyExternal("userB", "CN=mqtt-adapter", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "userB", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyExternalRefusesNonExistingAuthorizationId(final VertxTestContext ctx) { authService.verifyExternal("userC", "CN=mqtt-adapter", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "mqtt-adapter", TOKEN); ctx.completeNow(); })); }
@Test public void testVerifyExternalRefusesAuthorizationId(final VertxTestContext ctx) { authService.verifyExternal("userB", "CN=userA", ctx.succeeding(res -> { assertUserAndToken(ctx, res, "userA", TOKEN); ctx.completeNow(); })); }