class DefaultRoleHealthCheck extends HealthCheck {

  @Override
  protected Result check() throws Exception {
    if (!realmManager.isRealmEnabled(DefaultRoleRealm.NAME)) {
      return Result.healthy("Default Role Realm not in use.");
    }

    if (defaultRoleRealm.getRole() == null) {
      return Result.unhealthy("Default Role Realm is enabled but not configured.");
    }

    Role matched = securitySystem.listRoles(DEFAULT_SOURCE).stream()
        .filter(role -> role.getRoleId().equals(defaultRoleRealm.getRole())).findFirst().orElse(null);

    if (matched == null) {
      return Result
          .unhealthy("Default Role Realm configured to use role %s which doesn't exist.", defaultRoleRealm.getRole());
    }

    return Result.healthy("Default Role Realm configured to use role %s.", defaultRoleRealm.getRole());
  }

  @Inject public  DefaultRoleHealthCheck(
      final RealmManager realmManager,
      final DefaultRoleRealm defaultRoleRealm,
      final SecuritySystem securitySystem);

}