Sign in

Learn, try and Learn

According to Wikipedia, security is freedom from, or resilience against, the potential harm caused by others. I think this line is self-sufficient to tell us why we need to secure our app. According to an article in CyberCrime Magazine, the cybersecurity market has grown 35 times in a span of 13 years, from $3.5 Billion in 2004 to $120 Billion in 2017. It’s even forecasted this shall grow further and reach $170 Billion by 2022. Thus we can feel security is of paramount importance.

  • About spring security
  • Authentication and Authorization
  • How Spring Security functions
  • Follow up post — Implementations
Spring Security Logo
Spring Security Logo
Spring Security

What is Spring Security?


You can find part 1 of this article here — Spring Security: DB Integration: Part 1

If you are a starter to Spring Security then I would suggest starting from here — Spring Security: The Begining

A quick recap —

  1. … have added all necessary dependencies to our application.
  2. … have added configs to connect with a database server.
  3. … introduced a password encoder.
  4. … included authentication and authorizationlogic.
  5. … included a custom user details service.
Spring Security Logo
Spring Security Logo

Let’s see how to build this via code —

Step — 8: Creating entity classes to store user details.

We will be creating two entity classes — Authentication and Authority. Currently, I have assumed that Authentication and Authority have 1 to Many mapping between eachother.

If you are a starter to Spring Security I would suggest you start from Spring Security: The Begining.

This article is divided into 2 parts. The first part will tell you about the Spring security setup, while the next part will focus on hands-on.

After reading these articles, you will understand —

  1. … how user data is processed and stored in the Database.
  2. … how do we encrypt the passwords before storing them.
  3. … various classes and methods we will be using and why we use them?
Spring Security Logo
Spring Security Logo
Spring Security

Let’s go —

Step — 1: Add the following dependencies to the pom file.

I would be integrating my Spring Boot app with the Postgres database.


… Continuing from this

  1. … be able to create a basic secured app.
  2. … understand the basics of the various methods and classes used.
  3. … understand why not to use this example in production.

Let’s try to go step by step and build a secured app —

Step 1: Add spring security starter dependency to pom.xml and run the web application —

Spring security starter dependency

Step 2: Post step 1, run the server and try to hit any endpoint. I bet you will see the following message —

Sabyasachi Mohanty

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store