Search Tutorials


Spring Boot 3 + Security - Disable Authentication| JavaInUse

Spring Boot 3 + Security - Disable Authentication

In previous tutorial we implemented Spring Boot 3 + Security authentication simple example. After adding the spring security dependency we used the browser to access the exposed API. Spring security provided us with a default login page. After successful authentication we could access the exposed API. But suppose we have a scenario where we have added a spring security dependency but do not want the default authentication enabled. For example for this website - javainuse.com I added the spring security dependency as i have various tools like jwt generator. But I did not want default authentication enabled as then user would not be able to view or browse the site.

Video

This tutorial is explained in the below Youtube Video.

Spring Boot 3 Security

Simple Boot3 + Security in depth understanding Simple Boot3 + Security - Disable Authentication Simple Boot3 + Security - Custom Credentials

Implement Security Configuration to disable security configuration

We will be modifying the spring boot project we created in previous tutorial. The maven project will be as follows-
Spring Boot Security Disable authentication
Create a configuration class named SecurityConfig. In this configuration class we will permit all incoming requests without any authentication.
package com.javainuse.boot3security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {

	@Bean
	SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		http.authorizeHttpRequests().anyRequest().permitAll();
		return http.build();
	}
}
This is the only change required. If we now start the spring boot application and go to localhost:8080/hello we will be able to access it without authentication.
Spring Boot Security Hello World

Download Source Code

Download it -
Spring Boot 3 Security - Disable Authentication Example