[ISSUE#11494] Fix frequently request login api when using 2.X client 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.
This commit is contained in:
杨翊 SionYang 2023-12-12 14:13:56 +08:00 committed by GitHub
parent 26d045ca49
commit a3420b733b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -49,8 +49,7 @@ import java.util.concurrent.TimeUnit;
@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).
@ -105,7 +104,7 @@ public class JwtTokenManager extends Subscriber<ServerConfigChangeEvent> impleme
*/
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();

View File

@ -110,7 +110,7 @@ public class JwtTokenManagerTest {
public void testCreateTokenWhenDisableAuth() {
when(authConfigs.isAuthEnabled()).thenReturn(false);
jwtTokenManager = new JwtTokenManager(authConfigs);
assertEquals("", jwtTokenManager.createToken("nacos"));
assertEquals("AUTH_DISABLED", jwtTokenManager.createToken("nacos"));
}
@Test