TD-3: Player Test Data and CSRF Fix
This commit is contained in:
parent
d2613576ee
commit
89aa262830
4 changed files with 36 additions and 2 deletions
|
@ -2,10 +2,10 @@ package de.towerdefence.server.auth;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.Customizer;
|
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.core.session.SessionRegistry;
|
import org.springframework.security.core.session.SessionRegistry;
|
||||||
import org.springframework.security.core.session.SessionRegistryImpl;
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
@ -45,7 +45,7 @@ public class AuthConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
return http
|
return http
|
||||||
.csrf(Customizer.withDefaults())
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/api/" + API_VERSION + "/admin/**")
|
.requestMatchers("/api/" + API_VERSION + "/admin/**")
|
||||||
.authenticated()
|
.authenticated()
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class Player {
|
||||||
public static final int PASSWORD_HASH_BYTE_LENGTH = 64;
|
public static final int PASSWORD_HASH_BYTE_LENGTH = 64;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package de.towerdefence.server.player;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Configuration
|
||||||
|
@Profile("dev")
|
||||||
|
public class PlayerTestData {
|
||||||
|
@Autowired
|
||||||
|
private PlayerRepository playerRepository;
|
||||||
|
@Autowired
|
||||||
|
private PlayerService playerService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void loadFixtures() throws NoSuchAlgorithmException {
|
||||||
|
Player player1 = new Player();
|
||||||
|
player1.setUsername("Player1");
|
||||||
|
playerService.setPassword(player1, "1234");
|
||||||
|
this.playerRepository.save(player1);
|
||||||
|
|
||||||
|
Player player2 = new Player();
|
||||||
|
player2.setUsername("Player2");
|
||||||
|
playerService.setPassword(player2, "1234");
|
||||||
|
this.playerRepository.save(player2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
# General
|
# General
|
||||||
|
spring.profiles.active=dev
|
||||||
spring.application.name=Tower Defence Server
|
spring.application.name=Tower Defence Server
|
||||||
server.port=8080
|
server.port=8080
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue