Harden auth: separate access/refresh JWT, atomic refresh rotation, admin checks
- Refresh JWT carried no role but was accepted by JwtAuthenticationFilter and the STOMP CONNECT as an access token; tokens now carry a typ claim and the filters accept only access tokens (legacy tokens are told apart by role). - Refresh rotation uses GETDEL, so one refresh token cannot be spent twice; refresh tokens are no longer written to logs. - isCurrentUserAdmin and file deletion compared authorities with "ADMIN" instead of "ROLE_ADMIN", so admins were never recognised. - getCurrentUser answers 401 for anonymous requests; profile update keeps the login when the field is not sent; registration rejects empty login/password. - GlobalExceptionHandler turned AccessDenied, BadCredentials, EntityNotFound, Spring MVC 4xx errors and upload limits into 500. - Presigned URL TTL is capped at 7 days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ public class FileStorageController {
|
||||
* Вместе с кэшем ссылки (12ч) укладывается в её срок жизни (24ч).
|
||||
*/
|
||||
private static final Duration REDIRECT_CACHE_MAX_AGE = Duration.ofHours(6);
|
||||
private static final long MAX_PRESIGNED_TTL_HOURS = 7 * 24;
|
||||
|
||||
private final FileStorageService fileStorageService;
|
||||
|
||||
@@ -68,7 +69,8 @@ public class FileStorageController {
|
||||
@GetMapping("/url/{*objectName}")
|
||||
public ResponseEntity<Map<String, String>> getPresignedUrl(@PathVariable String objectName, @RequestParam(value = "ttlHours", required = false, defaultValue = "24") long ttlHours) {
|
||||
String key = objectName.startsWith("/") ? objectName.substring(1) : objectName;
|
||||
Duration ttl = ttlHours > 0 ? Duration.ofHours(ttlHours) : Duration.ofHours(24);
|
||||
// SigV4 не подписывает ссылки дольше 7 дней: больший ttlHours ронял presigner с 500
|
||||
Duration ttl = ttlHours > 0 ? Duration.ofHours(Math.min(ttlHours, MAX_PRESIGNED_TTL_HOURS)) : Duration.ofHours(24);
|
||||
String url = fileStorageService.generatePresignedDownloadUrl(key, ttl);
|
||||
return ResponseEntity.ok(Map.of("url", url));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user