feat(config): support HTTP Basic Authentication credentials#89
Conversation
|
If you can split it that would be awesome!!! |
3347b2f to
6e0ee41
Compare
|
hi @epugh, I separated features as you requested. so happy to contribute to this project. have a great day. |
|
Hi! A new PR-validation CI workflow recently landed on |
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>
c266d19 to
c3d03bf
Compare
|
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 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. |
…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>
Summary
Adds optional HTTP Basic Authentication for the SolrJ client.
solr.username/solr.password(bound fromSOLR_USERNAME/SOLR_PASSWORDenv vars).HttpJdkSolrClient.Builder#withBasicAuthCredentials.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 nullableusernameandpasswordrecord components (JSpecify@Nullable); expanded JavaDoc.SolrConfig#solrClient: applywithBasicAuthCredentialswhen both credentials are present and the username is non-blank.dev-docs/ARCHITECTURE.mdanddev-docs/DEVELOPMENT.mdlist the two new env vars next toSOLR_URL.Tests
SolrConfigAuthTest(new): 5 parameterized cases covering none / username-only / password-only / blank-username / both — asserts via reflection onHttpSolrClientBase#basicAuthAuthorizationStr.SolrConfigUrlNormalizationTest: updated to the new record constructor../gradlew buildpasses locally (Spotless + NullAway + full unit suite).Test plan
./gradlew spotlessCheck./gradlew build(unit tests)Notes
CONTRIBUTING.md.Companion PR (Content-Type tolerance fix): #90
Co-authored-by: Claude noreply@anthropic.com