Skip to content

Commit

Permalink
OAuth2: refactoring and improve templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalgrimaud committed Mar 16, 2022
1 parent c633859 commit 09ef1a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {{packageName}}.security.oauth2.infrastructure.WithUnauthenticatedMockUse

@AutoConfigureMockMvc
@IntegrationTest
@WithMockUser(value = "test")
@WithMockUser(value = TEST_USER_LOGIN)
class AccountResourceIT {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package {{packageName}}.account.infrastructure.primary.rest;

import static tech.jhipster.oauth2app.account.domain.AccountConstants.*;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
Expand Down Expand Up @@ -32,9 +34,9 @@ public class OAuth2TestUtil {
public static OAuth2AuthenticationToken testAuthenticationToken() {
Map<String, Object> claims = new HashMap<>();
claims.put("sub", TEST_USER_LOGIN);
claims.put("preferred_username", TEST_USER_LOGIN);
claims.put("email", "john.doe@jhipster.com");
claims.put(SUB, TEST_USER_LOGIN);
claims.put(PREFERRED_USERNAME, TEST_USER_LOGIN);
claims.put(EMAIL, "john.doe@jhipster.com");
claims.put("roles", Collections.singletonList(AuthoritiesConstants.ADMIN));
return authenticationToken(claims);
Expand All @@ -50,14 +52,14 @@ public class OAuth2TestUtil {
public static OAuth2AuthenticationToken authenticationToken(Map<String, Object> claims) {
Instant issuedAt = Instant.now();
Instant expiresAt = Instant.now().plus(1, ChronoUnit.DAYS);
if (!claims.containsKey("sub")) {
claims.put("sub", "jane");
if (!claims.containsKey(SUB)) {
claims.put(SUB, "jane");
}
if (!claims.containsKey("preferred_username")) {
claims.put("preferred_username", "jane");
if (!claims.containsKey(PREFERRED_USERNAME)) {
claims.put(PREFERRED_USERNAME, "jane");
}
if (!claims.containsKey("email")) {
claims.put("email", "jane.doe@jhipster.com");
if (!claims.containsKey(EMAIL)) {
claims.put(EMAIL, "jane.doe@jhipster.com");
}
if (claims.containsKey("auth_time")) {
issuedAt = (Instant) claims.get("auth_time");
Expand Down

0 comments on commit 09ef1a8

Please sign in to comment.