Having a look at basic authentication support in Sprint Boot
- if
spring-boot-starter-securitystarter is in a dependency, then endpoints are secured with username: user, and password logged to console on application startup. - can customise username and password via properties.
spring.security.user.nameandspring.security.user.password WebSecurityConfigurerAdapterextension for custom behaviour, e.g. assigning roles to username/password pairs and authorizing these roles particular endpoints
Note the following requests inserts the username and password for the basic authentication into the URL. Alternatively the header Authorization with the username and password encoded could have been used.
The following 2 requests are equivalent:
>curl -X GET http://admin:password@localhost:8080/admin/stats
>curl -X GET http://localhost:8080/admin/stats -H 'Authorization: Basic dXNlcjpwYXNzd29yZA=='
No authentication. Anybody can hit this endpoint:
>curl http://localhost:8080/about
Basic authentication and authorized to any role:
>curl -X GET http://user:password@localhost:8080/api/add
>curl -X GET http://admin:password@localhost:8080/api/add
Basic authentication and authorized to role ADMIN:
>curl -X GET http://admin:password@localhost:8080/admin/stats
The following is forbidden:
>curl -X GET http://user:password@localhost:8080/admin/stats