Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Full Stack Development with Spring Boot 2.0 and React

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

Product type Book
Published in Jun 2018
Publisher Packt
ISBN-13 9781789138085
Pages 302 pages
Edition 1st Edition
Languages
Author (1):
Juha Hinkula Juha Hinkula
Profile icon Juha Hinkula

Table of Contents (24) Chapters

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
1. Setting Up the Environment and Tools – Backend 2. Using JPA to Create and Access a Database 3. Creating a RESTful Web Service with Spring Boot 4. Securing and Testing Your Backend 5. Setting Up the Environment and Tools – Frontend 6. Getting Started with React 7. Consuming the REST API with React 8. Useful Third-Party Components for React 9. Setting Up the Frontend for Our Spring Boot RESTful Web Service 10. Adding CRUD Functionalities 11. Styling the Frontend with React Material-UI 12. Testing Your Frontend 13. Securing Your Application 14. Deploying Your Application 15. Best Practices 1. Assessments 2. Other Books You May Enjoy Index

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 2018 Publisher: Packt ISBN-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.
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 $15.99/month. Cancel anytime}