Skip to content

Commit

Permalink
[ISSUE#11494] Fix frequently request login api when using 2.X client …
Browse files Browse the repository at this point in the history
…with username. (#11495)

* Fix frequently request login api when using 2.X client with username.

* Fix frequently request login api when using 2.X client with username.
  • Loading branch information
KomachiSion authored Dec 12, 2023
1 parent 26d045c commit a3420b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
@Component
public class JwtTokenManager extends Subscriber<ServerConfigChangeEvent> implements TokenManager {

@Deprecated
private static final String AUTHORITIES_KEY = "auth";
private static final String AUTH_DISABLED_TOKEN = "AUTH_DISABLED";

/**
* Token validity time(seconds).
Expand Down Expand Up @@ -105,7 +104,7 @@ public String createToken(Authentication authentication) {
*/
public String createToken(String userName) {
if (!authConfigs.isAuthEnabled()) {
return StringUtils.EMPTY;
return AUTH_DISABLED_TOKEN;
}
checkJwtParser();
return jwtParser.jwtBuilder().setUserName(userName).setExpiredTime(this.tokenValidityInSeconds).compact();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void testGetExpiredTimeInSeconds() throws AccessException {
public void testCreateTokenWhenDisableAuth() {
when(authConfigs.isAuthEnabled()).thenReturn(false);
jwtTokenManager = new JwtTokenManager(authConfigs);
assertEquals("", jwtTokenManager.createToken("nacos"));
assertEquals("AUTH_DISABLED", jwtTokenManager.createToken("nacos"));
}

@Test
Expand Down

0 comments on commit a3420b7

Please sign in to comment.