-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/profile #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/profile #17
Changes from all commits
8a40658
e07b1a6
4736509
0b75ede
7e5913e
0ef19ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,13 +21,13 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) { | |||||||||
| return http | ||||||||||
| .authorizeHttpRequests(auth -> { | ||||||||||
| auth.requestMatchers("/").permitAll(); | ||||||||||
| auth.requestMatchers("/static/**").permitAll(); | ||||||||||
| auth.requestMatchers("/*.css", "/images/**").permitAll(); | ||||||||||
| auth.requestMatchers("/favicon.ico").permitAll(); | ||||||||||
| auth.requestMatchers("/index").permitAll(); | ||||||||||
| auth.requestMatchers("/error").permitAll(); | ||||||||||
| auth.requestMatchers("/cases/add").hasRole("ADMIN"); | ||||||||||
|
|
||||||||||
| auth.requestMatchers("/cases").hasRole("ADMIN"); | ||||||||||
| //auth.requestMatchers("/cases/add").hasRole("ADMIN"); | ||||||||||
| //auth.requestMatchers("/cases").hasRole("ADMIN"); | ||||||||||
|
Comment on lines
+29
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify whether /cases endpoints have compensating method-level authorization.
rg -nP --type=java -C3 '@(GetMapping|PostMapping|RequestMapping)\(([^)]*"/cases[^"]*")'
rg -nP --type=java -C2 '@PreAuthorize|@Secured|@RolesAllowed'Repository: ithsjava25/project-backend-DurTre Length of output: 2154 🏁 Script executed: cat -n src/main/java/org/example/crimearchive/controllers/HomeController.java | sed -n '53,80p'Repository: ithsjava25/project-backend-DurTre Length of output: 1393 🏁 Script executed: cat -n src/main/java/org/example/crimearchive/config/SecurityConfiguration.java | sed -n '20,40p'Repository: ithsjava25/project-backend-DurTre Length of output: 1304 🏁 Script executed: cat -n src/main/java/org/example/crimearchive/cases/CaseService.javaRepository: ithsjava25/project-backend-DurTre Length of output: 3036 Reinstate explicit authorization for The The 🔧 Suggested fix- //auth.requestMatchers("/cases/add").hasRole("ADMIN");
- //auth.requestMatchers("/cases").hasRole("ADMIN");
+ auth.requestMatchers("/cases/add").hasRole("ADMIN");
+ auth.requestMatchers("/cases").hasRole("ADMIN");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| auth.requestMatchers("/private").hasRole("ADMIN"); | ||||||||||
| auth.requestMatchers("/userpage").hasRole("USER"); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,16 @@ | ||||||||||||||
| package org.example.crimearchive.permissions; | ||||||||||||||
|
|
||||||||||||||
| import org.aopalliance.intercept.MethodInvocation; | ||||||||||||||
| import org.jspecify.annotations.Nullable; | ||||||||||||||
| import org.springframework.security.authorization.AuthorizationResult; | ||||||||||||||
| import org.springframework.security.authorization.method.MethodAuthorizationDeniedHandler; | ||||||||||||||
| import org.springframework.stereotype.Component; | ||||||||||||||
|
|
||||||||||||||
| @Component | ||||||||||||||
| public class NullAuthzDeniedHandler implements MethodAuthorizationDeniedHandler { | ||||||||||||||
| @Override | ||||||||||||||
| public @Nullable Object handleDeniedInvocation(MethodInvocation methodInvocation, AuthorizationResult authorizationResult) { | ||||||||||||||
| // when authz fails, return null | ||||||||||||||
| return null; | ||||||||||||||
|
Comment on lines
+12
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: fd -t f "NullAuthzDeniedHandler.java"Repository: ithsjava25/project-backend-DurTre Length of output: 155 🏁 Script executed: fd -t f "CaseService.java"Repository: ithsjava25/project-backend-DurTre Length of output: 138 🏁 Script executed: cat -n src/main/java/org/example/crimearchive/permissions/NullAuthzDeniedHandler.javaRepository: ithsjava25/project-backend-DurTre Length of output: 846 🏁 Script executed: cat -n src/main/java/org/example/crimearchive/cases/CaseService.java | head -50Repository: ithsjava25/project-backend-DurTre Length of output: 2412 🏁 Script executed: rg "NullAuthzDeniedHandler" --type javaRepository: ithsjava25/project-backend-DurTre Length of output: 505 🏁 Script executed: rg "@HandleAuthorizationDenied" --type javaRepository: ithsjava25/project-backend-DurTre Length of output: 214 🏁 Script executed: rg "AccessDeniedException" --type javaRepository: ithsjava25/project-backend-DurTre Length of output: 59 🏁 Script executed: rg "MethodAuthorizationDeniedHandler" --type javaRepository: ithsjava25/project-backend-DurTre Length of output: 407 Denied authorization is being silently swallowed on a write operation. The Throw +import org.springframework.security.access.AccessDeniedException;
@@
`@Override`
public `@Nullable` Object handleDeniedInvocation(MethodInvocation methodInvocation, AuthorizationResult authorizationResult) {
- // when authz fails, return null
- return null;
+ throw new AccessDeniedException("Access denied");
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| package org.example.crimearchive.reports; | ||
|
|
||
| import org.example.crimearchive.cases.Cases; | ||
| import org.springframework.data.repository.ListCrudRepository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public interface ReportRepository extends ListCrudRepository<Report, UUID> { | ||
|
|
@@ -14,6 +16,8 @@ public interface ReportRepository extends ListCrudRepository<Report, UUID> { | |
|
|
||
| long count(); | ||
|
|
||
| // List<Report> findAllByCaseNumberIn(List<String> permittedCaseNumbers); | ||
| List<Report> findAllByCaseEntity(Cases caseEntity); | ||
|
|
||
| Report getReportByCaseEntity(Cases caseEntity); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify all usages and relationship cardinality before refactor.
rg -nP --type=java -C3 '\bgetReportByCaseEntity\s*\('
rg -nP --type=java -C3 '@OneToMany\(mappedBy\s*=\s*"caseEntity"\)|Set<Report>\s+\w+'Repository: ithsjava25/project-backend-DurTre Length of output: 2788
The method returns a single Use 🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,17 +23,18 @@ public AccountInitilizer(UserRepository repo, CaseService caseService, PasswordE | |
| @Override | ||
| public void run(String... args) throws Exception { | ||
| if(userRepository.count() == 0){ | ||
| userRepository.save(createAccount("admin", "password", List.of("user", "admin"))); | ||
| userRepository.save(createAccount("demouser", "password", List.of("user"))); | ||
| userRepository.save(createAccount("officer", "password", List.of("user"))); | ||
| userRepository.save(createAccount("admin", "password", List.of("user", "admin"), "Lars Åkesson", "Polischef", "Västra Götaland")); | ||
| userRepository.save(createAccount("demouser", "password", List.of("user"), "Nils Jonsson", "Polis", "Skåne")); | ||
| userRepository.save(createAccount("officer", "password", List.of("user"), "Jimmy Johansson", "Polis", "Lappland")); | ||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid seeding predictable default credentials in runtime startup. Line 26–28 create known usernames with the same weak password ( 🔧 Suggested hardening-@Component
+@Component
+@org.springframework.context.annotation.Profile("dev")
public class AccountInitilizer implements CommandLineRunner {🤖 Prompt for AI Agents |
||
|
|
||
| caseService.addAccountToCase(1L, "K-2026-000001"); | ||
| caseService.addAccountToCase(1L, "K-2026-000002"); | ||
| caseService.addAccountToCase(1L, "K-2026-000003"); | ||
| } | ||
| } | ||
| private Account createAccount(String username, String rawPassword, List<String> roles){ | ||
| return new Account(username, passwordEncoder.encode(rawPassword), roles); | ||
|
|
||
| private Account createAccount(String username, String rawPassword, List<String> roles, String fullname, String profession, String department) { | ||
| return new Account(username, passwordEncoder.encode(rawPassword), roles, fullname, profession, department); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ithsjava25/project-backend-DurTre
Length of output: 958
🏁 Script executed:
Repository: ithsjava25/project-backend-DurTre
Length of output: 1806
🏁 Script executed:
Repository: ithsjava25/project-backend-DurTre
Length of output: 9246
🏁 Script executed:
# Check the current CaseService implementation cat -n src/main/java/org/example/crimearchive/cases/CaseService.javaRepository: ithsjava25/project-backend-DurTre
Length of output: 3036
🏁 Script executed:
Repository: ithsjava25/project-backend-DurTre
Length of output: 1605
getReportsshould return a collection instead of a singleReport.The domain model defines a one-to-many relationship between Cases and Reports. Using
getReportByCaseEntity()returns only a single report and will cause silent data loss when a case has multiple reports. The appropriate repository methodfindAllByCaseEntity()already exists.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents