I am refactoring my code because I saw that you shouldn't name endpoints with things like
api/v1/builds/all, api/v1/builds/create, api/v1/builds/edit, api/v1/builds/delete and the @GetMapping @PostMapping etc will handle the diffierent cases for you. But when I go change up the security config. I would have to have it like I do below I think, but this causes a problem since now it's saying it authenticate all users on this path as well as permit all.
So how can i restrict these mappings if they are all on the same path with out adding api/v1/builds/all, api/v1/builds/create, api/v1/builds/edit, api/v1/builds/delete
@GetMapping("/")
public ResponseEntity<List<BuildNoStepsDto>> getBuilds() {
return new ResponseEntity<>(buildService.getBuilds(), HttpStatus.OK);
}
@GetMapping("/{username}")
public ResponseEntity<List<BuildDTO>> getBuildsForUser(@PathVariable("username") String username) {
return new ResponseEntity<>(buildService.getBuildsForUser(username), HttpStatus.OK);
}
@GetMapping("/{id}")
public ResponseEntity<BuildDTO> getBuild(@PathVariable("id") long id) {
return new ResponseEntity<>(buildService.getBuildById(id), HttpStatus.OK);
}
@PostMapping("/")
@ResponseStatus(HttpStatus.CREATED)
public void createBuild(@RequestBody BuildDTO buildDTO) {
buildService.createBuild(buildDTO);
}
.authorizeHttpRequests()
.requestMatchers("/api/v1/builds/**", ).authenticated()
.requestMatchers("/api/v1/auth/**", "/api/v1/builds/**").permitAll()