/**
   * @param restResponse
   * @param servletContextUrl
   * @return
   */
  private String getGradleProperties(RestResponse restResponse, String servletContextUrl) {
    AddonsManager addonsManager = ContextHelper.get().beanForType(AddonsManager.class);
    FilteredResourcesAddon filteredResourcesWebAddon =
        addonsManager.addonByType(FilteredResourcesAddon.class);

    java.util.Properties credentialProperties = new java.util.Properties();
    credentialProperties.setProperty(
        "auth.username", filteredResourcesWebAddon.getGeneratedSettingsUsernameTemplate());

    credentialProperties.setProperty(
        "auth.password",
        filteredResourcesWebAddon.getGeneratedSettingsUserCredentialsTemplate(false));

    credentialProperties.setProperty("auth.contextUrl", servletContextUrl);

    String content =
        replaceValuesAndGetTemplateValue(
            "/gradle.properties.template", credentialProperties, restResponse);
    try {
      String filtered =
          filteredResourcesWebAddon.filterResource(
              null,
              (org.artifactory.md.Properties) InfoFactoryHolder.get().createProperties(),
              new StringReader(content));
      return filtered;
    } catch (Exception e) {
      log.error("Unable to filter gradle build properties file: " + e.getMessage());
      restResponse.error(e.getMessage());
    }
    return content;
  }
 /**
  * Performs local properties update
  *
  * @param resource
  * @return success/failure
  */
 private boolean doPull(RepoResource resource) {
   log.debug("Downloading properties for artifact {}", resource);
   String repoKey = StringUtils.replaceLast(resource.getRepoPath().getRepoKey(), "-cache", "");
   HttpRepo repo = (HttpRepo) repositoryService.remoteRepositoryByKey(repoKey);
   // If file doesn't exist then do mot update properties since it will be updated during file
   // download
   if (!repositoryService.exists(resource.getRepoPath())) {
     return false;
   }
   // If properties not expire the return false, no need to get properties drom the remote repo
   if (repo == null
       || resourceIsExpirable(resource, repo)
       || !isPropertiesExpired(resource, repo)) {
     return false;
   }
   String remotePath = repo.getUrl() + "/" + resource.getRepoPath().getPath() + ":properties";
   HttpGet getMethod = new HttpGet(HttpUtils.encodeQuery(remotePath));
   try {
     CloseableHttpResponse getResponse = repo.executeMethod(getMethod);
     boolean ok = HttpStatus.SC_OK == getResponse.getStatusLine().getStatusCode();
     boolean notFound = HttpStatus.SC_NOT_FOUND == getResponse.getStatusLine().getStatusCode();
     if (ok || notFound) {
       InputStream stream = getResponse.getEntity().getContent();
       Properties properties = (Properties) InfoFactoryHolder.get().createProperties();
       if (ok && stream != null) {
         RepoRequests.logToContext("Received remote property content");
         Properties remoteProperties =
             (Properties) InfoFactoryHolder.get().getFileSystemXStream().fromXML(stream);
         for (String remotePropertyKey : remoteProperties.keySet()) {
           Set<String> values = remoteProperties.get(remotePropertyKey);
           RepoRequests.logToContext(
               "Found remote property key '{}' with values '%s'", remotePropertyKey, values);
           if (!remotePropertyKey.startsWith(ReplicationAddon.PROP_REPLICATION_PREFIX)) {
             properties.putAll(remotePropertyKey, values);
           }
         }
       }
       updateRemoteProperties(resource, properties);
     }
     repositoryService.unexpireIfExists(
         repo.getLocalCacheRepo(), resource.getRepoPath().getPath());
   } catch (IOException e) {
     log.debug("Cannot update remote properties", e);
     return false;
   }
   return true;
 }
 @Override
 public Authentication getAnonymousAuthentication() {
   log.debug("Starting to generate Anonymous authentication");
   UserGroupService userGroupService = ContextHelper.get().beanForType(UserGroupService.class);
   UserInfo userInfo = userGroupService.findOrCreateExternalAuthUser(UserInfo.ANONYMOUS, true);
   MutableUserInfo mutableUserInfo = InfoFactoryHolder.get().copyUser(userInfo);
   mutableUserInfo.setRealm(MissionControlAuthenticationProvider.REALM);
   userInfo = mutableUserInfo;
   SimpleUser user = new SimpleUser(userInfo);
   // create new authentication response containing the user and it's authorities.
   log.debug("Finished to create Anonymous authentication");
   return new MissionControlAuthenticationToken(user, user.getAuthorities());
 }
 public MetadataResource(RepoPath repoPath) {
   this.info = InfoFactoryHolder.get().createMetadata(repoPath);
 }