Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 821cfd3

Browse files
authored
Merge pull request #71 from Zenfulcode/70-unauthenticated-error-when-creating-order
fixing unauthenticated users aka guests, could make order requests
2 parents 6ab2144 + d1e9857 commit 821cfd3

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/com/zenfulcode/commercify/commercify/config/SecurityConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3535
.requestMatchers(
3636
"/api/v1/auth/**",
3737
"/api/v1/products/active",
38-
"/api/v1/products/{id}").permitAll()
38+
"/api/v1/products/{id}",
39+
"/api/v1/orders",
40+
"/api/v1/payments/mobilepay/create",
41+
"/api/v1/payments/stripe/create").permitAll()
3942
.anyRequest().authenticated()
4043
)
4144
.sessionManagement(smc -> smc.sessionCreationPolicy(SessionCreationPolicy.STATELESS))

src/main/java/com/zenfulcode/commercify/commercify/controller/OrderController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class OrderController {
3737
"id", "userId", "status", "currency", "totalAmount", "createdAt", "updatedAt"
3838
);
3939

40+
@PreAuthorize("hasRole('USER') and #userId == authentication.principal.id")
4041
@PostMapping("/{userId}")
4142
public ResponseEntity<?> createOrder(@PathVariable Long userId, @RequestBody CreateOrderRequest orderRequest) {
4243
try {

src/main/java/com/zenfulcode/commercify/commercify/integration/mobilepay/MobilePayController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.RequiredArgsConstructor;
66
import lombok.extern.slf4j.Slf4j;
77
import org.springframework.http.ResponseEntity;
8+
import org.springframework.security.access.prepost.PreAuthorize;
89
import org.springframework.web.bind.annotation.*;
910

1011
@RestController
@@ -37,6 +38,7 @@ public ResponseEntity<String> handleCallback(
3738
}
3839
}
3940

41+
@PreAuthorize("hasRole('ADMIN')")
4042
@PostMapping("/webhook")
4143
public ResponseEntity<String> handleWebhook(
4244
@RequestParam String paymentReference,

0 commit comments

Comments
 (0)