Create an endpoint which is used in the frontend to check if the current token is still valid
package org.carlspring.strongbox.controllers;
-import java.io.IOException;
-
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
@@ -27,7 +26,24 @@ public class PingController
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_PLAIN_VALUE })
public ResponseEntity ping(@RequestHeader(HttpHeaders.ACCEPT) String accept)
- throws IOException
+ {
+ return getSuccessfulResponseEntity("pong", accept);
+ }
+
+ /**
+ * This endpoint is used in the frontend to check if a token is valid when the SPA has been loaded for the first time
+ * and there was a token stored in the client's browser.
+ *
+ * @param accept
+ *
+ * @return ResponseEntity
+ */
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful when token is still valid.") })
+ @PreAuthorize("hasAuthority('UI_LOGIN')")
+ @GetMapping(value = "/token",
+ produces = { MediaType.APPLICATION_JSON_VALUE,
+ MediaType.TEXT_PLAIN_VALUE })
+ public ResponseEntity protectedPing(@RequestHeader(HttpHeaders.ACCEPT) String accept)
{
return getSuccessfulResponseEntity("pong", accept);
}
