diff --git a/generators/spring-boot/templates/src/main/java/_package_/web/rest/AuthenticateController.java.ejs b/generators/spring-boot/templates/src/main/java/_package_/web/rest/AuthenticateController.java.ejs index 9c8c94892876..4be1c99206c9 100644 --- a/generators/spring-boot/templates/src/main/java/_package_/web/rest/AuthenticateController.java.ejs +++ b/generators/spring-boot/templates/src/main/java/_package_/web/rest/AuthenticateController.java.ejs @@ -117,15 +117,15 @@ public class AuthenticateController { <%_ } _%> /** - * {@code GET /authenticate} : check if the user is authenticated, and return its login. + * {@code GET /authenticate} : check if the user is authenticated, and return a boolean value. * * @param principal the authentication principal. - * @return the login if the user is authenticated. + * @return a boolean indicating if the user is authenticated. */ - @GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE) - public String isAuthenticated(Principal principal) { + @GetMapping(value = "/authenticate") + public Boolean isAuthenticated(Principal principal) { LOG.debug("REST request to check if the current user is authenticated"); - return principal == null ? null : principal.getName(); + return principal != null; } public String createToken(Authentication authentication, boolean rememberMe) { diff --git a/generators/spring-boot/templates/src/test/java/_package_/web/rest/AccountResourceIT.java.ejs b/generators/spring-boot/templates/src/test/java/_package_/web/rest/AccountResourceIT.java.ejs index 41a763744ec4..d052df0b5453 100644 --- a/generators/spring-boot/templates/src/test/java/_package_/web/rest/AccountResourceIT.java.ejs +++ b/generators/spring-boot/templates/src/test/java/_package_/web/rest/AccountResourceIT.java.ejs @@ -174,16 +174,17 @@ class AccountResourceIT { <%_ if (reactive) { _%> void testNonAuthenticatedUser() { accountWebTestClient.get().uri("/api/authenticate") - .accept(MediaType.TEXT_PLAIN) .exchange() - .expectStatus().isOk() - .expectBody().isEmpty(); + .expectStatus() + .isOk() + .expectBody(Boolean.class) + .isEqualTo(false); <%_ } else { _%> void testNonAuthenticatedUser() throws Exception { restAccountMockMvc - .perform(get("/api/authenticate").accept(MediaType.TEXT_PLAIN)) + .perform(get("/api/authenticate")) .andExpect(status().isOk()) - .andExpect(content().string("")); + .andExpect(content().string(Boolean.FALSE.toString())); <%_ } _%> } @@ -192,17 +193,20 @@ class AccountResourceIT { <%_ if (reactive) { _%> void testAuthenticatedUser() { accountWebTestClient - .get().uri("/api/authenticate") - .accept(MediaType.TEXT_PLAIN) + .get() + .uri("/api/authenticate") .exchange() - .expectStatus().isOk() - .expectBody(String.class).isEqualTo(TEST_USER_LOGIN); + .expectStatus() + .isOk() + .expectBody(Boolean.class) + .isEqualTo(true); <%_ } else { _%> void testAuthenticatedUser() throws Exception { restAccountMockMvc - .perform(get("/api/authenticate").with(request -> request).accept(MediaType.TEXT_PLAIN)) + .perform(get("/api/authenticate") + .with(request -> request)) .andExpect(status().isOk()) - .andExpect(content().string(TEST_USER_LOGIN)); + .andExpect(content().string(Boolean.TRUE.toString())); <%_ } _%> }