diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java index 7452c2f3e1d..33e727cc722 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManager.java @@ -49,8 +49,7 @@ @Component public class JwtTokenManager extends Subscriber 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 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(); diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java index 32f9fbc2171..6942f028e42 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/test/java/com/alibaba/nacos/plugin/auth/impl/token/impl/JwtTokenManagerTest.java @@ -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