Reader small image

You're reading from  Hands-On Full Stack Development with Spring Boot 2.0 and React

Product typeBook
Published inJun 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781789138085
Edition1st Edition
Languages
Right arrow
Author (1)
Juha Hinkula
Juha Hinkula
author image
Juha Hinkula

Juha Hinkula is a software development lecturer at Haaga-Helia University of Applied Sciences in Finland. He received an MSc degree in Computer Science from the University of Helsinki and he has over 17 years of industry experience in software development. Over the past few years, he has focused on modern full stack development. He is also a passionate mobile developer with Android-native technology, and also uses React Native.
Read more about Juha Hinkula

Right arrow

Chapter 4. Securing and Testing Your Backend

This chapter explains how to secure and test your Spring Boot backend. We will use the database application that we created in the previous chapter as a starting point.

In this chapter, we will look into the following:

  • How to secure your Spring Boot backend with Spring Boot
  • How to secure your Spring Boot backend with JWT
  • How to test your backend

Technical requirements


The Spring Boot application that was created in previous chapters is necessary.

Spring Security

Spring Security (https://spring.io/projects/spring-security) provides security services for Java-based web applications. The Spring Security project started in 2003 and was previously named The Acegi Security System for Spring.

By default, Spring Security enables the following features:

  • An AuthenticationManager bean with an in-memory single user. The username is user and the password is printed to the console output.
  • Ignored paths for common static resource locations, such as /css, /images, and more.
  • HTTP basic security for all other endpoints.
  • Security events published to Spring ApplicationEventPublisher.
  • Common low-level features are on by default (HSTS, XSS, CSRF, and so forth).

You can include Spring Security in your application by adding the following dependency to the pom.xml file:

 <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId...

Summary


In this chapter, we focused on securing and testing the Spring Boot backend. Securing was first done with Spring Security. The frontend will be developed with React in upcoming chapters; therefore, we implemented JWT authentication, which is a lightweight authentication method suitable for our needs. We also covered the basics of testing a Spring Boot application. We used JUnit for unit testing and implemented test cases for JPA and RESTful web service authentication. In the next chapter, we will setup the environment and tools for the frontend development.

Questions


  1. What is Spring Security?
  2. How can you secure your backend with Spring Boot?
  3. What is JWT?
  4. How can you secure your backend with JWT?
  5. How can you create unit tests with Spring Boot?
  6. How can you run and check the results of unit tests?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Full Stack Development with Spring Boot 2.0 and React
Published in: Jun 2018Publisher: PacktISBN-13: 9781789138085
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Juha Hinkula

Juha Hinkula is a software development lecturer at Haaga-Helia University of Applied Sciences in Finland. He received an MSc degree in Computer Science from the University of Helsinki and he has over 17 years of industry experience in software development. Over the past few years, he has focused on modern full stack development. He is also a passionate mobile developer with Android-native technology, and also uses React Native.
Read more about Juha Hinkula