@Override
  public Optional<AuthProperty> inferAuth(String registry) throws InferredAuthException {

    Server server = getServerFromMavenSettings(registry);
    if (server == null) {
      return Optional.empty();
    }

    SettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
    SettingsDecryptionResult result = decrypter.decrypt(request);
    // Un-encrypted passwords are passed through, so a problem indicates a real issue.
    // If there are any ERROR or FATAL problems reported, then decryption failed.
    for (SettingsProblem problem : result.getProblems()) {
      if (problem.getSeverity() == SettingsProblem.Severity.ERROR
          || problem.getSeverity() == SettingsProblem.Severity.FATAL) {
        throw new InferredAuthException(
            "Unable to decrypt server(" + registry + ") info from settings.xml: " + problem);
      }
    }
    Server resultServer = result.getServer();

    String username = resultServer.getUsername();
    String password = resultServer.getPassword();

    return Optional.of(
        new AuthProperty() {

          @Override
          public String getUsername() {
            return username;
          }

          @Override
          public String getPassword() {
            return password;
          }

          @Override
          public String getAuthDescriptor() {
            return CREDENTIAL_SOURCE;
          }

          @Override
          public String getUsernameDescriptor() {
            return CREDENTIAL_SOURCE;
          }

          @Override
          public String getPasswordDescriptor() {
            return CREDENTIAL_SOURCE;
          }
        });
  }
@Test
  public void testInferredAuth_registryWithHostAndPort() throws InferredAuthException {
    Optional<AuthProperty> auth =
        mavenSettingsServerCredentialsNoMasterPassword.inferAuth("docker.example.com:8080");
    Assert.assertTrue(auth.isPresent());
    Assert.assertEquals("registryUser", auth.get().getUsername());
    Assert.assertEquals("registryPassword", auth.get().getPassword());
  }