'Spring MVC Endpoint: Restrict access to application

I am working on a springboot application that has a MVC endpoint to expose some config details. This endpoint is there for a sole purpose to be called from the JS file in the same application.

@GetMapping("/config")
public Config getConfig() {

    return Config.builder()
            .key("key")
            .secret("secret")
            .build();
}

I want to be able to restrict access to this endpoint so that no external system/user should be able to call it. How can I achieve this?



Solution 1:[1]

you can restrict access to your endpoint using @Preauthorize annotation, for more details :

https://www.baeldung.com/spring-deny-access

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Medamine