ajuste de pujas
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -107,19 +107,19 @@ public class ContadorWebSocketHandler extends TextWebSocketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String extraerRoomKey(WebSocketSession session) {
|
private String extraerRoomKey(WebSocketSession session) {
|
||||||
String path = session.getUri().getPath();
|
String path = session.getUri().getPath(); // /ws/puja/2/3
|
||||||
String[] segments = path.split("/");
|
String[] segments = path.split("/");
|
||||||
|
|
||||||
// Para /ws/remate1/lote1 los segmentos son: ["", "ws", "remate1", "lote1"]
|
// segments: ["", "ws", "puja", "2", "3"]
|
||||||
if (segments.length >= 4) {
|
if (segments.length >= 5) {
|
||||||
String remate = segments[2]; // índice 2 = remate1
|
String remate = segments[3]; // índice 3 = 2
|
||||||
String lote = segments[3]; // índice 3 = lote1
|
String lote = segments[4]; // índice 4 = 3
|
||||||
return generarRoomKey(remate, lote);
|
return generarRoomKey(remate, lote);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "default-default";
|
return "default-default";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String generarRoomKey(String remate, String lote) {
|
private String generarRoomKey(String remate, String lote) {
|
||||||
return remate + "-" + lote;
|
return remate + "-" + lote;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
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.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.Customizer;
|
||||||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||||
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.WebSecurityCustomizer;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
@@ -32,32 +33,24 @@ public class SecurityConfig {
|
|||||||
return authConfig.getAuthenticationManager();
|
return authConfig.getAuthenticationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
|
||||||
return (web) -> web.ignoring().requestMatchers("/ws/**");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
http
|
http
|
||||||
|
.securityMatcher("/**")
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
.requestMatchers("/ws/**").permitAll() // WebSocket
|
||||||
.requestMatchers("/auth/**").permitAll()
|
.requestMatchers("/auth/**").permitAll()
|
||||||
.requestMatchers("/favicon.ico", "/error", "/static/**","/contador/**", "/api/**").permitAll()
|
.requestMatchers("/favicon.ico", "/error", "/static/**", "/contador/**", "/api/**").permitAll()
|
||||||
.requestMatchers("/ws/**").permitAll() // permitir WS sin auth
|
|
||||||
.requestMatchers("/admin/**").hasAnyAuthority("SUPER_USUARIO","ADMIN")
|
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
.httpBasic(httpBasic -> httpBasic
|
.httpBasic(Customizer.withDefaults());
|
||||||
.authenticationEntryPoint((request, response, authException) -> {
|
|
||||||
// Log del fallo de autenticación
|
|
||||||
System.out.println("Fallo de autenticación: " + authException.getMessage());
|
|
||||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(webSocketHandler, "/ws/{remate}/{lote}")
|
registry.addHandler(webSocketHandler, "/ws/puja/{remate}/{lote}")
|
||||||
.setAllowedOrigins("*");
|
.setAllowedOrigins("*");
|
||||||
registry.addHandler(eventoWebSocketHandler, "/ws/eventos/{remate}")
|
registry.addHandler(eventoWebSocketHandler, "/ws/eventos/{remate}")
|
||||||
.setAllowedOrigins("*");
|
.setAllowedOrigins("*");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.fercoganbackend.controller;
|
package com.example.fercoganbackend.controller;
|
||||||
|
|
||||||
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
||||||
|
import com.example.fercoganbackend.dto.CorregirRequest;
|
||||||
import com.example.fercoganbackend.service.ContadorService;
|
import com.example.fercoganbackend.service.ContadorService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -44,4 +45,21 @@ public class ContadorController {
|
|||||||
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(valor));
|
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(valor));
|
||||||
return valor;
|
return valor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/corregir/{remate}/{lote}")
|
||||||
|
public int corregirValor(
|
||||||
|
@PathVariable String remate,
|
||||||
|
@PathVariable String lote,
|
||||||
|
@RequestBody CorregirRequest request) {
|
||||||
|
|
||||||
|
String roomKey = remate + "-" + lote;
|
||||||
|
int nuevoValor = request.getNuevoValor();
|
||||||
|
|
||||||
|
contadorService.setContador(roomKey, nuevoValor);
|
||||||
|
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(nuevoValor));
|
||||||
|
|
||||||
|
return nuevoValor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.example.fercoganbackend.dto;
|
||||||
|
|
||||||
|
public class CorregirRequest {
|
||||||
|
private int nuevoValor;
|
||||||
|
|
||||||
|
public int getNuevoValor() { return nuevoValor; }
|
||||||
|
public void setNuevoValor(int nuevoValor) { this.nuevoValor = nuevoValor; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
spring.application.name=fercoganbackend
|
spring.application.name=fercoganbackend
|
||||||
spring.profiles.active=prod
|
spring.profiles.active=dev
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
|||||||
Reference in New Issue
Block a user