@Test public void checkIsHealthyWhenRealmIsEnabled() { Realm realm = mock(Realm.class); when(realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)).thenReturn(true); when(realmSecurityManager.getRealms()).thenReturn(singleton(realm)); when(realm.getName()).thenReturn(AuthenticatingRealmImpl.NAME); when(realm.getAuthenticationInfo(any(UsernamePasswordToken.class))).thenThrow(AuthenticationException.class); Result result = defaultUserHealthCheck.check(); assertThat(result.isHealthy(), is(true)); }
@Override protected Result check() { if (!realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)) { return Result.healthy(); } Optional<Realm> realm = realmSecurityManager.getRealms().stream() .filter(r -> r.getName().equals(AuthenticatingRealmImpl.NAME)).findFirst(); try { if (realm.map(r -> r.getAuthenticationInfo(new UsernamePasswordToken("admin", "admin123"))).isPresent()) { return Result.unhealthy(ERROR_MESSAGE); } } catch (AuthenticationException e) { log.trace("Unable to locate admin/admin123 user", e); } return Result.healthy(); }
DefaultUserHealthCheck extends HealthCheck { @Override protected Result check() { if (!realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)) { return Result.healthy(); } Optional<Realm> realm = realmSecurityManager.getRealms().stream() .filter(r -> r.getName().equals(AuthenticatingRealmImpl.NAME)).findFirst(); try { if (realm.map(r -> r.getAuthenticationInfo(new UsernamePasswordToken("admin", "admin123"))).isPresent()) { return Result.unhealthy(ERROR_MESSAGE); } } catch (AuthenticationException e) { log.trace("Unable to locate admin/admin123 user", e); } return Result.healthy(); } }
DefaultUserHealthCheck extends HealthCheck { @Override protected Result check() { if (!realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)) { return Result.healthy(); } Optional<Realm> realm = realmSecurityManager.getRealms().stream() .filter(r -> r.getName().equals(AuthenticatingRealmImpl.NAME)).findFirst(); try { if (realm.map(r -> r.getAuthenticationInfo(new UsernamePasswordToken("admin", "admin123"))).isPresent()) { return Result.unhealthy(ERROR_MESSAGE); } } catch (AuthenticationException e) { log.trace("Unable to locate admin/admin123 user", e); } return Result.healthy(); } @Inject  DefaultUserHealthCheck(final RealmManager realmManager, final RealmSecurityManager realmSecurityManager); }
DefaultUserHealthCheck extends HealthCheck { @Override protected Result check() { if (!realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)) { return Result.healthy(); } Optional<Realm> realm = realmSecurityManager.getRealms().stream() .filter(r -> r.getName().equals(AuthenticatingRealmImpl.NAME)).findFirst(); try { if (realm.map(r -> r.getAuthenticationInfo(new UsernamePasswordToken("admin", "admin123"))).isPresent()) { return Result.unhealthy(ERROR_MESSAGE); } } catch (AuthenticationException e) { log.trace("Unable to locate admin/admin123 user", e); } return Result.healthy(); } @Inject  DefaultUserHealthCheck(final RealmManager realmManager, final RealmSecurityManager realmSecurityManager);  }
DefaultUserHealthCheck extends HealthCheck { @Override protected Result check() { if (!realmManager.isRealmEnabled(AuthenticatingRealmImpl.NAME)) { return Result.healthy(); } Optional<Realm> realm = realmSecurityManager.getRealms().stream() .filter(r -> r.getName().equals(AuthenticatingRealmImpl.NAME)).findFirst(); try { if (realm.map(r -> r.getAuthenticationInfo(new UsernamePasswordToken("admin", "admin123"))).isPresent()) { return Result.unhealthy(ERROR_MESSAGE); } } catch (AuthenticationException e) { log.trace("Unable to locate admin/admin123 user", e); } return Result.healthy(); } @Inject  DefaultUserHealthCheck(final RealmManager realmManager, final RealmSecurityManager realmSecurityManager);   }