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) {
|
||||
String path = session.getUri().getPath();
|
||||
String path = session.getUri().getPath(); // /ws/puja/2/3
|
||||
String[] segments = path.split("/");
|
||||
|
||||
// Para /ws/remate1/lote1 los segmentos son: ["", "ws", "remate1", "lote1"]
|
||||
if (segments.length >= 4) {
|
||||
String remate = segments[2]; // índice 2 = remate1
|
||||
String lote = segments[3]; // índice 3 = lote1
|
||||
// segments: ["", "ws", "puja", "2", "3"]
|
||||
if (segments.length >= 5) {
|
||||
String remate = segments[3]; // índice 3 = 2
|
||||
String lote = segments[4]; // índice 4 = 3
|
||||
return generarRoomKey(remate, lote);
|
||||
}
|
||||
|
||||
return "default-default";
|
||||
}
|
||||
|
||||
|
||||
private String generarRoomKey(String remate, String lote) {
|
||||
return remate + "-" + lote;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
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.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||
@@ -32,32 +33,24 @@ public class SecurityConfig {
|
||||
return authConfig.getAuthenticationManager();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||
return (web) -> web.ignoring().requestMatchers("/ws/**");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
|
||||
http
|
||||
.securityMatcher("/**")
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/ws/**").permitAll() // WebSocket
|
||||
.requestMatchers("/auth/**").permitAll()
|
||||
.requestMatchers("/favicon.ico", "/error", "/static/**","/contador/**", "/api/**").permitAll()
|
||||
.requestMatchers("/ws/**").permitAll() // permitir WS sin auth
|
||||
.requestMatchers("/admin/**").hasAnyAuthority("SUPER_USUARIO","ADMIN")
|
||||
.requestMatchers("/favicon.ico", "/error", "/static/**", "/contador/**", "/api/**").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.httpBasic(httpBasic -> httpBasic
|
||||
.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());
|
||||
})
|
||||
);
|
||||
.httpBasic(Customizer.withDefaults());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
|
||||
|
||||
@Override
|
||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||
registry.addHandler(webSocketHandler, "/ws/{remate}/{lote}")
|
||||
registry.addHandler(webSocketHandler, "/ws/puja/{remate}/{lote}")
|
||||
.setAllowedOrigins("*");
|
||||
registry.addHandler(eventoWebSocketHandler, "/ws/eventos/{remate}")
|
||||
.setAllowedOrigins("*");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.fercoganbackend.controller;
|
||||
|
||||
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
||||
import com.example.fercoganbackend.dto.CorregirRequest;
|
||||
import com.example.fercoganbackend.service.ContadorService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -44,4 +45,21 @@ public class ContadorController {
|
||||
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(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; }
|
||||
}
|
||||
Reference in New Issue
Block a user