<commit_before>package jetbrains.buildServer.runAs.agent;

import com.intellij.openapi.diagnostic.Logger;
import java.util.ArrayList;
import java.util.Collections;
import jetbrains.buildServer.dotNet.buildRunner.agent.BuildStartException;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgumentsService;
import jetbrains.buildServer.dotNet.buildRunner.agent.TextParser;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.runAs.common.LoggingLevel;
import jetbrains.buildServer.runAs.common.WindowsIntegrityLevel;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class UserCredentialsServiceImpl implements UserCredentialsService {
  static final String DEFAULT_CREDENTIALS = "default";
  private static final Logger LOG = Logger.getInstance(UserCredentialsServiceImpl.class.getName());
  private static final AccessControlList OurBeforeStepDefaultAcl = new AccessControlList(Collections.<AccessControlEntry>emptyList());
  private final ParametersService myParametersService;
  private final PropertiesService myPropertiesService;
  private final CommandLineArgumentsService myCommandLineArgumentsService;
  private final TextParser<AccessControlList> myFileAccessParser;

  public UserCredentialsServiceImpl(
    @NotNull final ParametersService parametersService,
    @NotNull final PropertiesService propertiesService,
    @NotNull final CommandLineArgumentsService commandLineArgumentsService,
    @NotNull final TextParser<AccessControlList> fileAccessParser) {
    myParametersService = parametersService;
    myPropertiesService = propertiesService;
    myCommandLineArgumentsService = commandLineArgumentsService;
    myFileAccessParser = fileAccessParser;
  }

  @Nullable
  @Override
  public UserCredentials tryGetUserCredentials() {
    UserCredentials userCredentials;
    final boolean allowCustomCredentials = parseBoolean(myParametersService.tryGetConfigParameter(Constants.ALLOW_CUSTOM_CREDENTIALS), true);
    final boolean allowProfileIdFromServer = parseBoolean(myParametersService.tryGetConfigParameter(Constants.ALLOW_PROFILE_ID_FROM_SERVER), true);
    if(allowCustomCredentials && allowProfileIdFromServer) {
      userCredentials = tryGetCustomCredentials();
      if(userCredentials != null) {
        if(LOG.isDebugEnabled()) {
          LOG.debug("tryGetUserCredentials custom: " + userCredentials);
        }

        return userCredentials;
      }

      String credentialsRef = myParametersService.tryGetParameter(Constants.CREDENTIALS_PROFILE_ID);
      if (StringUtil.isEmptyOrSpaces(credentialsRef)) {
        userCredentials = getPredefinedCredentials("default", false);
        if(LOG.isDebugEnabled()) {
          LOG.debug("tryGetUserCredentials predefined \"" + Constants.CREDENTIALS_PROFILE_ID + "\": " + userCredentials);
        }

        return userCredentials;
      }

      userCredentials = getPredefinedCredentials(credentialsRef, true);
      if(LOG.isDebugEnabled()) {
        LOG.debug("tryGetUserCredentials predefined \"" + credentialsRef + "\": " + userCredentials);
      }

      return userCredentials;
    }

    if(allowCustomCredentials) {
      String credentialsRef = myParametersService.tryGetParameter(Constants.CREDENTIALS_PROFILE_ID);
      if (!StringUtil.isEmptyOrSpaces(credentialsRef)) {
        throw new BuildStartException("The usage of credentials is prohibited");
      }

      userCredentials = tryGetCustomCredentials();
      if(LOG.isDebugEnabled()) {
        LOG.debug("tryGetUserCredentials custom: " + userCredentials);
      }<commit_msg>Invalid error messa when “teamcity.runAs.allowProfileIdFromServer=false”<commit_after>package jetbrains.buildServer.runAs.agent;

import com.intellij.openapi.diagnostic.Logger;
import java.util.ArrayList;
import java.util.Collections;
import jetbrains.buildServer.dotNet.buildRunner.agent.BuildStartException;
import jetbrains.buildServer.dotNet.buildRunner.agent.CommandLineArgumentsService;
import jetbrains.buildServer.dotNet.buildRunner.agent.TextParser;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.runAs.common.LoggingLevel;
import jetbrains.buildServer.runAs.common.WindowsIntegrityLevel;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class UserCredentialsServiceImpl implements UserCredentialsService {
  static final String DEFAULT_CREDENTIALS = "default";
  private static final Logger LOG = Logger.getInstance(UserCredentialsServiceImpl.class.getName());
  private static final AccessControlList OurBeforeStepDefaultAcl = new AccessControlList(Collections.<AccessControlEntry>emptyList());
  private final ParametersService myParametersService;
  private final PropertiesService myPropertiesService;
  private final CommandLineArgumentsService myCommandLineArgumentsService;
  private final TextParser<AccessControlList> myFileAccessParser;

  public UserCredentialsServiceImpl(
    @NotNull final ParametersService parametersService,
    @NotNull final PropertiesService propertiesService,
    @NotNull final CommandLineArgumentsService commandLineArgumentsService,
    @NotNull final TextParser<AccessControlList> fileAccessParser) {
    myParametersService = parametersService;
    myPropertiesService = propertiesService;
    myCommandLineArgumentsService = commandLineArgumentsService;
    myFileAccessParser = fileAccessParser;
  }

  @Nullable
  @Override
  public UserCredentials tryGetUserCredentials() {
    UserCredentials userCredentials;
    final boolean allowCustomCredentials = parseBoolean(myParametersService.tryGetConfigParameter(Constants.ALLOW_CUSTOM_CREDENTIALS), true);
    final boolean allowProfileIdFromServer = parseBoolean(myParametersService.tryGetConfigParameter(Constants.ALLOW_PROFILE_ID_FROM_SERVER), true);
    if(allowCustomCredentials && allowProfileIdFromServer) {
      userCredentials = tryGetCustomCredentials();
      if(userCredentials != null) {
        if(LOG.isDebugEnabled()) {
          LOG.debug("tryGetUserCredentials custom: " + userCredentials);
        }

        return userCredentials;
      }

      String credentialsRef = myParametersService.tryGetParameter(Constants.CREDENTIALS_PROFILE_ID);
      if (StringUtil.isEmptyOrSpaces(credentialsRef)) {
        userCredentials = getPredefinedCredentials("default", false);
        if(LOG.isDebugEnabled()) {
          LOG.debug("tryGetUserCredentials predefined \"" + Constants.CREDENTIALS_PROFILE_ID + "\": " + userCredentials);
        }

        return userCredentials;
      }

      userCredentials = getPredefinedCredentials(credentialsRef, true);
      if(LOG.isDebugEnabled()) {
        LOG.debug("tryGetUserCredentials predefined \"" + credentialsRef + "\": " + userCredentials);
      }

      return userCredentials;
    }

    if(allowCustomCredentials) {
      userCredentials = tryGetCustomCredentials();
      if(LOG.isDebugEnabled()) {
        LOG.debug("tryGetUserCredentials custom: " + userCredentials);
      }
{'fraction_non_alphanumeric': 0.07762365139414319, 'fraction_numerical': 0.0, 'mean_word_length': 5.378909740840036, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3528133', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1805, 'n_words': 321}