added jwt auth to service
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package zw.qantra.tm.domain.controllers;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class TestController {
|
||||
|
||||
@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!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user