Files
velocity-pay-springboot/src/main/java/zw/qantra/tm/domain/controllers/TestController.java

35 lines
1.3 KiB
Java

package zw.qantra.tm.domain.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import zw.qantra.tm.domain.services.EmailService;
@RestController
@RequestMapping("/test")
@CrossOrigin(origins = "*")
public class TestController {
@Autowired
private EmailService emailService;
@GetMapping("/hello/{email}")
public ResponseEntity<String> helloEndpoint(@PathVariable String email) {
emailService.sendSimpleMessage(email, "Hello", "Hello World!");
return ResponseEntity.ok("Hello World!");
}
@GetMapping("/protected")
public ResponseEntity<String> protectedEndpoint() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
return ResponseEntity.ok("Hello " + username + "! This is a protected endpoint.");
}
@GetMapping("/public")
public ResponseEntity<String> publicEndpoint() {
return ResponseEntity.ok("This is a public endpoint - no authentication required!");
}
}