Skip to content

Commit

Permalink
Merge pull request #27058 from mshima/authenticated
Browse files Browse the repository at this point in the history
add produces to /authenticate endpoint
  • Loading branch information
DanielFran authored Aug 24, 2024
2 parents f1f0430 + 2971959 commit 32dcd4c
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 38 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ jobs:
run: npm run ci:backend:test
continue-on-error: ${{matrix.continue-on-backend-tests-error || false}}
timeout-minutes: 15
# Run npm install for workspaces only, as it is done in packaging for non-workspaces
- name: 'PREPARE: npm install'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && (matrix.sonar-analyse == 'true' || needs.build-matrix.outputs.client != 'false')
run: ${{ (matrix.workspaces == 'true' && 'npm') || './npmw' }} install
if: matrix.workspaces == 'true'
run: npm install
timeout-minutes: 7
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && (matrix.sonar-analyse == 'true' || needs.build-matrix.outputs.client != 'false')
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: packaging'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:package
timeout-minutes: 12
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && (matrix.sonar-analyse == 'true' || needs.build-matrix.outputs.client != 'false')
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: Start docker compose containers for e2e tests'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:prepare
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ jobs:
#----------------------------------------------------------------------
- uses: jhipster/actions/compare-sample@v0
id: compare
with:
generator-path: generator-jhipster
cmd: jhipster.cjs generate-sample ${{ matrix.name }} --skip-jhipster-dependencies --skip-checks --skip-install --no-insight
if: >-
github.event.pull_request &&
!contains(github.event.pull_request.labels.*.name, 'pr: disable-compare')
with:
generator-path: generator-jhipster
cmd: jhipster.cjs generate-sample ${{ matrix.name }} --skip-jhipster-dependencies --skip-checks --skip-install --no-insight
env:
# generate-sample uses JHI_FOLDER_APP to generate the application.
JHI_FOLDER_APP: ${{ github.workspace }}/base/app
Expand All @@ -136,18 +136,19 @@ jobs:
run: npm run ci:backend:test
continue-on-error: ${{matrix.continue-on-backend-tests-error || false}}
timeout-minutes: 15
# Run npm install for workspaces only, as it is done in packaging for non-workspaces
- name: 'PREPARE: npm install'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: ${{ (matrix.workspaces == 'true' && 'npm') || './npmw' }} install
if: matrix.workspaces == 'true'
run: npm install
timeout-minutes: 7
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: packaging'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:package
timeout-minutes: 12
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: Start docker compose containers for e2e tests'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:prepare
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/vue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ jobs:
run: npm run ci:backend:test
continue-on-error: ${{matrix.continue-on-backend-tests-error || false}}
timeout-minutes: 15
# Run npm install for workspaces only, as it is done in packaging for non-workspaces
- name: 'PREPARE: npm install'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: ${{ (matrix.workspaces == 'true' && 'npm') || './npmw' }} install
if: matrix.workspaces == 'true'
run: npm install
timeout-minutes: 7
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: packaging'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:package
timeout-minutes: 12
- name: 'TESTS: frontend'
if: steps.compare.outputs.equals != 'true' && matrix.skip-frontend-tests != 'true' && needs.build-matrix.outputs.client != 'false'
run: npm run ci:frontend:test
timeout-minutes: 15
- name: 'TESTS: Start docker compose containers for e2e tests'
if: steps.compare.outputs.equals != 'true'
run: npm run ci:e2e:prepare
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
<%_ if (reactive) { _%>
import java.util.Objects;
Expand Down Expand Up @@ -139,7 +140,7 @@ public class AccountResource {
* @param principal the authentication principal.
* @return the login if the user is authenticated.
*/
@GetMapping("/authenticate")
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated(Principal principal) {
LOG.debug("REST request to check if the current user is authenticated");
return principal == null ? null : principal.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import <%= packageName %>.service.dto.<%= user.adminUserDto %>;
import java.security.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class AccountResource {
* @param principal the authentication principal.
* @return the login if the user is authenticated.
*/
@GetMapping("/authenticate")
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated(Principal principal) {
LOG.debug("REST request to check if the current user is authenticated");
return principal == null ? null : principal.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -143,7 +144,7 @@ public class AccountResource {
* @param principal the authentication principal.
* @return the login if the user is authenticated.
*/
@GetMapping("/authenticate")
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated(Principal principal) {
LOG.debug("REST request to check if the current user is authenticated");
return principal == null ? null : principal.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -121,7 +122,7 @@ public class AuthenticateController {
* @param principal the authentication principal.
* @return the login if the user is authenticated.
*/
@GetMapping("/authenticate")
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated(Principal principal) {
LOG.debug("REST request to check if the current user is authenticated");
return principal == null ? null : principal.getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package <%= packageName %>.security.jwt;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
Expand All @@ -14,7 +15,7 @@ public class TestAuthenticationResource {
*
* @return ok.
*/
@GetMapping("/authenticate")
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated() {
return "ok";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ class AccountResourceIT {
<%_ if (reactive) { _%>
void testNonAuthenticatedUser() {
accountWebTestClient.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody().isEmpty();
<%_ } else { _%>
void testNonAuthenticatedUser() throws Exception {
restAccountMockMvc
.perform(get("/api/authenticate").accept(MediaType.APPLICATION_JSON))
.perform(get("/api/authenticate").accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(""));
<%_ } _%>
Expand All @@ -193,14 +193,14 @@ class AccountResourceIT {
void testAuthenticatedUser() {
accountWebTestClient
.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody(String.class).isEqualTo(TEST_USER_LOGIN);
<%_ } else { _%>
void testAuthenticatedUser() throws Exception {
restAccountMockMvc
.perform(get("/api/authenticate").with(request -> request).accept(MediaType.APPLICATION_JSON))
.perform(get("/api/authenticate").with(request -> request).accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(TEST_USER_LOGIN));
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ class AccountResourceIT {
void testNonAuthenticatedUser() <% if (!reactive) { %>throws Exception <% } %>{
<%_ if (reactive) { _%>
webTestClient.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody().isEmpty();
<%_ } else { _%>
restAccountMockMvc.perform(get("/api/authenticate")
.accept(MediaType.APPLICATION_JSON))
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(""));
<%_ } _%>
Expand All @@ -203,14 +203,14 @@ class AccountResourceIT {
<%_ if (reactive) { _%>
webTestClient
.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody(String.class).isEqualTo(TEST_USER_LOGIN);
<%_ } else { _%>
restAccountMockMvc.perform(get("/api/authenticate")
.with(request -> request)
.accept(MediaType.APPLICATION_JSON))
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(TEST_USER_LOGIN));
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ class AccountResourceIT {
void testNonAuthenticatedUser() <% if (!reactive) { %>throws Exception <% } %>{
<%_ if (reactive) { _%>
accountWebTestClient.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody().isEmpty();
<%_ } else { _%>
restAccountMockMvc.perform(get("/api/authenticate")
.accept(MediaType.APPLICATION_JSON))
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(""));
<%_ } _%>
Expand All @@ -134,14 +134,14 @@ class AccountResourceIT {
<%_ if (reactive) { _%>
accountWebTestClient
.get().uri("/api/authenticate")
.accept(MediaType.APPLICATION_JSON)
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody(String.class).isEqualTo(TEST_USER_LOGIN);
<%_ } else { _%>
restAccountMockMvc.perform(get("/api/authenticate")
.with(request -> request)
.accept(MediaType.APPLICATION_JSON))
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string(TEST_USER_LOGIN));
<%_ } _%>
Expand Down

0 comments on commit 32dcd4c

Please sign in to comment.