Search code examples
javapolymerweb-componentvaadin10

How does the login authentication work in Vaadin Bakery App


I am trying to learn vaadin JAVA framework. I am looking at the code of Bakery App. In LoginView.java there is call to setAction('login') that takes care of the successfull authentication. I want to know where in the code this is taking place. I just want to add a new username and password to the exisitng code. How to do that?


Solution

  • The Bakery app uses Spring Security to handle login logic. Spring Security is configured in class SecurityConfiguration. The users are loaded/saved within UserRepository which extends JpaRepository which is part of the Spring Data JPA framework. This repository saves entities inside Bakery app in memory by default which is mentioned in the README.md:

    1. Optionally you might want to avoid the data generator to be run on each single reload, therefore, make H2 database store entities in file-system instead of in memory by adding the following lines to the src/main/resources/application.properties
    spring.datasource.url=jdbc:h2:file:~/bakery-test-data
    spring.jpa.hibernate.ddl-auto=update
    

    The place where those users are created and saved into memory is in DataGenerator Line 77 - 81:

        User baker = createBaker(userRepository, passwordEncoder);
        User barista = createBarista(userRepository, passwordEncoder);
        createAdmin(userRepository, passwordEncoder);
        // A set of products without constrains that can be deleted
        createDeletableUsers(userRepository, passwordEncoder);
    

    This would be the place where you could add additional users.