Skip to content

Commit d09898f

Browse files
committed
add csrf code
1 parent 24d7f04 commit d09898f

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@
4747
<groupId>jakarta.ws.rs</groupId>
4848
<artifactId>jakarta.ws.rs-api</artifactId>
4949
</dependency>
50+
51+
<dependency>
52+
<groupId>org.springframework</groupId>
53+
<artifactId>spring-webmvc</artifactId>
54+
<version>5.3.9</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.security</groupId>
58+
<artifactId>spring-security-config</artifactId>
59+
<version>5.8.0</version> <!-- Use the latest stable version -->
60+
</dependency>
61+
<dependency>
62+
<groupId>org.springframework.security</groupId>
63+
<artifactId>spring-security-web</artifactId>
64+
<version>5.8.0</version>
65+
</dependency>
66+
5067
<dependency>
5168
<groupId>io.github.pixee</groupId>
5269
<artifactId>java-security-toolkit</artifactId>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.acme.csrf;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.ResponseBody;
5+
6+
import java.util.Optional;
7+
8+
/** The contact controller. */
9+
public abstract class ContactController {
10+
11+
@RequestMapping("/search")
12+
public @ResponseBody
13+
void logout() {
14+
if (currentSession().isPresent()) {
15+
Session session = currentSession().get();
16+
session.logout();
17+
}
18+
}
19+
20+
abstract Optional<Session> currentSession();
21+
22+
/** The session interface. */
23+
interface Session {
24+
/** Logs out the session. */
25+
void logout();
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.acme.csrf;
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.web.SecurityFilterChain;
7+
8+
@Configuration
9+
public class SecurityConfiguration {
10+
11+
@Bean
12+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
13+
http.csrf().disable();
14+
return http.build();
15+
}
16+
}

0 commit comments

Comments
 (0)