-
Work Log for SZ-20: Enable Basic Auth with JDBC-backed UserDetailsService
Timeline
- 2025-10-22: Issue created to address
401 Unauthorizederrors despite correct credentials. - 2025-10-23:
- Implemented
CustomUserDetailsServicebacked by Spring Data JPA. - Updated
BasicAuthSecurityConfigto use JDBC authentication andPasswordEncoder. - Added role-based access using
@PreAuthorizeand verified/api/usersrequiresROLE_ADMIN. - Verified login behavior via
curl -u admin@sztab.local:admin123on/api/users.
- Implemented
- 2025-10-24:
- Verified account creation and role assignment via POST
/api/users. - Diagnosed and resolved
TransientObjectExceptionby passing roleidin payload instead of justname. - Used
curlto list roles and confirm IDs. - Added
MarkdownViewControllerand/docs/index.htmlas static endpoint for testing public access. - Implemented and verified unit tests for
CustomUserDetailsService. - Merged branch
bugfix/sz20-basic-auth-yields-401towolnosc.
- Verified account creation and role assignment via POST
Technical Changes
- Created
CustomUserDetailsService.javato load users and roles from database. - Updated Spring Security config (
BasicAuthSecurityConfig.java) to:- Use
UserDetailsService - Encode passwords using
BCryptPasswordEncoder - Permit actuator endpoints and static docs without authentication
- Use
- Cleaned up
application.ymlto use properties appropriate for JDBC auth - Verified via
curlthat:- Basic Auth protects
/api/**endpoints - Role-based restrictions are enforced
- New users can be created with valid credentials
- Basic Auth protects
- Ensured new controller (
/docs/**) is public
Resolution
Basic Authentication is now enabled and functional using a JDBC-backed
UserDetailsService.
Test coverage added for the service, andcurlcalls verified successful user creation and protection of endpoints.
Branchbugfix/sz20-basic-auth-yields-401merged towolnosc.No version bump needed as this does not introduce any new externally visible features — internal correctness fix only.
- 2025-10-22: Issue created to address
-
Resolved.
Final implementation uses a JDBC-backed
UserDetailsServiceand fully verifies Basic Auth with curl-based user creation, login, and role retrieval.I originally estimated 2 hours but ended up spending ~7 hours, including time on a now-suspended UT approach. This helped clarify some Spring Security profile behavior, and I’ll factor this into future estimates.
Changes merged into
wolnosc. -
| Type |
Bug
|
| Priority |
Normal
|
| Assignee | |
| Version |
1.0
|
| Sprints |
n/a
|
| Customer |
n/a
|
Problem
Sztab backend (v1.2) fails to authenticate the admin user via HTTP Basic Auth when running via Docker Compose, even though:
PasswordEncoderbean is correctly declared inBasicAuthSecurityConfig.Root Cause
The
JdbcUserDetailsManagerbean is not explicitly wired to thePasswordEncoder, so Spring Security may use the default (noop) encoder during authentication, leading to password mismatch.Logs
Workaround
No temporary workaround unless Spring autowires correctly via global context — behavior is unpredictable and environment-dependent.
Fix Plan
Inject the
PasswordEncoderintoJdbcUserDetailsManagerexplicitly inBasicAuthSecurityConfig:Impact
Only affects Basic Auth login for users stored in the DB (e.g.,
admin). All other functionality remains unaffected.