UserInfoController.java

  1. package edu.ucsb.cs156.example.controllers;

  2. import edu.ucsb.cs156.example.models.CurrentUser;

  3. import io.swagger.v3.oas.annotations.Operation;
  4. import io.swagger.v3.oas.annotations.tags.Tag;

  5. import org.springframework.security.access.prepost.PreAuthorize;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;

  9. /**
  10.  * This is a REST controller for getting information about the current user.
  11.  */

  12. @Tag(name="Current User Information")
  13. @RequestMapping("/api/currentUser")
  14. @RestController
  15. public class UserInfoController extends ApiController {
  16.  
  17.   /**
  18.    * This method returns the current user.
  19.    * @return the current user
  20.    */

  21.   @Operation(summary= "Get information about current user")
  22.   @PreAuthorize("hasRole('ROLE_USER')")
  23.   @GetMapping("")
  24.   public CurrentUser getCurrentUser() {
  25.     return super.getCurrentUser();
  26.   }
  27. }