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:
SlimusMinus
2026-10-20 00:56:38 +03:00
parent a68b89981c
commit 5cd60b6318
11 changed files with 201 additions and 91 deletions

View File

@@ -3,7 +3,6 @@ package com.krylov.refound.service;
import com.krylov.refound.config.MinioProperties;
import com.krylov.refound.dto.DownloadedFile;
import com.krylov.refound.enums.ErrorCode;
import com.krylov.refound.enums.Role;
import com.krylov.refound.exception.ApiException;
import java.io.IOException;
import java.net.URLDecoder;
@@ -269,7 +268,7 @@ public class FileStorageService {
}
boolean isAdmin = authentication.getAuthorities().stream()
.anyMatch(authority -> Role.ADMIN.name().equals(authority.getAuthority()));
.anyMatch(authority -> UserService.ADMIN_AUTHORITY.equals(authority.getAuthority()));
if (isAdmin) {
return;
}