Content Selectors

Content Selectors

Content selectors grant access to specific content path, or namespace, from a repository rather than the entire repository. Content selectors define what content users may access. Define a selector with a search expression to allow access to components that match the repository path.

After creating the content selector, add the selector to a custom privilege. Use the privilege to provide access to that namespace for a role, group, or user.

Content Selector > Privilege > Role > Group > User

See Manage Selector Permissions

Creating a Content Selector

  1. Go to SettingsRepositoryContent Selectors.
  2. Select Create selector.
  3. Fill in the displayed fields. Mandatory fields are Name and Search Expression. Use the Search Expression field to build your query using CSEL syntax.

Preview Repository

Preview the results of the search expression by selecting the Preview button. The preview only displays 10 results to limit the impact to performance.

  1. Select a repository or grouping of repositories from the Preview Repository dropdown.

  2. Select the Preview button.

  3. Use the Filter option to check for a specific result.

  4. Use the Name column to sort the results.

  5. Select Save to create the content selector.

Content Selector Best Practices

See Content Selectors and Docker

Content Selectors in High Availability

Nexus Repository has two distinct implementations depending on the edition and deployment configuration:

  1. Standard Implementation (CE/Pro Single Node)

    Used for repository browsing and basic content queries
  2. Distributed Search Implementation (Pro with clustering/Cloud)

    Used for search functionality in clustered environments

The user interface validates regular expressions as Java Regular Expression which are further transformed into a form executed by PostgreSQL. This operation only accepts simpler POSIX regular expressions which are not performant in clustered Postgres environments.

Warning In deployments using PostgreSQL, Sonatype recommends avoiding regular expressions as much as possible to avoid crippling impacts to service performance.

For non-HA environments, you may use regular expressions in your content selectors though we recommend using the more performant solutions outlined below.

Content Selector Reference

Below are the attributes for content selectors that define path and format as values. The asset’s path must begin with a leading slash.

Attribute Allowed Values
path The path of your repository content with a leading slash
format The format of the content for which you query (including the format is not required and is not supported for all formats.)

Supported Formats

Content Selectors in Sonatype Nexus Repository are supported for most repository formats. This support is of two types:

Formats with enhanced support:

Formats with basic support:

The following formats have additional limitations:

Operators Allowed for HA Deployments

Operator Description Performance Example
== Matches text exactly Fastest format == "raw"
!= Not equals Fast path != "test.jar"
=^ Starts with text Fast path =^ "/org/apache/commons/"
and Match all expressions Fast format == "maven2" and path =^ "/org/apache/commons"
or Match any expression Fast format == "maven2" or format == "npm"
(expr) Group multiple expressions Variable (depends on pattern) format == "npm" or (format == "maven2" and path =^ "/org/apache/commons")

Operators to Avoid in HA Deployments

Operator Description Performance Example
=~ Matches a Java regular expression pattern Slow path =~ "^/org/apache/commons/.*"
\- Escaping dashes in version ranges Variable (depends on pattern) path =~ "[0-9a-zA-Z\-_]"

Reliable Patterns that are Java + POSIX Compatible

High-Performance Pattern Examples

These patterns are optimized for fast database execution.

Restrict access to specific organization/package paths.

path =~ "^/com/example/.*"

Allow only JAR files, block source/documentation.

path =~ ".*\.jar$"

Company-specific JAR artifacts only.

path =~ "^/com/mycompany/.*\.jar$"

Allow multiple specific top-level packages.

path =~ "^/(com|org|net)/.*"

Poor Performance Pattern Examples

These patterns cause significant performance degradation or timeouts. We recommend avoiding these types of patterns whenever possible.

Catastrophic exponential backtracking, database regex engine gets stuck on deeply nested paths.

// Content Selector - AVOID
path =~ "^(.*/.+)+\.jar$"

Better alternative:

path =~ ".*\.jar$"

The .* matches everything, then backtracks through entire path. Long paths require extensive backtracking to find alternation.

// Content Selector - AVOID
path =~ ".*(debug|test|sample).*\.jar$"

Better alternative:

path =~ "^.*(debug|test|sample)[^/]*\.jar$"
path =~ "^/(com|org|net|edu|gov|mil|int|arpa)/.*"

Database must evaluate multiple lookahead assertions per character.

// Content Selector - AVOID
path =~ "^/(?=.*important)(?!.*test)(?!.*debug).*"

As a better alternative, use simple prefix patterns with AND/OR logic.

path =~ "^/.*important.*" && path !~ ".*test.*"

Catastrophic performance with star height problem, (.*/)* creates exponential combinations.

// Content Selector - AVOID
path =~ "(.*/)*important/.*"

Character class matching multiplied by path depth.

// Content Selector - AVOID
path =~ "^/([a-zA-Z0-9._-]*/)+"

Better alternative:

path =~ "^/[a-zA-Z0-9._/-]+/"

Transform Poor Patterns to Good Patterns

For simple prefix matching, replace regex (=~) with starts-with (=^) operator for dramatic performance improvements.

// Replace these regex patterns:
path =~ "^/com/.*"           → path =^ "/com/"
path =~ "^/org/example/.*"   → path =^ "/org/example/"
path =~ "^/net/sf/.*"        → path =^ "/net/sf/"

Permissions for Tree Browsing

Read access selectors should include access to tree browsing in the Repository Manager UI. The content selectors need to include permissions for the parent directories of the artifacts.

Tree browsing for Highly Available (HA) environments

format == "maven2" and (path == "/" or path == "/org/" or path == "/org/apache/" or path =^ "/org/apache/commons/")

Alternatively, if you don't mind users being able to see any directory name (just not the contents), use the following.

format== "maven2" and path =~".*/|/org/apache/commons.*"