In this article, we will add basic authentication to a previous Spring application we created in this post :
Adding maven dependency
Add the following dependency to the pom.xml :
This will add the following jars to the maven :
Running the @SpringBootApplication
Running your SpringBootApplication class (the one annotated with @SpringBootApplication.. in this example, its SpringBootHelloApplication class) will create a password in the log similar to this :
b.a.s.AuthenticationManagerConfiguration : Using default security password: 97967275-9dd3-450a-9c4a-09f0f8d3df61
The default user id is user
Testing the security
Now if you try to test your app in browser, you should get a prompt for the user/password :
Now trying with the user id “user” and the generated password, you should be able to able to access the spring boot service.
You should the service page that displays the “Hello World” message at this point.
This is not a preferred way of implementing security though. You should implement OAUTH2 with spring boot. We will be including an article on the same shortly.
© 2017, https:. All rights reserved. On republishing this post, you must provide link to original post