Auth SpringBoot User Guide
Last updated
Was this helpful?
Last updated
Was this helpful?
This document lists out the instructions on how to use the in a Spring Boot application.
Step 1:
Step 2:
Step 3:
Add the Auth Adapter module to your project as a maven dependency
Add ComponentScan annotation as shown below to your project. This is to create auth adapter bean.
To restrict access to your endpoints, you need to add the @PreAuthorize annotation. Look at the below example for reference.
Note: Now we support only hasRole and hasAnyRole methods.
To make any kind of HTTP or HTTPS calls to a mosip's micro service that also injected the Auth Adapter, use the standard RestTemplate capabilities as shown below.
Intially autowire the RestTemplate in the class where you are going to make an API call.
Now make the call using the autowired restTemplate as shown in the sample below:
Note: Do not create a new instance of the RestTemplate instead use the autowired one.
There are few more methods available apart from hasAnyRole like hasRole. Look in to the documentation for more details.