February 03, 2020

Spring Security-Part 4.3: Form Based Authentication


Form Based Authentication
  • When we do basic authentication, we need to pass 'Authorization' in header (e.g, Authentication:Basic BASE_64_UserName:Password). Though the basic auth is simple and fast, it has one disadvantage that we can't logout.
  • We can user form based authentication, in which user will enter user name and password and can logout whenever required.


To switch from Basic to Form based authentication, we need to update ApplicationSecurityConfig. In the configure() method instead of httpBasic(), we need to use formLogin().

Spring Security-Part 4.2: @PreAuthorize, @PostAuthorize, @Secured, @RoleAllowed, @EnableGlobalMethodSecurity annotations


Annotation Based Roles and Authorities/Permissions

In our previous tutorial we had configured the roles and authorities in ApplicationSecurityConfig (which extends WebSecurityConfigurerAdapter). We can do the same thing by using @PreAuthorize annotation.

Spring Security-Part 4.1: Spring Security

Let's create a new project from Spring Initializr https://start.spring.io/.
  • Project: Maven Project
  • Language: Java
  • Spring Boot: 2.2.4
  • Group: com.example
  • Artifact: spring-security-demo
  • Java Version: 8
  • Dependencies: Spring Web
Generate the project and import it in either Eclipse/STS or IntelliJ.

Spring Security-Part 3 : Spring Security with JPA authentication and MySQL

Example of Spring Security with JPA authentication and MySQL
We will build a Spring boot project with Spring Security that will do database authentication using JPA and connect with MYSQL database.

Let's say we have a mysql database locally with database instance with name 'springsecurity'. This database has a table with a name 'user'. 'roles' has comma separated roles.

#SpringSecurity Part 3 : Spring Security Flow

In the Part 1 of #SpringSecurity tutorial, we learned the difference between Authentication and Authorization. In Part 2, we created a Basic Authentication implementation was explained.

In this section, we will understand Spring Security Flow.

Spring Security Flow

Above diagram show, how Spring Security works internally.

#SpringSecurity Part 2 : Securing Web-services with Spring (Basic, In-Memory and JDBC Authentication)

How can we implement basic authentication in Spring?
For this let us create a Spring Starter Project titled 'BasicAuthentication' from STS, this project has only Spring Web dependency.

#SpringSecurity Part 2 : Creating a simple Spring security project (Basic Authentication)

In the Part 1 of #SpringSecurity tutorial, I explained the difference between Authentication and Authorization. Now let's see how can we implement basic authentication in Spring.

#SpringSecurity Part 1 : Authentication v/s Authorization


Spring Security :  Authentication v/s Authorization

Authentication and Authorization are often used in conjunction with each other in terms of security, especially when it comes to gaining access to the system. 

Authentication means confirming your own identity, while authorization means granting access to the system. We can say, authentication is the process of verifying who you are, while authorization is the process of verifying what you have access to.

January 31, 2020

Part 2: Spring Data JPA Tutorial and Interview Questions

What is JPA?
JPA (Java Persistence API) is the specification of Java that is used to persist data between Java object and RDBMS(relational database).

JPA acts as a bridge between object-oriented domain models and relational database systems. As JPA is just a specification, it doesn't perform any operation by itself. It requires an implementation. Therefore, ORM tools like Hibernate implements JPA specifications for data persistence.

Ullu App launches maiden awards!

Ullu App recently threw a success bash, which was a well-attended affair by the luminaries of the entertainment industry. Vibhu Agarwal, CEO of Ullu App unveiled the trailer of their upcoming web series Peshawar, The Bull Of Dalal Street and Kasak. The event was graced by Ashmit Patel, Shishir Sharma, Ihana Dhillon, Deepika Singh, Ravi Bhatia, Rushad Rana, Amar Upadhyay, Rohit Roy, Rajeev Paul, Aman Verma, Sakshi Pradhan, Pratima Kannan, Sudhanshu Pandey, Ridheema Tiwari, Aadarsh Balakrishna, Vineet Raina and many more.

Part 1: Spring Data JPA Tutorial and Interview Questions

The DAO layer usually consists of a lot of boilerplate code that can be simplified. Spring Data makes it possible to remove the DAO implementations entirely.

JPA (Java Persistent API) is the sun specification for persisting objects in the enterprise application. It is currently used as the replacement for complex entity beans.

We are determined to cater to every individual: Ullu App's CEO Vibhu Agarwal

Ullu App became the talk of the town ever since its launch. The on-demand video streaming platform recently completed its first super successful year. To celebrate the occasion and unveil the trailer of their upcoming web series Peshawar, The Bull Of Dalal Street and Kasak, Ullu App's CEO Vibhu Agarwal had thrown a success bash. The event was graced by eminent  people from the industry few being Ashmit Patel, Amar Upadhyay, Aman Verma,  Deepika Singh, Ihana Dhillon, Pratima Kannan, Rohit Roy, Shishir Sharma, Sudhanshu Pandey, Ravi Bhatia, Pratima Kannan, Rajeev Paul, Aadarsh Balakrishnan, Sakshi Pradhan and many more.

January 28, 2020

#MongoDB Part 6: Interview Questions And Answers

How to create User and add Role in MongoDB?
Creating Admin User
We can create a user administrator in MongoDB by using the createUser method. e.g:

db.createUser(
{
   user: "myadmin",
   pwd: "password@123",
   roles:[{role: "userAdminAnyDatabase", db:"admin"}]
});

January 27, 2020

#MongoDB Part 5: Interview Questions And Answers

What is Mongo shell?
Mongo shell is a JavaScript interface to MongoDB that can be used to query and update data. It is interactive and can also be used to do administrative operations.

What is BSON?
BSON or binary JSON is the binary encoded format of JSON. It extends JSON and provides more data types and fields.

#MongoDB Part 4: Interview Questions And Answers

What is Namespace in MongoDB?
MongoDB stores BSON (Binary Interchange and Structure Object Notation) objects in the collection. The concatenation of the collection name and database name is called a namespace.

#MongoDB Part 3: Interview Questions And Answers

How to query a document in MongoDB using find()?
db.collection.find () is used for retrieval of documents from a MongoDB database. The find command is an in-built function which is used to retrieve the documents in the collection.