Skip to content

feat(config): support HTTP Basic Authentication credentials#89

Merged
epugh merged 1 commit into
apache:mainfrom
dolphinium:feat/basic-auth-support
Jun 15, 2026
Merged

feat(config): support HTTP Basic Authentication credentials#89
epugh merged 1 commit into
apache:mainfrom
dolphinium:feat/basic-auth-support

Conversation

@dolphinium

@dolphinium dolphinium commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Scope update (per maintainer request): this PR has been split. It now contains only the Basic Auth feature. The text/plain Content-Type tolerance fix has been moved to #90 so each change can be reviewed and merged independently.

Summary

Adds optional HTTP Basic Authentication for the SolrJ client.

  • New configuration properties solr.username / solr.password (bound from SOLR_USERNAME / SOLR_PASSWORD env vars).
  • When both are set, credentials are applied on every request via HttpJdkSolrClient.Builder#withBasicAuthCredentials.
  • When either is missing or the username is blank, the client is built exactly as before — fully backwards-compatible.

Motivation

Tested end-to-end against a production Basic-auth-protected Solr reached through an SSH tunnel. Before this PR every tool call returned 401 require authentication.

Changes

  • SolrConfigurationProperties: add nullable username and password record components (JSpecify @Nullable); expanded JavaDoc.
  • SolrConfig#solrClient: apply withBasicAuthCredentials when both credentials are present and the username is non-blank.
  • Docs: dev-docs/ARCHITECTURE.md and dev-docs/DEVELOPMENT.md list the two new env vars next to SOLR_URL.

Tests

  • SolrConfigAuthTest (new): 5 parameterized cases covering none / username-only / password-only / blank-username / both — asserts via reflection on HttpSolrClientBase#basicAuthAuthorizationStr.
  • SolrConfigUrlNormalizationTest: updated to the new record constructor.
  • ./gradlew build passes locally (Spotless + NullAway + full unit suite).

Test plan

  • ./gradlew spotlessCheck
  • ./gradlew build (unit tests)
  • Manual end-to-end against an authenticated classic-mode Solr 9.x over an SSH tunnel

Notes

  • No new runtime dependencies.
  • Behaviour is strictly backwards-compatible.
  • Signed off under DCO; commit follows Conventional Commits per CONTRIBUTING.md.

Companion PR (Content-Type tolerance fix): #90

Co-authored-by: Claude noreply@anthropic.com

@epugh

epugh commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

If you can split it that would be awesome!!!

@dolphinium dolphinium force-pushed the feat/basic-auth-support branch from 3347b2f to 6e0ee41 Compare April 16, 2026 18:27
@dolphinium dolphinium changed the title feat(config): support HTTP Basic Authentication and tolerate text/plain responses feat(config): support HTTP Basic Authentication credentials Apr 16, 2026
@dolphinium

Copy link
Copy Markdown
Contributor Author

hi @epugh, I separated features as you requested. so happy to contribute to this project. have a great day.

@adityamparikh

Copy link
Copy Markdown
Contributor

Hi! A new PR-validation CI workflow recently landed on main (#117). To get this PR's tests evaluated against the new pipeline, could you rebase your branch onto current main and push? That will trigger the new ci.yml (build / unit / integration). Thanks!

Add optional `solr.username` / `solr.password` configuration properties
(also bound from the `SOLR_USERNAME` / `SOLR_PASSWORD` environment
variables) that, when both are set, are applied to every SolrJ request
via `HttpJdkSolrClient.Builder#withBasicAuthCredentials`. When either
value is missing or the username is blank, the client is built without
credentials so existing unauthenticated deployments are unaffected.

Documents the new variables in the Development and Architecture guides
and adds `SolrConfigAuthTest` covering:

- no credentials attached when both values are missing,
- no credentials attached when only one value is provided (or the
  username is blank), and
- credentials applied when both values are provided.

The existing `SolrConfigUrlNormalizationTest` is updated to the new
record constructor.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Yunus Emre Korkmaz <yunus.emre.korkmaz@turboard.com>
@adityamparikh

Copy link
Copy Markdown
Contributor

Thanks for this, @dolphinium! I took your feature commit unchanged and opened #152 on top of it, folding in a small review-cleanup pass (reuse StringUtils.hasText + Spring ReflectionUtils in the test, tighten the auth-header assertion to an exact match). Your authorship is preserved as the first commit there, and ./gradlew build passes.

Whether to continue here or land via #152 is up to the maintainers — just wanted to link the two so the connection is visible from both sides.

@epugh epugh merged commit 19aaccb into apache:main Jun 15, 2026
1 check passed
epugh added a commit that referenced this pull request Jun 15, 2026
…152)

* feat(config): support HTTP Basic Authentication credentials

Add optional `solr.username` / `solr.password` configuration properties
(also bound from the `SOLR_USERNAME` / `SOLR_PASSWORD` environment
variables) that, when both are set, are applied to every SolrJ request
via `HttpJdkSolrClient.Builder#withBasicAuthCredentials`. When either
value is missing or the username is blank, the client is built without
credentials so existing unauthenticated deployments are unaffected.

Documents the new variables in the Development and Architecture guides
and adds `SolrConfigAuthTest` covering:

- no credentials attached when both values are missing,
- no credentials attached when only one value is provided (or the
  username is blank), and
- credentials applied when both values are provided.

The existing `SolrConfigUrlNormalizationTest` is updated to the new
record constructor.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Yunus Emre Korkmaz <yunus.emre.korkmaz@turboard.com>

* refactor(config): reuse Spring StringUtils/ReflectionUtils in basic-auth wiring

Review cleanup on top of the HTTP Basic Auth support from #89 (by
@dolphinium). No behavioural change to the feature.

- SolrConfig: replace the inline `username != null && !username.isEmpty()`
  guard with Spring's `StringUtils.hasText`, matching the convention already
  used in HttpSecurityConfiguration and SearchService.
- SolrConfigAuthTest: drop the hand-rolled superclass-walking `findField`
  helper in favour of `ReflectionUtils.findField`/`makeAccessible`/`getField`,
  and tighten the over-defensive `equals(x) || equals("Basic " + x)` assertion
  to an exact `assertEquals` now that the stored format is known (SolrJ stores
  `"Basic " + Base64(user:pass)` in UTF-8).

./gradlew build passes (Spotless + NullAway + full test suite incl. Testcontainers).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>

---------

Signed-off-by: Yunus Emre Korkmaz <yunus.emre.korkmaz@turboard.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
Signed-off-by: Eric Pugh <epugh@opensourceconnections.com>
Co-authored-by: Yunus Emre Korkmaz <yunus.emre.korkmaz@turboard.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Eric Pugh <epugh@opensourceconnections.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants