Update subscribe endpoint in CommandsToServerController to use X-Altitude-Token header instead of AuthenticationPrincipal; fix invalid token handling; add return in ServerMessageService test message logic.

This commit is contained in:
akastijn 2026-08-02 17:25:50 +02:00
parent 9757ce2ffa
commit 8849612138
2 changed files with 4 additions and 6 deletions

View File

@ -9,10 +9,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.token.Token; import org.springframework.security.core.token.Token;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@ -27,7 +24,7 @@ public class CommandsToServerController {
private String validToken; private String validToken;
@GetMapping(path = "/subscribe/{server}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) @GetMapping(path = "/subscribe/{server}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribe(@AuthenticationPrincipal Token token, public SseEmitter subscribe(@RequestHeader(value = "X-Altitude-Token") String token,
HttpServletResponse response, @PathVariable String server) { HttpServletResponse response, @PathVariable String server) {
if (validToken == null || validToken.equals("invalid-token")) { if (validToken == null || validToken.equals("invalid-token")) {
log.error("Invalid token in config"); log.error("Invalid token in config");
@ -37,7 +34,7 @@ public class CommandsToServerController {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED); throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
} }
if (!token.getKey().equals(validToken)) { if (!token.equals(validToken)) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN); throw new ResponseStatusException(HttpStatus.FORBIDDEN);
} }

View File

@ -49,6 +49,7 @@ public class ServerMessageService {
.message("This is a test <red>a cool test</red>").build(); .message("This is a test <red>a cool test</red>").build();
if (!sendMessage("alpha", "web_chat", toJson(chatFromWeb))) { if (!sendMessage("alpha", "web_chat", toJson(chatFromWeb))) {
log.warn("Failed to send test message"); log.warn("Failed to send test message");
return;
} }
log.info("Sent test message"); log.info("Sent test message");
} }