Improve subscribe endpoint in CommandsToServerController: add error logging for missing or invalid tokens
This commit is contained in:
parent
8849612138
commit
d3389159b6
|
|
@ -24,17 +24,19 @@ public class CommandsToServerController {
|
|||
private String validToken;
|
||||
|
||||
@GetMapping(path = "/subscribe/{server}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter subscribe(@RequestHeader(value = "X-Altitude-Token") String token,
|
||||
public SseEmitter subscribe(@RequestHeader(value = "X-Altitude-Token", required = false) String token,
|
||||
HttpServletResponse response, @PathVariable String server) {
|
||||
if (validToken == null || validToken.equals("invalid-token")) {
|
||||
log.error("Invalid token in config");
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
if (token == null) {
|
||||
log.error("No token provided when trying to subscribe to {}", server);
|
||||
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
if (!token.equals(validToken)) {
|
||||
log.error("Invalid token provided when trying to subscribe to {}", server);
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user