Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,39 @@
</properties>

<dependencies>
<!-- MongoDB starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- OAuth2 Client -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

<!-- Web starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- WebSocket starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<!-- Lombok (provided) -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -50,21 +67,11 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Compilador Java configurado para release 17 -->
<!-- Java compiler plugin para versión 17 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -74,7 +81,7 @@
</configuration>
</plugin>

<!-- Plugin de Spring Boot -->
<!-- Spring Boot plugin para empaquetar -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/pintudos/game/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
@Configuration
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf()
.disable() // Necesario para SockJS
.authorizeHttpRequests(authz ->
authz
.requestMatchers(
"/game/**", // SockJS handshake y WebSocket transport
"/ws/**", // Si usas /ws como endpoint de registro STOMP
"/topic/**", // Canal de suscripciones
"/app/**" // Canal de envío desde el cliente
)
.permitAll()
.anyRequest()
.authenticated() // El resto necesita auth
)
.formLogin()
.disable()
.httpBasic()
.disable();
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors()
.and()
.csrf()
.disable()
.authorizeHttpRequests(authz -> authz
// Permite acceso sin autenticación a los endpoints SockJS
.requestMatchers(
"/game", "/game/**", "/game/info/**"
).permitAll()
// Archivos públicos
.requestMatchers(
"/", "/login/", "/error", "/css/", "/js/"
).permitAll()
// Endpoints que requieren autenticación
.requestMatchers(
"/app/**", "/topic/**"
).authenticated()
.anyRequest().authenticated()
)
.oauth2Login();

return http.build();
}
return http.build();
}
}
10 changes: 6 additions & 4 deletions src/main/java/pintudos/game/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public WebMvcConfigurer corsConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("http://localhost:5173", "http://localhost:3000") // Especificar frontend
.allowedMethods("*")
.allowedHeaders("*"); // Habilitar credenciales
.addMapping("/**")
.allowedOrigins("http://localhost:5173", "http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("Set-Cookie", "Authorization")
.allowCredentials(true);
}
};
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Nombre de la aplicación y conexión a Mongo (ya existente)
spring.application.name=game
spring.data.mongodb.uri=mongodb+srv://diego:marzo245@universidad.lavtxfi.mongodb.net/pintudos?retryWrites=true&w=majority

# Configuración de autenticación con Google
spring.security.oauth2.client.registration.google.client-id=186447712086-73urgfm1lll5069lh18ed9venvnsr5an.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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
spring.security.oauth2.client.registration.google.scope=profile,email

spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/auth
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
spring.security.oauth2.client.provider.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo
spring.security.oauth2.client.provider.google.user-name-attribute=sub