##############
Spring Security
###############
-> To implement security for our applications Spring provided 'security' module
-> To use Spring Security in our project 'spring-security-starter' we need to add
in [Link] file
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
-> By default it will secure all the endpoints of our application
Default uname : user
Default Pwd: Will be printed on the console
-> To override default credentials we can configure credentails in
[Link] file
[Link]=admin
[Link]=admin@123
-> Create Rest Controller class with required method
#####################################
Rest Client To access Secured REST API
#######################################
@Service
public class WelcomeService {
private String apiUrl = "[Link]
public void invokeWelcomeApi() {
RestTemplate rt = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
[Link]("admin", "admin@123");
HttpEntity<String> reqEntity = new HttpEntity<>(headers);
ResponseEntity<String> responseEntity = [Link](apiUrl,
[Link], reqEntity, [Link]);
String body = [Link]();
[Link](body);
}
public void invokeWelcome() {
WebClient webClient = [Link]();
String block = [Link]()
.uri(apiUrl)
.headers(headers ->
[Link]("admin", "admin@123"))
.retrieve()
.bodyToMono([Link])
.block();
[Link](block);
}