Search code examples
nexustalend

NexusTargetMappingAuthorizationFilter


I've got a weird one (to me): Using Nexus 2.11.4-01 and a another piece of software (Talend) is interfacing with it. When Talend tries to talk to Nexus it throws an error, looks like it's trying to hit a URL of the form http://servername:8081/nexus/service/local/repositories/scratch/content which throws a 403 when browsed to with Chrome. The Nexus logs show:

2015-09-07 15:47:30,396+0000 WARN  [qtp131312334-65] admin org.sonatype.nexus.security.filter.authz.NexusTargetMappingAuthorizationFilter - Cannot translate request to Nexus repository path, expected pattern /service/local/repositories/([^/]*)/content/(.*), request: GET http://servername:8081/nexus/service/local/repositories/scratch/content

For any repo that I try, now "scratch" should match the pattern and the source here (for Nexus 2.11.3 admittedly) which I found via some googleing suggests it should work too: http://grepcode.com/file/repo1.maven.org/maven2/org.sonatype.nexus/nexus-core/2.11.3-01/org/sonatype/nexus/security/filter/authz/NexusTargetMappingAuthorizationFilter.java

  private String getResourceStorePath(final ServletRequest request) {
    String path = WebUtils.getPathWithinApplication((HttpServletRequest) request);
    if (getPathPrefix() != null) {
      final Pattern p = getPathPrefixPattern();
      final Matcher m = p.matcher(path);
      if (m.matches()) {
        path = getPathReplacement();
        // TODO: hardcoded currently
        if (path.contains("@1")) {
          path = path.replaceAll("@1", Matcher.quoteReplacement(m.group(1)));
        }
        if (path.contains("@2")) {
          path = path.replaceAll("@2", Matcher.quoteReplacement(m.group(2)));
        }
        // and so on... this will be reworked to be dynamic
      }
      else {
        // what happens here: router requests are formed as: /KIND/ID/REPO_PATH
        // where KIND = {"repositories", "groups", ...}, ID is a repo ID, and REPO_PATH is a repository path
        // being here, means we could not even match anything of these, usually having newline in string
        // as that's the only thing the "dotSTAR" regex would not match (it would match any other character)
        log.warn(formatMessage(request, "Cannot translate request to Nexus repository path, expected pattern {}"), p);
        return null;
      }
    }

    return path;
  }

So my question is what am I doing wrong, what am I missing?


Solution

  • The solution is that the version of Nexus shipped with Talend 5.6 (and that it is written to interface with) is pretty ancient and that the newer versions of Nexus use a different interface.