Skip to content

feature/login-home-screen - #30

Closed
gvaguirres wants to merge 3 commits into
mainfrom
feature/login-home-screen
Closed

feature/login-home-screen#30
gvaguirres wants to merge 3 commits into
mainfrom
feature/login-home-screen

Conversation

@gvaguirres

@gvaguirres gvaguirres commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features

    • Added admin dashboard now exclusively accessible to admin users
    • Implemented role-based routing: admins directed to dashboard, users to home page
    • Development environment now includes pre-seeded admin account for testing
  • Chores

    • Updated security configuration and streamlined endpoint handlers

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@gvaguirres has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 39 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 7 minutes and 39 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: 2ae09d09-5d08-42f2-a331-d85636de145f

📥 Commits

Reviewing files that changed from the base of the PR and between 84db270 and e255368.

📒 Files selected for processing (1)
  • src/main/java/backendlab/team4you/controller/SignupController.java
📝 Walkthrough

Walkthrough

This pull request restructures the application's authentication and authorization flow by introducing role-based routing, seeding an admin user in the dev profile, separating admin and user endpoints across controllers, and updating security configuration to enforce role-specific access controls.

Changes

Cohort / File(s) Summary
Seed Data & User Initialization
src/main/java/backendlab/team4you/Team4youApplication.java
Added admin user creation in dev-profile seed data with encoded credentials and ROLE_ADMIN assignment; updated existing seeded user with new encoded ID, modified password/email, and ROLE_USER assignment.
Security Configuration
src/main/java/backendlab/team4you/config/SecurityConfig.java, src/main/java/backendlab/team4you/config/CustomAuthenticationSuccessHandler.java
Updated authorization rules to restrict /dashboard to ROLE_ADMIN, /home and /profile/** to ROLE_USER; modified form-login to redirect to / instead of /login; added conditional authentication success redirect (admin → /dashboard, others → /home); updated role mapping to strip ROLE_ prefix.
Controller Reorganization
src/main/java/backendlab/team4you/controller/AdminController.java, src/main/java/backendlab/team4you/controller/SignupController.java, src/main/java/backendlab/team4you/controller/UserController.java
Moved /dashboard endpoint from SignupController to new AdminController with @PreAuthorize("hasRole('ADMIN')") protection; added /home endpoint in UserController; changed root (/) endpoint to return login view.
Configuration
src/main/resources/application.properties
Added trailing newline to properties file.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AuthHandler as AuthenticationHandler
    participant SecurityContext as SecurityContext
    participant AdminController as AdminController
    participant UserController as UserController

    Client->>AuthHandler: POST /login (credentials)
    AuthHandler->>SecurityContext: Authenticate user
    SecurityContext-->>AuthHandler: Authentication result + roles
    
    alt Has ROLE_ADMIN
        AuthHandler->>AdminController: Redirect to /dashboard
        AdminController-->>Client: Return dashboard view
    else Has ROLE_USER
        AuthHandler->>UserController: Redirect to /home
        UserController-->>Client: Return home view
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • JohanHiths
  • MartinStenhagen

Poem

🐰 Admin and user paths now divide so clear,
Seeds planted with roles, the config's sincere,
Dashboard for admins, home for the rest,
Authorization guards keeping security blessed!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 PR title 'feature/login-home-screen' is partially related to the changes but misleading. While routing changes involve login and home screens, the changeset includes substantial security enhancements (admin role setup, role-based authorization, WebAuthn handling) that aren't captured by the title. Consider a more descriptive title that reflects the main changes: 'feature: add role-based access control with admin dashboard' or 'feature: implement admin role and role-based routing' would better represent the full scope of security changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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/login-home-screen

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.

@gvaguirres gvaguirres linked an issue Apr 16, 2026 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/backendlab/team4you/config/SecurityConfig.java (1)

40-45: ⚠️ Potential issue | 🔴 Critical

/admin/** is still exposed to any authenticated user.

Only /dashboard is admin-gated here. AdminController still exposes GET /admin/logs, GET /admin/users, POST /admin/users, and POST /admin/logs/delete, and those now fall through to .anyRequest().authenticated(). A regular USER can still hit admin pages and admin mutations.

🔐 Minimal fix
-                                .requestMatchers("/dashboard").hasRole("ADMIN")
+                                .requestMatchers("/dashboard", "/admin/**").hasRole("ADMIN")
                                 .requestMatchers("/home", "/profile/**").hasRole("USER")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/backendlab/team4you/config/SecurityConfig.java` around lines 40
- 45, SecurityConfig currently only restricts "/dashboard" to ADMIN, leaving
"/admin/**" governed by .anyRequest().authenticated() so USERs can access
AdminController endpoints; update the authorization matcher list in
SecurityConfig to explicitly restrict the admin endpoints by adding a rule like
requestMatchers("/admin/**").hasRole("ADMIN") (placed before
.anyRequest().authenticated()) so all AdminController routes (e.g., GET/POST
/admin/logs, /admin/users) require the ADMIN role.
🧹 Nitpick comments (1)
src/main/java/backendlab/team4you/Team4youApplication.java (1)

32-47: Store seeded roles in one format.

This writes ROLE_ADMIN for the admin and USER for the normal user. The rest of the auth flow already has to compensate for both shapes, which makes authority creation brittle. Pick one persisted role format and keep all writers on it.

♻️ Example if you standardize on unprefixed stored roles
-				devAdmin.setRole("ROLE_ADMIN");
+				devAdmin.setRole("ADMIN");
...
 				devUser.setRole("USER");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/backendlab/team4you/Team4youApplication.java` around lines 32 -
47, The seeded roles are inconsistent: devAdmin uses "ROLE_ADMIN" while devUser
uses "USER", which forces auth code to handle two formats; standardize persisted
roles (pick one format) and update the seeders accordingly — for example change
devAdmin.setRole("ROLE_ADMIN") to devAdmin.setRole("ADMIN") (or alternatively
change devUser.setRole("USER") to "ROLE_USER") so both UserEntity instances
(devAdmin and devUser in Team4youApplication.java) call setRole with the same
normalized string; ensure any other seeding or hard-coded role writes follow the
chosen format.
🤖 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/backendlab/team4you/Team4youApplication.java`:
- Around line 24-50: The current seeding logic inside Team4youApplication only
runs when repository.count() == 0, so existing databases with users skip
creating the dev admin; change it to always check and create the dev admin
independently by querying for the admin user (e.g., findByName or findByEmail or
a repository.existsByRole/existsByName) and only call repository.save(new
UserEntity(...)) for the devAdmin if that lookup returns absent, while leaving
the existing repository.count() block (or other seeds) intact for creating the
devUser; reference the UserEntity devAdmin construction,
devAdmin.setRole("ROLE_ADMIN"), and repository.save(devAdmin) to locate where to
add the existence check and conditional save.

---

Outside diff comments:
In `@src/main/java/backendlab/team4you/config/SecurityConfig.java`:
- Around line 40-45: SecurityConfig currently only restricts "/dashboard" to
ADMIN, leaving "/admin/**" governed by .anyRequest().authenticated() so USERs
can access AdminController endpoints; update the authorization matcher list in
SecurityConfig to explicitly restrict the admin endpoints by adding a rule like
requestMatchers("/admin/**").hasRole("ADMIN") (placed before
.anyRequest().authenticated()) so all AdminController routes (e.g., GET/POST
/admin/logs, /admin/users) require the ADMIN role.

---

Nitpick comments:
In `@src/main/java/backendlab/team4you/Team4youApplication.java`:
- Around line 32-47: The seeded roles are inconsistent: devAdmin uses
"ROLE_ADMIN" while devUser uses "USER", which forces auth code to handle two
formats; standardize persisted roles (pick one format) and update the seeders
accordingly — for example change devAdmin.setRole("ROLE_ADMIN") to
devAdmin.setRole("ADMIN") (or alternatively change devUser.setRole("USER") to
"ROLE_USER") so both UserEntity instances (devAdmin and devUser in
Team4youApplication.java) call setRole with the same normalized string; ensure
any other seeding or hard-coded role writes follow the chosen format.
🪄 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: 3aa89a6c-5afe-4d56-8f80-873b62e7a0e3

📥 Commits

Reviewing files that changed from the base of the PR and between 49aba48 and 84db270.

📒 Files selected for processing (7)
  • src/main/java/backendlab/team4you/Team4youApplication.java
  • src/main/java/backendlab/team4you/config/CustomAuthenticationSuccessHandler.java
  • src/main/java/backendlab/team4you/config/SecurityConfig.java
  • src/main/java/backendlab/team4you/controller/AdminController.java
  • src/main/java/backendlab/team4you/controller/SignupController.java
  • src/main/java/backendlab/team4you/controller/UserController.java
  • src/main/resources/application.properties
💤 Files with no reviewable changes (1)
  • src/main/java/backendlab/team4you/controller/SignupController.java

Comment thread src/main/java/backendlab/team4you/Team4youApplication.java
@gvaguirres gvaguirres closed this Apr 18, 2026
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.

Home-screen/login

1 participant