6 Hands-on: A small secured web application

 

This chapter covers

  • Applying authentication in a hands-on example

  • Defining the user with the UserDetails interface

  • Defining a custom UserDetailsService

  • Using a provided implementation of PasswordEncoder

  • Defining your authentication logic by implementing an AuthenticationProvider

  • Setting the form-login authentication method

We’ve come a long way in these first chapters and have already discussed plenty of details about authentication. But we have applied each of these new details individually. It is time to put together what we learned in a more complex project. This hands-on example helps you to have a better overview of how all the components we discussed so far work together in a real application.

6.1 Project requirements and setup

In this section, we implement a small web application where the user, after successful authentication, can see a list of products on the main page. You can find the complete implementation with the provided projects in ssia-ch6-ex1.

For our project, a database stores the products and users for this application. The passwords for each user are hashed with either bcrypt or scrypt. I chose two hashing algorithms to give us a reason to customize the authentication logic in the example. A column in the users table stores the encryption type. A third table stores the users’ authorities.

6.2 Implementing user management

6.3 Implementing custom authentication logic

6.4 Implementing the main page

6.5 Running and testing the application

Summary

sitemap