Spring Boot + Swagger 3 (OpenAPI 3) + Security Example(Basic Authentication)
Introduction
In previous tutorial we had implemented Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example. Also previously we had implemented Understand Spring Security Architecture and implement Spring Boot Security Example. In this tutorial we will be implementing Spring Boot Basic Security for the spring boot swagger example. So when using Swagger to access the endpoints, swagger also allows us to configure the spring security user name and password.Spring Boot Swagger- Table of Contents
Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot + Swagger + Profile - Implementing Spring Boot Profile for a Swagger application Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example Spring Boot + Swagger 3 (OpenAPI 3) + Security Example
Video
This tutorial is explained in the below Youtube Video.Lets Begin
We will be modifying the Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example project we had implemented in the previous tutorial.
The final maven project we will be developing is as follows -

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.0.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.javainuse</groupId> <artifactId>boot-swagger-3-fin</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot-swagger-3</name> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- Swagger UI --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.2.32</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>