Using the HTTP client

To see the output, open your third-party HTTP client tools. Here, we're using Insomnia. 

After you run the project, open Insomnia.

Please follow these steps to test the project:

  1. Create a New Request with a name.
  2. In the GET input box, put the http://localhost:8080/user URL. Here, localhost:8080 is the root URL and as we use @RequestMapping(path = ["/user"], method = [RequestMethod.GET]) in the controller class, the project will work under the http://localhost:8080/user path.
  3. If you hit the Send button, you'll see an HTTP Status 401 - Bad credentials error, as shown in the following screenshot:

Although you're using the basic authentication, you have to input a Username and Password to complete this request. You need to click on the Auth (second tab) and select Basic auth; you can enter the Username and Password there. If you input a random username and password, you'll also get the same error. 

After entering the correct Username and Password, you'll get the list of the users in JSON format as output, as shown in the following screenshot:

You can also test in the browser. There, you'll be asked to input the Username and Password

You can also use the browser to see the REST API:

 

After inserting the username and password, we can see the user list:

You've created a very simple project using Spring Security basic authentication. We hope that from now on you can write your own auth-based project with the help of Spring Security. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.163.250