Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring_App

Requirements:

Create a guestbook back end application using Spring Boot. The business concepts for the application are users and messages. An user can post a message and you can’t have anonymous messages. You should create a maven project for this application and it should extend spring-boot-starter-parent. Develop de application as a multi module maven project. The layers described below should be placed each on it’s own maven module (database, persistence, etc). Use the project from above as the root maven module.

Database:

Use the H2 in-memory database. It will be created at application start-up and destroyed when you close the application. H2 console should be enabled. For creating the tables needed you should use SQL scripts and Flyway to manage the deployment of the SQL scripts. The user table should have the following columns: Id (primary key and auto generated by the db) User_name Password (should be encrypted with a password encoder, example BCryptPasswordEncoder) The message table should have the following columns: Id (primary key and auto generated by the db) Post_date Message User_id (foreign key to the id column in the user table) Create a default user with user_name=admin, password=admin and create it with Flyway’s BaseJavaMigration Use Lombok

Persistence:

Use JPA with Hibernate Create entities for the user and message tables Create repositories for the entities: They should extend JPARepository Use @Repository The parameters for the data source should come from a properties file (application.properties) You should validate the db user against a blacklist In case the db user is in the blacklist throw an Exception and close the application Write integration tests using @DataJpaTest

Service:

The services will map the entities to DTOs, for each entity you should have a DTO They should provide supporting methods for the web layer Don’t expose the entities to the web layer, only DTOs Use aspects to intercept methods annotated with a custom annotation that you will define The aspect will print the value of an environment variable

Web:

Create 2 controller classes using @RestController and @RequestMapping The user controller should expose endpoints: Save Update Delete Get all users The message controller should expose endpoints: Save Update Delete Get all messages Get all messages for a specific user Get all user names and for each user the number of messages he posted Get the user with the highest number of messages (+ based on an environment variable and a custom header with the value of that environment variable) For one of the controllers write integration tests using @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT), TestRestTemplate and @MockBean for all services. For the other create unit tests using @WebMvcTest and MockMvc.

Security:

All the endpoints should be protected by basic authentication The user and password should be checked against the db for each request The configuration for the security should be done in a separate configuration file (@Configuration @EnableWebSecurity)

Hints:

In order to have the db user blacklist working you should define the data source using @Bean in a @Configuration file The data source should be of the default type: HikariDataSource For the web layer you will use @PostMapping, @RequestBody, @PutMapping, @PathVariable, @DeleteMapping, @GetMapping For the security layer you should use jdbcAuthentication and your class should extend WebSecurityConfigurerAdapter You will override the method configure(AuthenticationManagerBuilder auth) The web layer will call only the service layer The service layer will call only the persistence layer

Bonus task:

Create DAOs that contain the read operations you created for the persistence module. Use JDBC with Spring support. Create custom Service implementations that use the JDBC DAOs for reads and the old repositories for all other operations (create/update/delete) Use Spring and Maven profiles to switch between the different Service implementations Create test that verify the alternate behavior

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages