Skip to content

Commit be340f0

Browse files
committed
Fix failing tests and remove redundant helper class
1 parent 3dec2ad commit be340f0

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

src/main/java/org/openpodcastapi/opa/auth/JwtAccessDeniedHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.openpodcastapi.opa.auth;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import jakarta.servlet.http.HttpServletRequest;
45
import jakarta.servlet.http.HttpServletResponse;
5-
import org.openpodcastapi.opa.util.JSONFormatter;
6+
import lombok.RequiredArgsConstructor;
67
import org.springframework.http.HttpStatus;
78
import org.springframework.security.access.AccessDeniedException;
89
import org.springframework.security.web.access.AccessDeniedHandler;
@@ -11,7 +12,10 @@
1112
import java.io.IOException;
1213

1314
@Component
15+
@RequiredArgsConstructor
1416
public class JwtAccessDeniedHandler implements AccessDeniedHandler {
17+
private final ObjectMapper objectMapper;
18+
1519
@Override
1620
public void handle(HttpServletRequest request,
1721
HttpServletResponse response,
@@ -25,6 +29,6 @@ public void handle(HttpServletRequest request,
2529

2630
AuthDTO.ErrorMessageDTO message = new AuthDTO.ErrorMessageDTO("Forbidden", "You do not have permission to access this resource");
2731

28-
response.getWriter().write(JSONFormatter.parseDataToJSON(message));
32+
response.getWriter().write(objectMapper.writeValueAsString(message));
2933
}
3034
}

src/main/java/org/openpodcastapi/opa/auth/JwtAuthenticationEntryPoint.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.openpodcastapi.opa.auth;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import jakarta.servlet.http.HttpServletRequest;
45
import jakarta.servlet.http.HttpServletResponse;
5-
import org.openpodcastapi.opa.util.JSONFormatter;
6+
import lombok.RequiredArgsConstructor;
67
import org.springframework.http.HttpStatus;
78
import org.springframework.security.core.AuthenticationException;
89
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -11,7 +12,10 @@
1112
import java.io.IOException;
1213

1314
@Component
15+
@RequiredArgsConstructor
1416
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
17+
private final ObjectMapper objectMapper;
18+
1519
/// Returns a 401 when a request is made without a valid bearer token
1620
@Override
1721
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
@@ -23,6 +27,6 @@ public void commence(HttpServletRequest request, HttpServletResponse response, A
2327

2428
AuthDTO.ErrorMessageDTO message = new AuthDTO.ErrorMessageDTO("Access denied", "You need to log in to access this resource");
2529

26-
response.getWriter().write(JSONFormatter.parseDataToJSON(message));
30+
response.getWriter().write(objectMapper.writeValueAsString(message));
2731
}
2832
}

src/main/java/org/openpodcastapi/opa/security/TokenService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public String generateRefreshToken(UserEntity userEntity) {
7474

7575
/// Validates the refresh token for a userEntity and updates its expiry time
7676
///
77-
/// @param rawToken the raw token to validate
78-
/// @param userEntity the [UserEntity] to validate the token for
77+
/// @param rawToken the raw token to validate
78+
/// @param userEntity the [UserEntity] to validate the token for
7979
/// @return the validated [UserEntity]
8080
public UserEntity validateRefreshToken(String rawToken, UserEntity userEntity) {
8181
// Only fetch refresh tokens for the requesting userEntity

src/main/java/org/openpodcastapi/opa/subscription/SubscriptionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Page<SubscriptionDTO.UserSubscriptionDTO> getAllActiveSubscriptionsForUse
7979
/// If an existing entry is found for the userEntity and subscriptionEntity, the `isSubscribed` property is set to `true`
8080
///
8181
/// @param subscriptionEntity the target subscriptionEntity
82-
/// @param userId the ID of the target userEntity
82+
/// @param userId the ID of the target userEntity
8383
/// @return a [SubscriptionDTO.UserSubscriptionDTO] representation of the subscriptionEntity link
8484
/// @throws EntityNotFoundException if no matching userEntity is found
8585
protected SubscriptionDTO.UserSubscriptionDTO persistUserSubscription(SubscriptionEntity subscriptionEntity, Long userId) {
@@ -90,7 +90,7 @@ protected SubscriptionDTO.UserSubscriptionDTO persistUserSubscription(Subscripti
9090
log.debug("Creating new userEntity subscriptionEntity for userEntity {} and subscriptionEntity {}", userId, subscriptionEntity.getUuid());
9191
UserSubscriptionEntity createdSubscription = new UserSubscriptionEntity();
9292
createdSubscription.setIsSubscribed(true);
93-
createdSubscription.setUserEntity(userEntity);
93+
createdSubscription.setUser(userEntity);
9494
createdSubscription.setSubscription(subscriptionEntity);
9595
return userSubscriptionRepository.save(createdSubscription);
9696
});

src/main/java/org/openpodcastapi/opa/subscription/UserSubscriptionEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class UserSubscriptionEntity {
2525

2626
@ManyToOne
2727
@JoinColumn(name = "user_id")
28-
private UserEntity userEntity;
28+
private UserEntity user;
2929

3030
@ManyToOne
3131
@JoinColumn(name = "subscription_id")

src/main/java/org/openpodcastapi/opa/util/JSONFormatter.java

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/test/java/org/openpodcastapi/opa/subscriptions/UserSubscriptionEntityMapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void testToDto() {
4949

5050
UserSubscriptionEntity userSubscriptionEntity = UserSubscriptionEntity.builder()
5151
.uuid(uuid)
52-
.userEntity(userEntity)
52+
.user(userEntity)
5353
.subscription(subscriptionEntity)
5454
.isSubscribed(true)
5555
.createdAt(timestamp)

0 commit comments

Comments
 (0)