Skip to content

Commit 77b0cf8

Browse files
authored
[BAEL-9165] by sgrverma23: Guide to disable Spring Security (#18351)
* BAEL-9165:sgrverma23- Adding spring-disable-security inside parent spring-security-module * BAEL-9165:sgrverma23- added spring-security-common-security-configuration inside spring-disable-security module * BAEL-9165:sgrverma23- added spring-security-noauth-cnofig inside spring-disable-security module * BAEL-9165:sgrverma23- added spring-security--noauth-nodependencies inside spring-disable-security module * BAEL-9165:sgrverma23- added spring-security-noauth-profile inside spring-disable-security module * BAEL-9165:sgrverma23- refactored pom.xml and readme file
1 parent 6eee205 commit 77b0cf8

File tree

31 files changed

+540
-0
lines changed

31 files changed

+540
-0
lines changed

spring-security-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<module>spring-security-pkce-spa</module>
6060
<module>spring-security-compromised-password</module>
6161
<module>spring-security-authorization</module>
62+
<module>spring-disable-security</module>
6263
<module>spring-security-dynamic-registration</module>
6364
<module>spring-security-ott</module>
6465
<module>spring-security-passkey</module>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Relevant Articles
2+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>spring-disable-security</artifactId>
5+
<name>spring-disable-security</name>
6+
<packaging>pom</packaging>
7+
8+
<parent>
9+
<groupId>com.baeldung</groupId>
10+
<artifactId>parent-boot-3</artifactId>
11+
<version>0.0.1-SNAPSHOT</version>
12+
<relativePath>../../parent-boot-3</relativePath>
13+
</parent>
14+
15+
<modules>
16+
<module>spring-security-noauth-profile</module>
17+
<module>spring-security-noauth-config</module>
18+
<module>spring-security-noauth-nodependencies</module>
19+
<module>spring-security-common-security-configuration</module>
20+
</modules>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-web</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-compiler-plugin</artifactId>
39+
<version>${maven-compiler-plugin.version}</version>
40+
<configuration>
41+
<parameters>true</parameters>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
<properties>
48+
<spring-boot.version>3.3.1</spring-boot.version>
49+
<logback.version>1.5.6</logback.version>
50+
<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
51+
</properties>
52+
53+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-security-common-security-configuration</artifactId>
7+
<version>1.0.0</version>
8+
<name>spring-security-common-security-configuration</name>
9+
<description>Disable Spring Security</description>
10+
11+
<parent>
12+
<groupId>com.baeldung</groupId>
13+
<artifactId>spring-disable-security</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-security</artifactId>
21+
</dependency>
22+
</dependencies>
23+
24+
<build>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-maven-plugin</artifactId>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
33+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class DisableSpringSecurityApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(DisableSpringSecurityApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.controller;
2+
3+
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
@RequestMapping("/api")
14+
public class MessageController {
15+
@GetMapping("/endpoint")
16+
public ResponseEntity<String> publicEndpoint() {
17+
return ResponseEntity.ok("This is a public endpoint.");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.security;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7+
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
8+
import org.springframework.security.web.SecurityFilterChain;
9+
10+
@Configuration
11+
@EnableWebSecurity
12+
public class SecurityConfiguration {
13+
@Bean
14+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
15+
16+
http
17+
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
18+
.csrf(AbstractHttpConfigurer::disable);
19+
return http.build();
20+
}
21+
}

spring-security-modules/spring-disable-security/spring-security-common-security-configuration/src/main/resources/application.properties

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.junit.jupiter.api.Test;
2+
import org.springframework.beans.factory.annotation.Autowired;
3+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
import org.springframework.test.web.servlet.MockMvc;
6+
import com.baeldung.DisableSpringSecurityApplication;
7+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
8+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
9+
10+
@SpringBootTest(classes = DisableSpringSecurityApplication.class)
11+
@AutoConfigureMockMvc
12+
public class CommonSecurityConfigTest {
13+
14+
@Autowired
15+
private MockMvc mockMvc;
16+
17+
@Test
18+
public void whenAccessingAnyEndpoint_thenReturnOk() throws Exception {
19+
mockMvc.perform(get("/api/endpoint"))
20+
.andExpect(status().isOk());
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung;
2+
3+
4+
import com.baeldung.DisableSpringSecurityApplication;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.test.annotation.DirtiesContext;
9+
import org.springframework.test.context.junit4.SpringRunner;
10+
11+
@RunWith(SpringRunner.class)
12+
@SpringBootTest(classes = DisableSpringSecurityApplication.class)
13+
public class DisableSpringSecurityApplicationTest {
14+
15+
@Test
16+
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
17+
}
18+
}
19+

0 commit comments

Comments
 (0)