Skip to content

bugfix: register dev auth filter inside Spring Security#208

Merged
TatjanaTrajkovic merged 4 commits into
mainfrom
bugfix/devsecconfigApiError
Apr 15, 2026
Merged

bugfix: register dev auth filter inside Spring Security#208
TatjanaTrajkovic merged 4 commits into
mainfrom
bugfix/devsecconfigApiError

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

filter chain

DevSecurityConfig's X-Dev-User filter was auto-registered
as a servlet filter,
causing SecurityContextHolderFilter to reset the
SecurityContext before auth
could be checked. Moved it inside the security chain via
SecurityConfig.
Also reverted incorrect ObjectMapper import in controller
tests to tools.jackson.

Summary by CodeRabbit

  • Refactor
    • Improved servlet filter registration management for authentication configuration.
    • Enhanced conditional filter chain setup for better control over authentication filter initialization.

  filter chain

  DevSecurityConfig's X-Dev-User filter was auto-registered
   as a servlet filter,
  causing SecurityContextHolderFilter to reset the
  SecurityContext before auth
  could be checked. Moved it inside the security chain via
  SecurityConfig.
  Also reverted incorrect ObjectMapper import in controller
   tests to tools.jackson.
@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@TatjanaTrajkovic has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 51 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 51 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f773bdc-234e-4719-a17d-5b312a7ac9cb

📥 Commits

Reviewing files that changed from the base of the PR and between 83c3774 and 1b3ff37.

📒 Files selected for processing (3)
  • src/main/java/org/example/vet1177/config/DevSecurityConfig.java
  • src/main/java/org/example/vet1177/entities/ActivityLog.java
  • src/main/java/org/example/vet1177/exception/GlobalExceptionHandler.java
📝 Walkthrough

Walkthrough

The changes introduce selective registration of a development authentication filter into the Spring Security filter chain. The DevSecurityConfig explicitly names the devAuthFilter bean and suppresses its automatic servlet filter registration via a FilterRegistrationBean, while SecurityConfig optionally injects and conditionally inserts it into the security filter chain before JWT authentication.

Changes

Cohort / File(s) Summary
DevSecurityConfig Filter Registration
src/main/java/org/example/vet1177/config/DevSecurityConfig.java
Added FilterRegistrationBean bean to disable servlet filter auto-registration of devAuthFilter. Renamed existing bean to @Bean("devAuthFilter") for explicit referencing. Removed unused User import.
SecurityConfig Filter Chain Integration
src/main/java/org/example/vet1177/security/SecurityConfig.java
Added optional injection of devAuthFilter with @Autowired(required=false) and @Qualifier("devAuthFilter"). Modified securityFilterChain() to conditionally register the filter before JwtAuthenticationFilter in the security chain.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

Hops the filter, deft and neat,
In the chain where devs can meet,
Conditional logic, gracefully weaves,
Before JWT, belief it believes! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: registering the dev auth filter inside Spring Security, which aligns with the primary objective of moving the filter from auto-registration as a servlet filter to the Spring Security filter chain.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/devsecconfigApiError

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@TatjanaTrajkovic TatjanaTrajkovic linked an issue Apr 15, 2026 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/example/vet1177/config/DevSecurityConfig.java`:
- Around line 70-72: The devAuthFilterRegistration method is injecting a
OncePerRequestFilter ambiguously (there are multiple OncePerRequestFilter beans
such as JwtAuthenticationFilter); fix by adding `@Qualifier`("devAuthFilter") to
the method parameter so Spring injects the specific "devAuthFilter" bean —
update the parameter in devAuthFilterRegistration to accept `@Lazy`
`@Qualifier`("devAuthFilter") OncePerRequestFilter devAuthFilter to disambiguate
injection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32e1daa9-2c6a-49b1-8693-96a90317e3f2

📥 Commits

Reviewing files that changed from the base of the PR and between ac27de5 and 83c3774.

📒 Files selected for processing (2)
  • src/main/java/org/example/vet1177/config/DevSecurityConfig.java
  • src/main/java/org/example/vet1177/security/SecurityConfig.java

Comment thread src/main/java/org/example/vet1177/config/DevSecurityConfig.java
  Entity used description/created_at but schema defines
  details/performed_at.
  Also added missing entity_type field which is NOT NULL in
   the schema,
  causing a constraint violation on every medical record
  creation.
  of 500
  The generic Exception handler was catching Spring's
  AccessDeniedException
  before it could be mapped to 403, causing @PreAuthorize
  failures to return 500.
@TatjanaTrajkovic
TatjanaTrajkovic merged commit caec9c7 into main Apr 15, 2026
2 checks passed
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.

bugfix: fix broken endpoints

1 participant