Repository navigation
Recover role management work and fix what it would break - #31
Merged
Merged
Conversation
RoleController carries @PreAuthorize("hasRole('ROLE_ADMIN')"), but method security is never enabled, and /roles/** falls outside the /admin/** URL rule. Any authenticated user can create or delete roles. The non-admin case currently gets a 302 and the role is saved; it should get a 403. Adds spring-security-test for @WithMockUser and csrf(). [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Without @EnableMethodSecurity, the @PreAuthorize annotations on RoleController and AdminController are silently ignored. Enabling it makes the role check on RoleController effective, so non-admin users now get a 403. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Role management now sits behind both the /admin/** URL rule and the controller's @PreAuthorize check, instead of relying on one alone. - Remove GET /roles, which rendered a role_home template that was never written. The HR administrator page already lists roles. - Redirect to /admin after create and delete instead of echoing the Referer header, which produced "redirect:null" when it was absent. - Bind department as the RoleDepartment enum and roleId as a long, so bad input returns 400 instead of a 500 from valueOf/parseLong. - Use hasRole('ADMIN') in both controllers, matching the URL rule; Spring adds the ROLE_ prefix. Tests cover delete, bad input, and the method-level check on its own, independent of the URL rule. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
RepairOrder.priority is constrained with @pattern("/([0-9])+/g"), a JavaScript regex literal. Java treats the slashes and "g" as literal characters, so no single-digit priority can match, including the field's own default of "0". This was harmless while the project had no Bean Validation provider. The spring-boot-starter-validation dependency from the working branch makes Hibernate validate entities before insert, at which point every new repair order would be rejected. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Replace the JavaScript-style pattern with "[0-9]", a single digit, which also makes @SiZe(max = 1) redundant. The new repair order form now uses a number input limited to 0-9, so the browser stops out-of-range values before they reach the server. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
With a Bean Validation provider on the classpath, @Valid on CustomerController is enforced for the first time. Cover the normal create flow end to end, and confirm a customer without a last name is now rejected with 400 instead of being saved. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The roles toolbar had a "Cool Button" with no id, handler or action. [Ticket: #13] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13
Background
d6fd705is the last commit that survived a hardware failure in early 2025. It was pushed toworkingbut never merged, so the last two months of work were invisible frommain. It adds role management (RoleController,RoleDepartment), a rebuilt HR administrator page, and a switch fromjakarta.validation-apitospring-boot-starter-validation.This PR brings that commit in unchanged and fixes what it would have broken. The branch was brought up to date by merging
maininto it rather than rebasing, which would have rewritten the original commit.Fixes on top of the recovered commit
Role endpoints were open to any logged-in user.
RoleControllerrelied on@PreAuthorize, but method security was never enabled, and/roles/**sat outside the/admin/**URL rule.@EnableMethodSecurity. This also makes the existing check onAdminControllereffective./admin/roles, so the URL rule and the method check each protect them independently.GET /roles, which rendered arole_hometemplate that doesn't exist./admininstead of echoing theRefererheader, which becameredirect:nullwhen the header was missing.RoleDepartment,long), so bad input gets a 400 instead of a 500.Every new repair order would have failed to save. Before merging, I audited everything the validation starter turns on. With a Bean Validation provider present, Hibernate validates entities before insert and update, so constraints that were decorative on
mainbecome enforced:@NotNullcan never failRepairOrder.priority@Pattern("/([0-9])+/g"), a JavaScript regex literal that no value can match, including the field's own default"0". Fixed to[0-9]; the form input is now a 0–9 number fieldAlso removed a leftover "Cool Button" with no behavior from the HR page's roles toolbar.
Behavior changes to know about
@Validis now enforced. A customer without a last name, or an employee with a blank first or last name, gets a 400 instead of being saved.Tests
The commits are ordered test-first for both bugs: the failing test lands first, then the fix.
RoleControllerSecurityTest(6)RepairOrderValidationTest(9)0/5/9valid;""," ",a,10,-1rejectedCustomerControllerTest(2)18 tests passing, 0 DDL errors on the H2 test profile.
Not in this PR
GET /admin/create_employeestill renders the nonexistentemployee_form; tracked in Fix routes to missing templates and file-upload setup #17.🤖 Generated with Claude Code