Skip to content

Commit

Permalink
V3.0 develop fix console login problem (#13007)
Browse files Browse the repository at this point in the history
* Fix console ui login error and fix console leak filters.

* Some simple refactor for nacos auth plugin.
  • Loading branch information
KomachiSion authored Jan 2, 2025
1 parent 05362b0 commit f0ad076
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 280 deletions.
2 changes: 1 addition & 1 deletion console-ui/src/reducers/authority.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const getPermissions = params => dispatch =>
*/
const checkPermission = ([role, resource, action]) => {
const params = { role, resource, action };
return request.get('v1/auth/permissions', { params }).then(res => res.data);
return request.get('v3/auth/permission', { params }).then(res => res.data);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.alibaba.nacos.console.filter.NacosConsoleAuthFilter;
import com.alibaba.nacos.console.filter.XssFilter;
import com.alibaba.nacos.core.code.ControllerMethodsCache;
import com.alibaba.nacos.core.controller.compatibility.ApiCompatibilityFilter;
import com.alibaba.nacos.core.paramcheck.ParamCheckerFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
Expand All @@ -41,7 +43,7 @@
* @since 1.2.0
*/
@Component
public class ConsoleConfig {
public class ConsoleWebConfig {

private final ControllerMethodsCache methodsCache;

Expand All @@ -51,7 +53,7 @@ public class ConsoleConfig {
@Value("${nacos.deployment.type:merged}")
private String type;

public ConsoleConfig(ControllerMethodsCache methodsCache) {
public ConsoleWebConfig(ControllerMethodsCache methodsCache) {
this.methodsCache = methodsCache;
}

Expand Down Expand Up @@ -96,6 +98,38 @@ public NacosConsoleAuthFilter consoleAuthFilter(ControllerMethodsCache methodsCa
return new NacosConsoleAuthFilter(NacosConsoleAuthConfig.getInstance(), methodsCache);
}

@Bean
public FilterRegistrationBean<ParamCheckerFilter> consoleParamCheckerFilterRegistration(
ParamCheckerFilter consoleParamCheckerFilter) {
FilterRegistrationBean<ParamCheckerFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(consoleParamCheckerFilter);
registration.addUrlPatterns("/*");
registration.setName("consoleParamCheckerFilter");
registration.setOrder(8);
return registration;
}

@Bean
public ParamCheckerFilter consoleParamCheckerFilter(ControllerMethodsCache methodsCache) {
return new ParamCheckerFilter(methodsCache);
}

@Bean
public ApiCompatibilityFilter consoleApiCompatibilityFilter(ControllerMethodsCache methodsCache) {
return new ApiCompatibilityFilter(methodsCache);
}

@Bean
public FilterRegistrationBean<ApiCompatibilityFilter> consoleApiCompatibilityFilterRegistration(
ApiCompatibilityFilter consoleApiCompatibilityFilter) {
FilterRegistrationBean<ApiCompatibilityFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(consoleApiCompatibilityFilter);
registration.addUrlPatterns("/v1/*", "/v2/*");
registration.setName("consoleApiCompatibilityFilter");
registration.setOrder(5);
return registration;
}

@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(ZoneId.systemDefault().toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.console.config;

import com.alibaba.nacos.auth.config.AuthConfigs;
import com.alibaba.nacos.plugin.auth.impl.authenticate.IAuthenticationManager;
import com.alibaba.nacos.plugin.auth.impl.controller.v3.PermissionControllerV3;
import com.alibaba.nacos.plugin.auth.impl.controller.v3.RoleControllerV3;
import com.alibaba.nacos.plugin.auth.impl.controller.v3.UserControllerV3;
import com.alibaba.nacos.plugin.auth.impl.roles.NacosRoleServiceImpl;
import com.alibaba.nacos.plugin.auth.impl.token.TokenManagerDelegate;
import com.alibaba.nacos.plugin.auth.impl.users.NacosUserDetailsServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration of console auth controller.
*
* @author xiweng.yy
*/
@Configuration
@ConditionalOnProperty(value = "nacos.deployment.type", havingValue = "merged")
public class NacosConsoleAuthControllerConfig {

@Bean
public UserControllerV3 consoleUserControllerV3(NacosUserDetailsServiceImpl userDetailsService,
NacosRoleServiceImpl roleService, AuthConfigs authConfigs, IAuthenticationManager iAuthenticationManager,
TokenManagerDelegate jwtTokenManager) {
return new UserControllerV3(userDetailsService, roleService, authConfigs, iAuthenticationManager, jwtTokenManager);
}

@Bean
public RoleControllerV3 consoleRoleControllerV3(NacosRoleServiceImpl roleService) {
return new RoleControllerV3(roleService);
}

@Bean
public PermissionControllerV3 permissionControllerV3(NacosRoleServiceImpl roleService) {
return new PermissionControllerV3(roleService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.model.v2.Result;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.HealthHandler;
import com.alibaba.nacos.console.handler.inner.HealthInnerHandler;
import org.springframework.stereotype.Service;
Expand All @@ -37,9 +37,9 @@ public class HealthProxy {

private final Map<String, HealthHandler> healthHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

public HealthProxy(HealthInnerHandler healthInnerHandler, ConsoleConfig consoleConfig) {
public HealthProxy(HealthInnerHandler healthInnerHandler, ConsoleWebConfig consoleConfig) {
this.healthHandlerMap.put("merged", healthInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus;
import com.alibaba.nacos.config.server.model.SameConfigPolicy;
import com.alibaba.nacos.config.server.model.form.ConfigForm;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.config.ConfigHandler;
import com.alibaba.nacos.console.handler.inner.config.ConfigInnerHandler;
import com.alibaba.nacos.persistence.model.Page;
Expand All @@ -52,10 +52,10 @@ public class ConfigProxy {

private final Map<String, ConfigHandler> configHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

@Autowired
public ConfigProxy(ConfigInnerHandler configInnerHandler, ConsoleConfig consoleConfig) {
public ConfigProxy(ConfigInnerHandler configInnerHandler, ConsoleWebConfig consoleConfig) {
this.configHandlerMap.put("merged", configInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.alibaba.nacos.api.exception.api.NacosApiException;
import com.alibaba.nacos.config.server.model.ConfigHistoryInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.config.HistoryHandler;
import com.alibaba.nacos.console.handler.inner.config.HistoryInnerHandler;
import com.alibaba.nacos.persistence.model.Page;
Expand All @@ -42,7 +42,7 @@ public class HistoryProxy {

private final Map<String, HistoryHandler> historyHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

/**
* Constructs a new HistoryProxy with the given HistoryInnerHandler and ConsoleConfig.
Expand All @@ -51,7 +51,7 @@ public class HistoryProxy {
* @param consoleConfig the console configuration used to determine the deployment type
*/
@Autowired
public HistoryProxy(HistoryInnerHandler historyInnerHandler, ConsoleConfig consoleConfig) {
public HistoryProxy(HistoryInnerHandler historyInnerHandler, ConsoleWebConfig consoleConfig) {
this.historyHandlerMap.put("merged", historyInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.alibaba.nacos.console.proxy.core;

import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.core.ClusterHandler;
import com.alibaba.nacos.console.handler.inner.core.ClusterInnerHandler;
import com.alibaba.nacos.core.cluster.Member;
Expand All @@ -37,15 +37,15 @@ public class ClusterProxy {

private final Map<String, ClusterHandler> clusterHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

/**
* Constructs a new ClusterProxy with the given ClusterInnerHandler and ConsoleConfig.
*
* @param clusterInnerHandler the default implementation of ClusterHandler
* @param consoleConfig the console configuration used to determine the deployment type
*/
public ClusterProxy(ClusterInnerHandler clusterInnerHandler, ConsoleConfig consoleConfig) {
public ClusterProxy(ClusterInnerHandler clusterInnerHandler, ConsoleWebConfig consoleConfig) {
this.clusterHandlerMap.put("merged", clusterInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.alibaba.nacos.console.proxy.core;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.core.NamespaceHandler;
import com.alibaba.nacos.console.handler.inner.core.NamespaceInnerHandler;
import com.alibaba.nacos.core.namespace.model.Namespace;
Expand All @@ -39,9 +39,9 @@ public class NamespaceProxy {

private final Map<String, NamespaceHandler> namespaceHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

public NamespaceProxy(NamespaceInnerHandler namespaceInnerHandler, ConsoleConfig consoleConfig) {
public NamespaceProxy(NamespaceInnerHandler namespaceInnerHandler, ConsoleWebConfig consoleConfig) {
this.namespaceHandlerMap.put("merged", namespaceInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.inner.naming.InstanceInnerHandler;
import com.alibaba.nacos.console.handler.naming.InstanceHandler;
import com.alibaba.nacos.naming.model.form.InstanceForm;
Expand All @@ -39,15 +39,15 @@ public class InstanceProxy {

private final Map<String, InstanceHandler> instanceHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

/**
* Constructs a new InstanceProxy with the given InstanceInnerHandler and ConsoleConfig.
*
* @param instanceInnerHandler the default implementation of InstanceHandler
* @param consoleConfig the console configuration used to determine the deployment type
*/
public InstanceProxy(InstanceInnerHandler instanceInnerHandler, ConsoleConfig consoleConfig) {
public InstanceProxy(InstanceInnerHandler instanceInnerHandler, ConsoleWebConfig consoleConfig) {
this.instanceHandlerMap.put("merged", instanceInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.alibaba.nacos.console.proxy.naming;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.console.config.ConsoleConfig;
import com.alibaba.nacos.console.config.ConsoleWebConfig;
import com.alibaba.nacos.console.handler.inner.naming.ServiceInnerHandler;
import com.alibaba.nacos.console.handler.naming.ServiceHandler;
import com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata;
Expand All @@ -42,7 +42,7 @@ public class ServiceProxy {

private final Map<String, ServiceHandler> serviceHandlerMap = new HashMap<>();

private final ConsoleConfig consoleConfig;
private final ConsoleWebConfig consoleConfig;

/**
* Constructs a new ServiceProxy with the given ServiceInnerHandler and ConsoleConfig. The handler is mapped to a
Expand All @@ -51,7 +51,7 @@ public class ServiceProxy {
* @param serviceInnerHandler the default implementation of ServiceHandler
* @param consoleConfig the console configuration used to determine the deployment type
*/
public ServiceProxy(ServiceInnerHandler serviceInnerHandler, ConsoleConfig consoleConfig) {
public ServiceProxy(ServiceInnerHandler serviceInnerHandler, ConsoleWebConfig consoleConfig) {
this.serviceHandlerMap.put("merged", serviceInnerHandler);
this.consoleConfig = consoleConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions console/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<link rel="stylesheet" type="text/css" href="console-ui/public/css/icon.css">
<link rel="stylesheet" type="text/css" href="console-ui/public/css/font-awesome.css">
<!-- 第三方css结束 -->
<link href="./css/main.css?de2927c59d7a3241fe90" rel="stylesheet"></head>
<link href="./css/main.css?f0b86f8c9f9e1f652597" rel="stylesheet"></head>

<body>
<div id="root" style="overflow:hidden"></div>
Expand All @@ -56,6 +56,6 @@
<script src="console-ui/public/js/merge.js"></script>
<script src="console-ui/public/js/loader.js"></script>
<!-- 第三方js结束 -->
<script type="text/javascript" src="./js/main.js?de2927c59d7a3241fe90"></script></body>
<script type="text/javascript" src="./js/main.js?f0b86f8c9f9e1f652597"></script></body>

</html>
6 changes: 3 additions & 3 deletions console/src/main/resources/static/js/main.js

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -32,7 +31,6 @@
*
* @author wfnuser
*/
@Component
@Deprecated
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {

Expand Down
Loading

0 comments on commit f0ad076

Please sign in to comment.