Skip to content

Feature/access/logback#87

Merged
gitnes94 merged 4 commits into
mainfrom
feature/Access/logback
Apr 22, 2026
Merged

Feature/access/logback#87
gitnes94 merged 4 commits into
mainfrom
feature/Access/logback

Conversation

@gitnes94

@gitnes94 gitnes94 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features

    • Error pages for 404 and 500 errors now properly handled
    • Dashboard displays ticket creator information
    • Enhanced system logging with user attribution
  • Security

    • Authentication now required on staff self-service endpoints
    • Authorization checks added to ticket access operations
    • Updated ticket management authorization requirements

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@gitnes94 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 38 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 14 minutes and 38 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: 1fac5b49-5ca6-49e3-adda-6f5b8bf5e20b

📥 Commits

Reviewing files that changed from the base of the PR and between 931edeb and 57a4d97.

📒 Files selected for processing (1)
  • src/main/resources/logback-spring.xml
📝 Walkthrough

Walkthrough

This PR enhances application security and observability by adding method-level authorization checks across ticket-related endpoints, introducing a comprehensive Logback configuration for structured logging, implementing detailed audit logging with staff identifiers in critical operations, and registering error page routes while improving security configuration ordering.

Changes

Cohort / File(s) Summary
Gitignore & Logging Configuration
.gitignore, src/main/resources/Logback spring.xml, src/main/resources/application.properties
Added logs/ directory to version control exclusions, introduced Logback rolling file appender writing to logs/cyberwatch.log with daily rotation and 30-day retention, and configured Spring Security to DEBUG level.
Authorization & Security Framework
src/main/java/org/example/cyberwatch/config/SecurityConfig.java, src/main/java/org/example/cyberwatch/config/security/TicketSecurityService.java, src/main/java/org/example/cyberwatch/exception/GlobalExceptionHandler.java
Updated HTTP authorization configuration for new /api/staff/me* endpoints, added isAdmin() public method to TicketSecurityService with warning logs on denial, added denial logging to existing access check methods, and cleaned up exception handler annotations.
Web Configuration
src/main/java/org/example/cyberwatch/config/WebConfig.java
Registered view controller forwarding for error pages /error/404 and /error/500 to static HTML responses.
Controller Security Annotations
src/main/java/org/example/cyberwatch/features/activitylog/controller/ActivityLogController.java, src/main/java/org/example/cyberwatch/features/comment/controller/CommentController.java, src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java
Added @PreAuthorize constraints to activity log retrieval and comment operations using ticket-specific security checks; migrated ticket admin operations from hasRole('ADMIN') to isAdmin() bean-based authorization.
Service Logging Enhancements
src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java, src/main/java/org/example/cyberwatch/features/activitylog/service/ActivityLogService.java
Enhanced TicketService log statements to include staff identifiers (performedById, assignedById, uploadedById) for ticket status, reopening, assignment, and upload operations; removed obsolete comments.
UI Improvements
src/main/resources/static/js/dashboard.js
Added ticket creator name rendering in dashboard ticket cards using createdBy.fullName with HTML escaping and fallback to Okänd; corrected malformed onkeydown attribute markup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Added roll based access control. #77: Updates TicketSecurityService with logging and introduces the isAdmin() method that is now being utilized across multiple controllers for authorization decisions.
  • Feature/employment #81: Modifies SecurityConfig and WebConfig to handle /api/staff/me endpoints and status changes, overlapping with the security configuration updates in this PR.
  • Added S3 Security and bunch of other stuff #76: Modifies TicketController and TicketService for ticket-related features; this PR's authorization and logging changes affect the same endpoints and service methods.

Suggested reviewers

  • alicewersen-rgb
  • codebyNorthsteep

Poem

🐰 Hop hop, the logs now flow,
Security gates on guard below,
Admins checked with proper care,
Rolling files float through the air!
Authorization blooms so bright,
Our burrows secured, day and night! 🔐

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/access/logback' is vague and does not clearly convey the main purpose of the changes, using generic branch naming convention rather than describing the actual functionality. Revise the title to clearly describe the primary change, such as 'Add authentication guards and Logback logging configuration' or 'Implement access control checks and structured logging'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 feature/Access/logback

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.

@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: 5

🧹 Nitpick comments (2)
src/main/java/org/example/cyberwatch/config/security/TicketSecurityService.java (1)

83-91: Consider null-guarding authentication in isAdmin.

canAccess/canAccessByCode also assume authentication is non-null, but since isAdmin is now invoked from method-level SpEL on endpoints where Spring Security normally supplies a non-null Authentication, this is low-risk. Still, a defensive if (authentication == null) return false; would align with typical PermissionEvaluator-style helpers and avoid an NPE if ever invoked outside a filtered context (e.g., tests, internal callers).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/cyberwatch/config/security/TicketSecurityService.java`
around lines 83 - 91, Add a defensive null check at the start of
isAdmin(Authentication authentication): if authentication is null return false;
this prevents an NPE when isAdmin is invoked outside a secured filter context
(e.g., in tests or internal callers). Locate the isAdmin method in
TicketSecurityService and add the null-guard before using
authentication.getPrincipal(); no other behavior should change (canAccess and
canAccessByCode can remain as-is for now, but follow the same pattern if you
want consistency with PermissionEvaluator-style helpers).
src/main/resources/Logback spring.xml (1)

14-14: Relative log path logs/cyberwatch.log depends on the process working directory.

Using a relative path means logs land in whatever directory the JVM is launched from, which is fragile across environments (IDE run vs. java -jar vs. containers). Consider parameterizing via a Spring property so it can be overridden per-environment:

-        <file>logs/cyberwatch.log</file>
+        <springProperty scope="context" name="LOG_PATH" source="logging.file.path" defaultValue="logs"/>
+        <file>${LOG_PATH}/cyberwatch.log</file>

And update fileNamePattern on line 19 to use ${LOG_PATH} accordingly. Note that <springProperty> requires the file to be named logback-spring.xml (see the filename comment above).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/Logback` spring.xml at line 14, Change the hardcoded
relative path in the <file> element to a Spring-configurable property and update
the rolling <fileNamePattern> to use it: add a <springProperty name="LOG_PATH"
source="LOG_PATH" defaultValue="logs"/> via <springProperty>, replace <file>
value with ${LOG_PATH}/cyberwatch.log and adjust the <fileNamePattern> to
reference ${LOG_PATH} as well; also ensure the config file is named
logback-spring.xml so <springProperty> is supported.
🤖 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/cyberwatch/config/WebConfig.java`:
- Around line 19-21: The registered view controllers for "/error/404" and
"/error/500" won't catch actual HTTP error dispatches; add an ErrorPageRegistrar
bean (e.g., errorPageRegistrar()) that calls registry.addErrorPages(new
ErrorPage(HttpStatus.NOT_FOUND, "/error/404")) and registry.addErrorPages(new
ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")) so error responses
are routed to those paths; import ErrorPage,
ErrorPageRegistrar/ErrorPageRegistry and HttpStatus accordingly.

In
`@src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java`:
- Line 141: The logs in TicketService (e.g., the line logging "Ticket {} status
avancerad..." and similar lines at the other noted locations) currently include
caller-supplied IDs like performedById/assignedById/uploadedById which are
untrusted; change the API and service boundary so the controller resolves the
acting staff from the authenticated principal and passes a server-side actor
identity into service methods (instead of accepting performedById/uploadedById
from request params), remove those caller-controlled ID parameters from public
request signatures and from these audit-style log statements, and update the
service methods (TicketService methods that perform status
changes/assignments/uploads) to accept only the server-resolved actor identity
before reintroducing actor IDs in logs.

In `@src/main/resources/application.properties`:
- Line 27: The default property logging.level.org.springframework.security=DEBUG
should not be enabled globally; change the default to a less verbose level
(e.g., INFO or WARN) in application.properties and move the DEBUG setting into a
profile-specific file (e.g., application-dev.properties or
application-local.properties) or enable it via a spring profile so DEBUG is only
active when a development profile is active; update any documentation or run
configurations to use that profile when you need verbose security logs and
verify by running with the dev profile that
logging.level.org.springframework.security=DEBUG is applied while the default
environment uses INFO/WARN.

In `@src/main/resources/Logback` spring.xml:
- Around line 34-38: The org.springframework logger in the XML is set to WARN
which overrides the DEBUG setting for org.springframework.security from
application.properties; to preserve Spring Security DEBUG output, add an
explicit logger entry for org.springframework.security with level="DEBUG" in
this XML (e.g., <logger name="org.springframework.security" level="DEBUG"/>), or
alternatively remove the org.springframework.security DEBUG override from
application.properties so there is no conflicting configuration—modify the
logger entries around the existing <logger name="org.springframework"
level="WARN"/> and <logger name="org.example.cyberwatch" level="INFO"/> to
include the explicit child logger if keeping DEBUG.
- Around line 1-45: The Logback config file is misnamed so Spring Boot won't
load it; rename the resource file from "Logback spring.xml" to
"logback-spring.xml" so Spring Boot auto-detects it, ensuring the
<configuration> with appenders "CONSOLE" and "FILE", the <file> element pointing
to logs/cyberwatch.log, the rollingPolicy settings (fileNamePattern,
maxFileSize, maxHistory, totalSizeCap) and the logger entries
(org.springframework, org.hibernate, org.example.cyberwatch, and the <root>
logger) are applied at runtime.

---

Nitpick comments:
In
`@src/main/java/org/example/cyberwatch/config/security/TicketSecurityService.java`:
- Around line 83-91: Add a defensive null check at the start of
isAdmin(Authentication authentication): if authentication is null return false;
this prevents an NPE when isAdmin is invoked outside a secured filter context
(e.g., in tests or internal callers). Locate the isAdmin method in
TicketSecurityService and add the null-guard before using
authentication.getPrincipal(); no other behavior should change (canAccess and
canAccessByCode can remain as-is for now, but follow the same pattern if you
want consistency with PermissionEvaluator-style helpers).

In `@src/main/resources/Logback` spring.xml:
- Line 14: Change the hardcoded relative path in the <file> element to a
Spring-configurable property and update the rolling <fileNamePattern> to use it:
add a <springProperty name="LOG_PATH" source="LOG_PATH" defaultValue="logs"/>
via <springProperty>, replace <file> value with ${LOG_PATH}/cyberwatch.log and
adjust the <fileNamePattern> to reference ${LOG_PATH} as well; also ensure the
config file is named logback-spring.xml so <springProperty> is supported.
🪄 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: 20ef20b2-e086-4193-af68-a58b4766d300

📥 Commits

Reviewing files that changed from the base of the PR and between fdd8827 and 931edeb.

⛔ Files ignored due to path filters (1)
  • logs/cyberwatch.log is excluded by !**/*.log
📒 Files selected for processing (13)
  • .gitignore
  • src/main/java/org/example/cyberwatch/config/SecurityConfig.java
  • src/main/java/org/example/cyberwatch/config/WebConfig.java
  • src/main/java/org/example/cyberwatch/config/security/TicketSecurityService.java
  • src/main/java/org/example/cyberwatch/exception/GlobalExceptionHandler.java
  • src/main/java/org/example/cyberwatch/features/activitylog/controller/ActivityLogController.java
  • src/main/java/org/example/cyberwatch/features/activitylog/service/ActivityLogService.java
  • src/main/java/org/example/cyberwatch/features/comment/controller/CommentController.java
  • src/main/java/org/example/cyberwatch/features/ticket/controller/TicketController.java
  • src/main/java/org/example/cyberwatch/features/ticket/service/TicketService.java
  • src/main/resources/Logback spring.xml
  • src/main/resources/application.properties
  • src/main/resources/static/js/dashboard.js
💤 Files with no reviewable changes (1)
  • src/main/java/org/example/cyberwatch/features/activitylog/service/ActivityLogService.java

Comment thread src/main/java/org/example/cyberwatch/config/WebConfig.java
Comment thread src/main/resources/application.properties Outdated
Comment thread src/main/resources/logback-spring.xml
Comment thread src/main/resources/logback-spring.xml
@gitnes94
gitnes94 merged commit f693ef4 into main Apr 22, 2026
2 checks passed
@gitnes94
gitnes94 deleted the feature/Access/logback branch April 22, 2026 19:16
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.

1 participant