Skip to content

Commit 9cc82e5

Browse files
committed
fix(sonar): simplify authentication response type
1 parent 059b93d commit 9cc82e5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

generators/spring-boot/templates/src/main/java/_package_/web/rest/AuthenticateController.java.ejs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ public class AuthenticateController {
117117
<%_ } _%>
118118

119119
/**
120-
* {@code GET /authenticate} : check if the user is authenticated, and return its login.
120+
* {@code GET /authenticate} : check if the user is authenticated, and return a boolean value.
121121
*
122122
* @param principal the authentication principal.
123-
* @return the login if the user is authenticated.
123+
* @return a boolean indicating if the user is authenticated.
124124
*/
125-
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
126-
public String isAuthenticated(Principal principal) {
125+
@GetMapping(value = "/authenticate")
126+
public Boolean isAuthenticated(Principal principal) {
127127
LOG.debug("REST request to check if the current user is authenticated");
128-
return principal == null ? null : principal.getName();
128+
return principal != null;
129129
}
130130

131131
public String createToken(Authentication authentication, boolean rememberMe) {

generators/spring-boot/templates/src/test/java/_package_/web/rest/AccountResourceIT.java.ejs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,17 @@ class AccountResourceIT {
174174
<%_ if (reactive) { _%>
175175
void testNonAuthenticatedUser() {
176176
accountWebTestClient.get().uri("/api/authenticate")
177-
.accept(MediaType.TEXT_PLAIN)
178177
.exchange()
179-
.expectStatus().isOk()
180-
.expectBody().isEmpty();
178+
.expectStatus()
179+
.isOk()
180+
.expectBody(Boolean.class)
181+
.isEqualTo(false);
181182
<%_ } else { _%>
182183
void testNonAuthenticatedUser() throws Exception {
183184
restAccountMockMvc
184-
.perform(get("/api/authenticate").accept(MediaType.TEXT_PLAIN))
185+
.perform(get("/api/authenticate"))
185186
.andExpect(status().isOk())
186-
.andExpect(content().string(""));
187+
.andExpect(content().string(Boolean.FALSE.toString()));
187188
<%_ } _%>
188189
}
189190
@@ -192,17 +193,20 @@ class AccountResourceIT {
192193
<%_ if (reactive) { _%>
193194
void testAuthenticatedUser() {
194195
accountWebTestClient
195-
.get().uri("/api/authenticate")
196-
.accept(MediaType.TEXT_PLAIN)
196+
.get()
197+
.uri("/api/authenticate")
197198
.exchange()
198-
.expectStatus().isOk()
199-
.expectBody(String.class).isEqualTo(TEST_USER_LOGIN);
199+
.expectStatus()
200+
.isOk()
201+
.expectBody(Boolean.class)
202+
.isEqualTo(true);
200203
<%_ } else { _%>
201204
void testAuthenticatedUser() throws Exception {
202205
restAccountMockMvc
203-
.perform(get("/api/authenticate").with(request -> request).accept(MediaType.TEXT_PLAIN))
206+
.perform(get("/api/authenticate")
207+
.with(request -> request))
204208
.andExpect(status().isOk())
205-
.andExpect(content().string(TEST_USER_LOGIN));
209+
.andExpect(content().string(Boolean.TRUE.toString()));
206210
<%_ } _%>
207211
}
208212

0 commit comments

Comments
 (0)