diff --git a/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java b/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java index e1fff64a..dbf1121a 100644 --- a/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java +++ b/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java @@ -40,8 +40,7 @@ public void changePassword(@Valid @RequestBody ChangePasswordDto request) { changePasswordService.changePassword(request); } - @Operation(summary = "Send email to restore password", - responses = { + @Operation(summary = "Send email to restore password", responses = { @ApiResponse(responseCode = "200", description = SUCCESSFULLY_SEND_REQUEST_RESTORE_PASSWORD, content = @Content), @ApiResponse(responseCode = "400", description = ERR_SENDING_EMAIL, @@ -53,8 +52,7 @@ public void sendRequestToRestorePassword(@RequestParam String email, changePasswordService.sendEmailToRestorePassword(email, clientHost); } - @Operation(summary = "Restore password", - responses = { + @Operation(summary = "Restore password", responses = { @ApiResponse(responseCode = "200", description = SUCCESSFULLY_RESTORED_PASSWORD, content = @Content), @ApiResponse(responseCode = "404", description = EMAIL_TOKEN_NOT_FOUND, @@ -64,4 +62,4 @@ public void sendRequestToRestorePassword(@RequestParam String email, public void restorePassword(@Valid @RequestBody RestorePasswordDto restorePasswordDto) { changePasswordService.restorePassword(restorePasswordDto); } -} +} \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/controller/rest/MessageController.java b/src/main/java/com/chat/yourway/controller/rest/MessageController.java index ecc066bc..9dabf832 100644 --- a/src/main/java/com/chat/yourway/controller/rest/MessageController.java +++ b/src/main/java/com/chat/yourway/controller/rest/MessageController.java @@ -108,8 +108,7 @@ public void reportMessage(@PathVariable UUID id) { messageService.reportMessageById(id); } - @Operation(summary = "Mark a message as read", - responses = { + @Operation(summary = "Mark a message as read", responses = { @ApiResponse(responseCode = "200", description = SUCCESSFULLY, content = @Content), @ApiResponse(responseCode = "400", description = MESSAGE_HAS_ALREADY_REPORTED, diff --git a/src/main/java/com/chat/yourway/dto/common/EmailMessageDto.java b/src/main/java/com/chat/yourway/dto/common/EmailMessageDto.java index 0adb70e3..b105f158 100644 --- a/src/main/java/com/chat/yourway/dto/common/EmailMessageDto.java +++ b/src/main/java/com/chat/yourway/dto/common/EmailMessageDto.java @@ -2,7 +2,4 @@ public record EmailMessageDto(String to, String subject, - String text -) { -} - + String text) { } \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/dto/common/EmailMessageInfoDto.java b/src/main/java/com/chat/yourway/dto/common/EmailMessageInfoDto.java index 04ef9b50..089b0f53 100644 --- a/src/main/java/com/chat/yourway/dto/common/EmailMessageInfoDto.java +++ b/src/main/java/com/chat/yourway/dto/common/EmailMessageInfoDto.java @@ -8,6 +8,4 @@ public record EmailMessageInfoDto(String username, String email, UUID uuidToken, String path, - EmailMessageType emailMessageType) { - -} + EmailMessageType emailMessageType) { } \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/security/JwtAuthFilter.java b/src/main/java/com/chat/yourway/security/JwtAuthFilter.java index 3cf548ee..0b332054 100644 --- a/src/main/java/com/chat/yourway/security/JwtAuthFilter.java +++ b/src/main/java/com/chat/yourway/security/JwtAuthFilter.java @@ -6,11 +6,10 @@ import com.chat.yourway.repository.redis.TokenRedisRepository; import io.jsonwebtoken.JwtException; import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.lang.NonNull; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -34,9 +33,10 @@ public class JwtAuthFilter extends OncePerRequestFilter { private final HandlerExceptionResolver handlerExceptionResolver; @Override + @SneakyThrows protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, - @NonNull FilterChain filterChain) throws ServletException, IOException { + @NonNull FilterChain filterChain) { if (isNotAuthorizationHeader(request) && isNotTokenParameter(request)) { log.warn("Request without authorization. Header or parameter does not contain {}", AUTHORIZATION); @@ -75,8 +75,7 @@ private Boolean isTokenValid(String jwtToken, UserDetails userDetails) { } private void setAuthentication(UserDetails userDetails, HttpServletRequest request) { - var authToken = new UsernamePasswordAuthenticationToken(userDetails, null, - userDetails.getAuthorities()); + var authToken = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authToken); } @@ -88,5 +87,4 @@ private boolean isNotAuthorizationHeader(HttpServletRequest request) { private boolean isNotTokenParameter(HttpServletRequest request) { return request.getParameter(AUTHORIZATION) == null; } - -} +} \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/security/JwtService.java b/src/main/java/com/chat/yourway/security/JwtService.java index 8259a2b5..5db4edb4 100644 --- a/src/main/java/com/chat/yourway/security/JwtService.java +++ b/src/main/java/com/chat/yourway/security/JwtService.java @@ -41,6 +41,7 @@ public String generateRefreshToken(UserDetails userDetails) { public String extractToken(HttpServletRequest request) { String token = request.getHeader(AUTHORIZATION); + if (token == null) { token = request.getParameter(AUTHORIZATION); } diff --git a/src/main/java/com/chat/yourway/security/TokenService.java b/src/main/java/com/chat/yourway/security/TokenService.java index 6942ebab..68a6ceae 100644 --- a/src/main/java/com/chat/yourway/security/TokenService.java +++ b/src/main/java/com/chat/yourway/security/TokenService.java @@ -20,20 +20,24 @@ public void saveToken(Token token) { } public Token findByToken(String token) { - return tokenRedisRepository.findByToken(token) - .orElseThrow(() -> new TokenNotFoundException("Token wasn't found in repository")); + return tokenRedisRepository.findByToken(token).orElseThrow( + () -> new TokenNotFoundException("Token wasn't found in repository") + ); } public void revokeAllContactTokens(Contact contact) { var validUserTokens = tokenRedisRepository.findAllByEmail(contact.getEmail()); + if (validUserTokens.isEmpty()) { return; } + validUserTokens.forEach(token -> { - token.setExpired(true); - token.setRevoked(true); - }); + token.setExpired(true); + token.setRevoked(true); + } + ); + tokenRedisRepository.saveAll(validUserTokens); } - -} +} \ No newline at end of file