-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE#10153] Add auth state into /state api and add announcement api. (
#10203) * Add ModuleState and use ModuleState replace ServerStateController. * Add AuthModuleStateBuilder * state接口使用ModuleState. * Add announcement api. * skip rat scan for announcement.conf * default plugin open login page when auth.enabled=true.
- Loading branch information
1 parent
d291f24
commit 5fffde5
Showing
22 changed files
with
647 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
auth/src/main/java/com/alibaba/nacos/auth/config/AuthModuleStateBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.auth.config; | ||
|
||
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginManager; | ||
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService; | ||
import com.alibaba.nacos.sys.module.ModuleState; | ||
import com.alibaba.nacos.sys.module.ModuleStateBuilder; | ||
import com.alibaba.nacos.sys.utils.ApplicationUtils; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Module state builder for auth module. | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
public class AuthModuleStateBuilder implements ModuleStateBuilder { | ||
|
||
public static final String AUTH_MODULE = "auth"; | ||
|
||
public static final String AUTH_ENABLED = "auth_enabled"; | ||
|
||
public static final String LOGIN_PAGE_ENABLED = "login_page_enabled"; | ||
|
||
public static final String AUTH_SYSTEM_TYPE = "auth_system_type"; | ||
|
||
@Override | ||
public ModuleState build() { | ||
ModuleState result = new ModuleState(AUTH_MODULE); | ||
AuthConfigs authConfigs = ApplicationUtils.getBean(AuthConfigs.class); | ||
result.newState(AUTH_ENABLED, authConfigs.isAuthEnabled()); | ||
result.newState(LOGIN_PAGE_ENABLED, isLoginPageEnabled(authConfigs)); | ||
result.newState(AUTH_SYSTEM_TYPE, authConfigs.getNacosAuthSystemType()); | ||
return result; | ||
} | ||
|
||
private Boolean isLoginPageEnabled(AuthConfigs authConfigs) { | ||
Optional<AuthPluginService> authPluginService = AuthPluginManager.getInstance() | ||
.findAuthServiceSpiImpl(authConfigs.getNacosAuthSystemType()); | ||
return authPluginService.map(AuthPluginService::isLoginEnabled).orElse(false); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
auth/src/main/resources/META-INF/services/com.alibaba.nacos.sys.module.ModuleStateBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
com.alibaba.nacos.auth.config.AuthModuleStateBuilder |
61 changes: 61 additions & 0 deletions
61
auth/src/test/java/com/alibaba/nacos/auth/config/AuthModuleStateBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.auth.config; | ||
|
||
import com.alibaba.nacos.sys.module.ModuleState; | ||
import com.alibaba.nacos.sys.utils.ApplicationUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import static com.alibaba.nacos.auth.config.AuthModuleStateBuilder.AUTH_ENABLED; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AuthModuleStateBuilderTest { | ||
|
||
@Mock | ||
private ConfigurableApplicationContext context; | ||
|
||
@Mock | ||
private AuthConfigs authConfigs; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
when(context.getBean(AuthConfigs.class)).thenReturn(authConfigs); | ||
ApplicationUtils.injectContext(context); | ||
when(authConfigs.getNacosAuthSystemType()).thenReturn("nacos"); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testBuild() { | ||
ModuleState actual = new AuthModuleStateBuilder().build(); | ||
assertFalse((Boolean) actual.getStates().get(AUTH_ENABLED)); | ||
assertFalse((Boolean) actual.getStates().get("login_page_enabled")); | ||
assertEquals("nacos", actual.getStates().get("auth_system_type")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
当前集群没有开启鉴权,请参考[文档](https://nacos.io/zh-cn/docs/v2/guide/user/auth.html)开启鉴权~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
sys/src/main/java/com/alibaba/nacos/sys/env/EnvModuleStateBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.nacos.sys.env; | ||
|
||
import com.alibaba.nacos.common.utils.VersionUtils; | ||
import com.alibaba.nacos.sys.module.ModuleState; | ||
import com.alibaba.nacos.sys.module.ModuleStateBuilder; | ||
|
||
/** | ||
* Module state builder for env module. | ||
* | ||
* @author xiweng.yy | ||
*/ | ||
public class EnvModuleStateBuilder implements ModuleStateBuilder { | ||
|
||
@Override | ||
public ModuleState build() { | ||
ModuleState result = new ModuleState(Constants.SYS_MODULE); | ||
result.newState(Constants.STANDALONE_MODE_STATE, | ||
EnvUtil.getStandaloneMode() ? EnvUtil.STANDALONE_MODE_ALONE : EnvUtil.STANDALONE_MODE_CLUSTER); | ||
result.newState(Constants.FUNCTION_MODE_STATE, EnvUtil.getFunctionMode()); | ||
result.newState(Constants.NACOS_VERSION, VersionUtils.version); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.