Can you explain the difference between authentication and authorization in Spring Security?

Authentication and Authorization are two fundamental security concepts in Spring Security. Authentication verifies the identity of a user, while Authorization determines what actions or resources that authenticated user is allowed to access.

Key Points

Example

Consider an internet banking application

Step 1

The user enters a username and password.

Spring Security verifies the credentials and confirms the user's identity.

This process is Authentication.

Step 2

After successful login, Spring checks whether the user has permission to perform actions such as:

This process is Authorization.

Comparison

Authentication

Authorization

Authentication Example

http
    .formLogin();

This enables user authentication.

Authorization Example

http

.authorizeHttpRequests(auth -> auth

.requestMatchers("/admin/**")

.hasRole("ADMIN")

.requestMatchers("/user/**")

.hasRole("USER")

.anyRequest()

.authenticated()

);

Here

Real-World Example

Airport Security

Authentication

Authorization

Spring Security Flow

User Request

↓

Authentication

↓

Identity Verified?

↓

Authorization

↓

Permission Check

↓

Access Granted or Denied

Common Authentication Methods

Common Authorization Methods

Interview Tip

A concise interview answer is: Authentication is the process of verifying the identity of a user using credentials such as username and password or tokens. Authorization is the process of determining what resources or operations that authenticated user is permitted to access. In Spring Security, authentication occurs first, followed by authorization based on roles and permissions.

Last updated: 16 July 2026

Previous question: You are creating an endpoint in a Spring Boot application that allows users to upload files. Explain how you would handle the file upload and where you would store the files.

Next question: After a user registers, your Spring Boot application must send a welcome email. How would you send it?

More Spring Boot - Level II interview questions

All Spring Boot - Level II questions