How to enable spring basic authentication only on a specific profile?

Viewed 958

I'm using spring-boot-security for basic authentication on my @RestController endpoints, as follows:

pom.xml:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

application.properties:

security.user.name=user
security.user.password=pass

Question: how can I disable the basic auth in development, and only enable it if a specific profile is active using startup parameter -Dspring.profiles.active=production.

I would like to move the properties above into application-production.properties. And in dev there should not be any auth on the endpoints.

1 Answers
Related