#Endpoint naming and protecting those routes

3 messages · Page 1 of 1 (latest)

atomic rivet
#

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()
bronze steepleBOT
#

This post has been reserved for your question.

Hey @atomic rivet! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.