mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
⬆️ Upgrading dependencies. spring cloud alibaba 2.2.0
This commit is contained in:
1 parent
49966b1096
commit
1635fadc38
39 files changed
+573
-427
No files matched your search
@@ -25,6 +25,7 @@
|
||||
<swagger.core.version>1.5.22</swagger.core.version>
|
||||
<mp.weixin.version>3.6.0</mp.weixin.version>
|
||||
<ijpay.version>1.2.0</ijpay.version>
|
||||
<fastjson.version>1.2.62</fastjson.version>
|
||||
<aliyun.version>3.0.52.ALL</aliyun.version>
|
||||
</properties>
|
||||
|
||||
@@ -129,6 +130,12 @@
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.connector.version}</version>
|
||||
</dependency>
|
||||
<!--fastjson-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
<!--swagger 最新依赖内置版本-->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
|
||||
+14
-7
@@ -17,25 +17,32 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.sentinel;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
||||
import com.pig4cloud.pigx.common.sentinel.handle.PigxUrlBlockHandler;
|
||||
import com.pig4cloud.pigx.common.sentinel.parser.PigxHeaderRequestOriginParser;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020-02-12
|
||||
* <p>
|
||||
* sentinel 配置
|
||||
*/
|
||||
@Configuration
|
||||
public class SentinelAutoConfiguration {
|
||||
|
||||
@PostConstruct
|
||||
public void initWebCallbackManager() {
|
||||
WebCallbackManager.setUrlBlockHandler(new PigxUrlBlockHandler());
|
||||
WebCallbackManager.setRequestOriginParser(new PigxHeaderRequestOriginParser());
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public BlockExceptionHandler blockExceptionHandler() {
|
||||
return new PigxUrlBlockHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RequestOriginParser requestOriginParser(){
|
||||
return new PigxHeaderRequestOriginParser();
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -19,7 +19,7 @@ package com.pig4cloud.pigx.common.sentinel.handle;
|
||||
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -27,7 +27,6 @@ import org.springframework.http.HttpStatus;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -36,10 +35,10 @@ import java.io.IOException;
|
||||
* 降级 限流策略
|
||||
*/
|
||||
@Slf4j
|
||||
public class PigxUrlBlockHandler implements UrlBlockHandler {
|
||||
@Override
|
||||
public void blocked(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException {
|
||||
public class PigxUrlBlockHandler implements BlockExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
|
||||
log.error("sentinel 降级 资源名称{}", e.getRule().getResource(), e);
|
||||
|
||||
response.setContentType(ContentType.JSON.toString());
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.sentinel.parser;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-web-servlet</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
@@ -29,14 +28,11 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-parameter-flow-control</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-api-gateway-adapter-common</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -50,6 +46,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
@@ -82,11 +79,6 @@
|
||||
<artifactId>httpcore-nio</artifactId>
|
||||
<version>4.4.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.58</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 1999-2018 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.csp.sentinel.dashboard.auth;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author lkxiaolou
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface AuthAction {
|
||||
|
||||
/**
|
||||
* @return the privilege type
|
||||
*/
|
||||
AuthService.PrivilegeType value();
|
||||
|
||||
/**
|
||||
* @return the target name to control
|
||||
*/
|
||||
String targetName() default "app";
|
||||
|
||||
/**
|
||||
* @return the message when permission is denied
|
||||
*/
|
||||
String message() default "Permission denied";
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 1999-2018 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.csp.sentinel.dashboard.auth;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.domain.Result;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* The web interceptor for privilege-based authorization.
|
||||
*
|
||||
* @author lkxiaolou
|
||||
* @since 1.7.1
|
||||
*/
|
||||
@Component
|
||||
public class AuthorizationInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
|
||||
Method method = ((HandlerMethod) handler).getMethod();
|
||||
|
||||
AuthAction authAction = method.getAnnotation(AuthAction.class);
|
||||
if (authAction != null) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
if (authUser == null) {
|
||||
responseNoPrivilegeMsg(response, authAction.message());
|
||||
return false;
|
||||
}
|
||||
String target = request.getParameter(authAction.targetName());
|
||||
|
||||
if (!authUser.authTarget(target, authAction.value())) {
|
||||
responseNoPrivilegeMsg(response, authAction.message());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void responseNoPrivilegeMsg(HttpServletResponse response, String message) throws IOException {
|
||||
Result result = Result.ofFail(-1, message);
|
||||
response.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
response.getOutputStream().write(JSON.toJSONBytes(result));
|
||||
}
|
||||
}
|
||||
+26
-19
@@ -13,9 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.filter;
|
||||
package com.alibaba.csp.sentinel.dashboard.auth;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -30,39 +29,46 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Servlet Filter that authenticate requests.
|
||||
* <p>The Servlet filter for authentication.</p>
|
||||
*
|
||||
* Note:
|
||||
* Some urls are excluded as they needn't auth, such as:
|
||||
* <p>Note: some urls are excluded as they needn't auth, such as:</p>
|
||||
* <ul>
|
||||
* <li>index url: {@code /}</li>
|
||||
* <li>authentication request url: {@code /login}, {@code /logout}</li>
|
||||
* <li>machine registry: {@code /registry/machine}</li>
|
||||
* <li>static resources</li>
|
||||
* </ul>
|
||||
*
|
||||
* Index url: /
|
||||
* Authentication request url: /login,logout
|
||||
* Used for client: /registry/machine
|
||||
* Static resources: htm,html,js and so on.
|
||||
*
|
||||
* The excluded urls and urlSuffixes are configured in application.properties
|
||||
* The excluded urls and urlSuffixes could be configured in {@code application.properties} file.
|
||||
*
|
||||
* @author cdfive
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Component
|
||||
public class AuthFilter implements Filter {
|
||||
public class LoginAuthenticationFilter implements Filter {
|
||||
|
||||
private static final String URL_SUFFIX_DOT = ".";
|
||||
|
||||
/**Some urls which needn't auth, such as /auth/login,/registry/machine and so on*/
|
||||
/**
|
||||
* Some urls which needn't auth, such as /auth/login, /registry/machine and so on.
|
||||
*/
|
||||
@Value("#{'${auth.filter.exclude-urls}'.split(',')}")
|
||||
private List<String> authFilterExcludeUrls;
|
||||
|
||||
/**Some urls with suffixes which needn't auth, such as htm,html,js and so on*/
|
||||
/**
|
||||
* Some urls with suffixes which needn't auth, such as htm, html, js and so on.
|
||||
*/
|
||||
@Value("#{'${auth.filter.exclude-url-suffixes}'.split(',')}")
|
||||
private List<String> authFilterExcludeUrlSuffixes;
|
||||
|
||||
/**Authentication using AuthService interface*/
|
||||
/**
|
||||
* Authentication using AuthService interface.
|
||||
*/
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@@ -72,13 +78,14 @@ public class AuthFilter implements Filter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||
|
||||
String requestURI = httpRequest.getRequestURI();
|
||||
String servletPath = httpRequest.getServletPath();
|
||||
|
||||
// Exclude the urls which needn't auth
|
||||
if (authFilterExcludeUrls.contains(requestURI)) {
|
||||
if (authFilterExcludeUrls.contains(servletPath)) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
@@ -94,7 +101,7 @@ public class AuthFilter implements Filter {
|
||||
authFilterExcludeUrlSuffix = URL_SUFFIX_DOT + authFilterExcludeUrlSuffix;
|
||||
}
|
||||
|
||||
if (requestURI.endsWith(authFilterExcludeUrlSuffix)) {
|
||||
if (servletPath.endsWith(authFilterExcludeUrlSuffix)) {
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
+5
-3
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.auth;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -25,16 +26,17 @@ import javax.servlet.http.HttpSession;
|
||||
* @author cdfive
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@Primary
|
||||
@Component
|
||||
@Primary
|
||||
@ConditionalOnProperty(name = "auth.enabled", matchIfMissing = true)
|
||||
public class SimpleWebAuthServiceImpl implements AuthService<HttpServletRequest> {
|
||||
|
||||
public static final String WEB_SESSTION_KEY = "session_sentinel_admin";
|
||||
public static final String WEB_SESSION_KEY = "session_sentinel_admin";
|
||||
|
||||
@Override
|
||||
public AuthUser getAuthUser(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
Object sentinelUserObj = session.getAttribute(SimpleWebAuthServiceImpl.WEB_SESSTION_KEY);
|
||||
Object sentinelUserObj = session.getAttribute(SimpleWebAuthServiceImpl.WEB_SESSION_KEY);
|
||||
if (sentinelUserObj != null && sentinelUserObj instanceof AuthUser) {
|
||||
return (AuthUser) sentinelUserObj;
|
||||
}
|
||||
|
||||
+38
-11
@@ -62,6 +62,7 @@ import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerFlowConfig
|
||||
import com.alibaba.csp.sentinel.dashboard.domain.cluster.config.ServerTransportConfig;
|
||||
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
|
||||
|
||||
import org.apache.http.Consts;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
@@ -175,12 +176,7 @@ public class SentinelApiClient {
|
||||
for (Entry<String, String> entry : params.entrySet()) {
|
||||
list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
try {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(list));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.warn("httpPostContent encode entity error: {}", params, e);
|
||||
return null;
|
||||
}
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(list, Consts.UTF_8));
|
||||
}
|
||||
return httpPost;
|
||||
}
|
||||
@@ -369,17 +365,44 @@ public class SentinelApiClient {
|
||||
params.put("type", type);
|
||||
params.put("data", data);
|
||||
String result = executeCommand(app, ip, port, SET_RULES_PATH, params, true).get();
|
||||
logger.info("setRules: {}", result);
|
||||
logger.info("setRules result: {}, type={}", result, type);
|
||||
return true;
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
logger.warn("setRules api failed: {}", type, e);
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn("setRules API failed: {}", type, e);
|
||||
return false;
|
||||
} catch (ExecutionException e) {
|
||||
logger.warn("setRules API failed: {}", type, e.getCause());
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
logger.warn("setRules failed", e);
|
||||
logger.error("setRules API failed, type={}", type, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setRulesAsync(String app, String ip, int port, String type, List<? extends RuleEntity> entities) {
|
||||
try {
|
||||
AssertUtil.notNull(entities, "rules cannot be null");
|
||||
AssertUtil.notEmpty(app, "Bad app name");
|
||||
AssertUtil.notEmpty(ip, "Bad machine IP");
|
||||
AssertUtil.isTrue(port > 0, "Bad machine port");
|
||||
String data = JSON.toJSONString(
|
||||
entities.stream().map(r -> r.toRule()).collect(Collectors.toList()));
|
||||
Map<String, String> params = new HashMap<>(2);
|
||||
params.put("type", type);
|
||||
params.put("data", data);
|
||||
return executeCommand(app, ip, port, SET_RULES_PATH, params, true)
|
||||
.thenCompose(r -> {
|
||||
if ("success".equalsIgnoreCase(r.trim())) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return AsyncUtils.newFailedFuture(new CommandFailedException(r));
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("setRulesAsync API failed, type={}", type, e);
|
||||
return AsyncUtils.newFailedFuture(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<NodeVo> fetchResourceOfMachine(String ip, int port, String type) {
|
||||
return fetchItems(ip, port, RESOURCE_URL_PATH, type, NodeVo.class);
|
||||
}
|
||||
@@ -393,7 +416,7 @@ public class SentinelApiClient {
|
||||
* @return
|
||||
*/
|
||||
public List<NodeVo> fetchClusterNodeOfMachine(String ip, int port, boolean includeZero) {
|
||||
String type = "noZero";
|
||||
String type = "notZero";
|
||||
if (includeZero) {
|
||||
type = "zero";
|
||||
}
|
||||
@@ -491,6 +514,10 @@ public class SentinelApiClient {
|
||||
return setRules(app, ip, port, FLOW_RULE_TYPE, rules);
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> setFlowRuleOfMachineAsync(String app, String ip, int port, List<FlowRuleEntity> rules) {
|
||||
return setRulesAsync(app, ip, port, FLOW_RULE_TYPE, rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* set rules of the machine. rules == null will return immediately;
|
||||
* rules.isEmpty() means setting the rules to empty.
|
||||
|
||||
+40
-3
@@ -15,18 +15,28 @@
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
|
||||
import com.alibaba.csp.sentinel.dashboard.filter.AuthFilter;
|
||||
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthorizationInterceptor;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.LoginAuthenticationFilter;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.Filter;
|
||||
|
||||
/**
|
||||
@@ -38,7 +48,15 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
private final Logger logger = LoggerFactory.getLogger(WebConfig.class);
|
||||
|
||||
@Autowired
|
||||
private AuthFilter authFilter;
|
||||
private LoginAuthenticationFilter loginAuthenticationFilter;
|
||||
|
||||
@Autowired
|
||||
private AuthorizationInterceptor authorizationInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authorizationInterceptor).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
@@ -61,16 +79,35 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("sentinelFilter");
|
||||
registration.setOrder(1);
|
||||
// If this is enabled, the entrance of all Web URL resources will be unified as a single context name.
|
||||
// In most scenarios that's enough, and it could reduce the memory footprint.
|
||||
registration.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "true");
|
||||
|
||||
logger.info("Sentinel servlet CommonFilter registered");
|
||||
|
||||
return registration;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void doInit() {
|
||||
Set<String> suffixSet = new HashSet<>(Arrays.asList(".js", ".css", ".html", ".ico", ".txt",
|
||||
".woff", ".woff2"));
|
||||
// Example: register a UrlCleaner to exclude URLs of common static resources.
|
||||
WebCallbackManager.setUrlCleaner(url -> {
|
||||
if (StringUtil.isEmpty(url)) {
|
||||
return url;
|
||||
}
|
||||
if (suffixSet.stream().anyMatch(url::endsWith)) {
|
||||
return null;
|
||||
}
|
||||
return url;
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean authenticationFilterRegistration() {
|
||||
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(authFilter);
|
||||
registration.setFilter(loginAuthenticationFilter);
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("authenticationFilter");
|
||||
registration.setOrder(0);
|
||||
|
||||
+19
-7
@@ -22,10 +22,10 @@ import com.alibaba.csp.sentinel.dashboard.domain.Result;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(AuthController.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AuthController.class);
|
||||
|
||||
@Value("${auth.username:sentinel}")
|
||||
private String authUsername;
|
||||
@@ -46,8 +46,11 @@ public class AuthController {
|
||||
@Value("${auth.password:sentinel}")
|
||||
private String authPassword;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public Result login(HttpServletRequest request, String username, String password) {
|
||||
public Result<AuthService.AuthUser> login(HttpServletRequest request, String username, String password) {
|
||||
if (StringUtils.isNotBlank(DashboardConfig.getAuthUsername())) {
|
||||
authUsername = DashboardConfig.getAuthUsername();
|
||||
}
|
||||
@@ -63,18 +66,27 @@ public class AuthController {
|
||||
*/
|
||||
if (StringUtils.isNotBlank(authUsername) && !authUsername.equals(username)
|
||||
|| StringUtils.isNotBlank(authPassword) && !authPassword.equals(password)) {
|
||||
LOGGER.error("Login failed: Invalid username or password, username=" + username + ", password=" + password);
|
||||
LOGGER.error("Login failed: Invalid username or password, username=" + username);
|
||||
return Result.ofFail(-1, "Invalid username or password");
|
||||
}
|
||||
|
||||
AuthService.AuthUser authUser = new SimpleWebAuthServiceImpl.SimpleWebAuthUserImpl(username);
|
||||
request.getSession().setAttribute(SimpleWebAuthServiceImpl.WEB_SESSTION_KEY, authUser);
|
||||
request.getSession().setAttribute(SimpleWebAuthServiceImpl.WEB_SESSION_KEY, authUser);
|
||||
return Result.ofSuccess(authUser);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/logout", method = RequestMethod.POST)
|
||||
public Result logout(HttpServletRequest request) {
|
||||
@PostMapping(value = "/logout")
|
||||
public Result<?> logout(HttpServletRequest request) {
|
||||
request.getSession().invalidate();
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/check")
|
||||
public Result<?> check(HttpServletRequest request) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
if (authUser == null) {
|
||||
return Result.ofFail(-1, "Not logged in");
|
||||
}
|
||||
return Result.ofSuccess(authUser);
|
||||
}
|
||||
}
|
||||
+9
-22
@@ -18,12 +18,9 @@ package com.alibaba.csp.sentinel.dashboard.controller;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
@@ -60,16 +57,11 @@ public class AuthorityRuleController {
|
||||
@Autowired
|
||||
private RuleRepository<AuthorityRuleEntity, Long> repository;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@GetMapping("/rules")
|
||||
public Result<List<AuthorityRuleEntity>> apiQueryAllRulesForMachine(HttpServletRequest request,
|
||||
@RequestParam String app,
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<AuthorityRuleEntity>> apiQueryAllRulesForMachine(@RequestParam String app,
|
||||
@RequestParam String ip,
|
||||
@RequestParam Integer port) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app cannot be null or empty");
|
||||
}
|
||||
@@ -119,10 +111,8 @@ public class AuthorityRuleController {
|
||||
}
|
||||
|
||||
@PostMapping("/rule")
|
||||
public Result<AuthorityRuleEntity> apiAddAuthorityRule(HttpServletRequest request,
|
||||
@RequestBody AuthorityRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<AuthorityRuleEntity> apiAddAuthorityRule(@RequestBody AuthorityRuleEntity entity) {
|
||||
Result<AuthorityRuleEntity> checkResult = checkEntityInternal(entity);
|
||||
if (checkResult != null) {
|
||||
return checkResult;
|
||||
@@ -144,11 +134,9 @@ public class AuthorityRuleController {
|
||||
}
|
||||
|
||||
@PutMapping("/rule/{id}")
|
||||
public Result<AuthorityRuleEntity> apiUpdateParamFlowRule(HttpServletRequest request,
|
||||
@PathVariable("id") Long id,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<AuthorityRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id,
|
||||
@RequestBody AuthorityRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
if (id == null || id <= 0) {
|
||||
return Result.ofFail(-1, "Invalid id");
|
||||
}
|
||||
@@ -176,8 +164,8 @@ public class AuthorityRuleController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/rule/{id}")
|
||||
public Result<Long> apiDeleteRule(HttpServletRequest request, @PathVariable("id") Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.DELETE_RULE)
|
||||
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id cannot be null");
|
||||
}
|
||||
@@ -185,7 +173,6 @@ public class AuthorityRuleController {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Exception e) {
|
||||
|
||||
+11
-22
@@ -18,12 +18,9 @@ package com.alibaba.csp.sentinel.dashboard.controller;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
@@ -54,14 +51,10 @@ public class DegradeController {
|
||||
@Autowired
|
||||
private SentinelApiClient sentinelApiClient;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/rules.json")
|
||||
public Result<List<DegradeRuleEntity>> queryMachineRules(HttpServletRequest request, String app, String ip, Integer port) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<DegradeRuleEntity>> queryMachineRules(String app, String ip, Integer port) {
|
||||
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
@@ -84,12 +77,9 @@ public class DegradeController {
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/new.json")
|
||||
public Result<DegradeRuleEntity> add(HttpServletRequest request,
|
||||
String app, String ip, Integer port, String limitApp, String resource,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<DegradeRuleEntity> add(String app, String ip, Integer port, String limitApp, String resource,
|
||||
Double count, Integer timeWindow, Integer grade) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.WRITE_RULE);
|
||||
|
||||
if (StringUtil.isBlank(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
}
|
||||
@@ -143,10 +133,9 @@ public class DegradeController {
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/save.json")
|
||||
public Result<DegradeRuleEntity> updateIfNotNull(HttpServletRequest request,
|
||||
Long id, String app, String limitApp, String resource,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<DegradeRuleEntity> updateIfNotNull(Long id, String app, String limitApp, String resource,
|
||||
Double count, Integer timeWindow, Integer grade) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -159,7 +148,7 @@ public class DegradeController {
|
||||
if (entity == null) {
|
||||
return Result.ofFail(-1, "id " + id + " dose not exist");
|
||||
}
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
|
||||
if (StringUtil.isNotBlank(app)) {
|
||||
entity.setApp(app.trim());
|
||||
}
|
||||
@@ -195,8 +184,8 @@ public class DegradeController {
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/delete.json")
|
||||
public Result<Long> delete(HttpServletRequest request, Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.DELETE_RULE)
|
||||
public Result<Long> delete(Long id) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -205,7 +194,7 @@ public class DegradeController {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
+40
-41
@@ -17,11 +17,11 @@ package com.alibaba.csp.sentinel.dashboard.controller;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
|
||||
@@ -57,19 +57,15 @@ public class FlowControllerV1 {
|
||||
|
||||
@Autowired
|
||||
private InMemoryRuleRepositoryAdapter<FlowRuleEntity> repository;
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@Autowired
|
||||
private SentinelApiClient sentinelApiClient;
|
||||
|
||||
@GetMapping("/rules")
|
||||
public Result<List<FlowRuleEntity>> apiQueryMachineRules(HttpServletRequest request,
|
||||
@RequestParam String app,
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<FlowRuleEntity>> apiQueryMachineRules(@RequestParam String app,
|
||||
@RequestParam String ip,
|
||||
@RequestParam Integer port) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
@@ -138,10 +134,8 @@ public class FlowControllerV1 {
|
||||
}
|
||||
|
||||
@PostMapping("/rule")
|
||||
public Result<FlowRuleEntity> apiAddFlowRule(HttpServletRequest request, @RequestBody FlowRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<FlowRuleEntity> apiAddFlowRule(@RequestBody FlowRuleEntity entity) {
|
||||
Result<FlowRuleEntity> checkResult = checkEntityInternal(entity);
|
||||
if (checkResult != null) {
|
||||
return checkResult;
|
||||
@@ -154,25 +148,23 @@ public class FlowControllerV1 {
|
||||
entity.setResource(entity.getResource().trim());
|
||||
try {
|
||||
entity = repository.save(entity);
|
||||
} catch (Throwable throwable) {
|
||||
logger.error("Failed to add flow rule", throwable);
|
||||
return Result.ofThrowable(-1, throwable);
|
||||
|
||||
publishRules(entity.getApp(), entity.getIp(), entity.getPort()).get(5000, TimeUnit.MILLISECONDS);
|
||||
return Result.ofSuccess(entity);
|
||||
} catch (Throwable t) {
|
||||
Throwable e = t instanceof ExecutionException ? t.getCause() : t;
|
||||
logger.error("Failed to add new flow rule, app={}, ip={}", entity.getApp(), entity.getIp(), e);
|
||||
return Result.ofFail(-1, e.getMessage());
|
||||
}
|
||||
if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) {
|
||||
logger.error("Publish flow rules failed after rule add");
|
||||
}
|
||||
return Result.ofSuccess(entity);
|
||||
}
|
||||
|
||||
@PutMapping("/save.json")
|
||||
public Result<FlowRuleEntity> updateIfNotNull(HttpServletRequest request, Long id, String app,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<FlowRuleEntity> apiUpdateFlowRule(Long id, String app,
|
||||
String limitApp, String resource, Integer grade,
|
||||
Double count, Integer strategy, String refResource,
|
||||
Integer controlBehavior, Integer warmUpPeriodSec,
|
||||
Integer maxQueueingTimeMs) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.WRITE_RULE);
|
||||
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -233,21 +225,23 @@ public class FlowControllerV1 {
|
||||
try {
|
||||
entity = repository.save(entity);
|
||||
if (entity == null) {
|
||||
return Result.ofFail(-1, "save entity fail");
|
||||
return Result.ofFail(-1, "save entity fail: null");
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
logger.error("save error:", throwable);
|
||||
return Result.ofThrowable(-1, throwable);
|
||||
|
||||
publishRules(entity.getApp(), entity.getIp(), entity.getPort()).get(5000, TimeUnit.MILLISECONDS);
|
||||
return Result.ofSuccess(entity);
|
||||
} catch (Throwable t) {
|
||||
Throwable e = t instanceof ExecutionException ? t.getCause() : t;
|
||||
logger.error("Error when updating flow rules, app={}, ip={}, ruleId={}", entity.getApp(),
|
||||
entity.getIp(), id, e);
|
||||
return Result.ofFail(-1, e.getMessage());
|
||||
}
|
||||
if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) {
|
||||
logger.info("publish flow rules fail after rule update");
|
||||
}
|
||||
return Result.ofSuccess(entity);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete.json")
|
||||
public Result<Long> delete(HttpServletRequest request, Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<Long> apiDeleteFlowRule(Long id) {
|
||||
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -255,20 +249,25 @@ public class FlowControllerV1 {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Exception e) {
|
||||
return Result.ofFail(-1, e.getMessage());
|
||||
}
|
||||
if (!publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort())) {
|
||||
logger.info("publish flow rules fail after rule delete");
|
||||
try {
|
||||
publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort()).get(5000, TimeUnit.MILLISECONDS);
|
||||
return Result.ofSuccess(id);
|
||||
} catch (Throwable t) {
|
||||
Throwable e = t instanceof ExecutionException ? t.getCause() : t;
|
||||
logger.error("Error when deleting flow rules, app={}, ip={}, id={}", oldEntity.getApp(),
|
||||
oldEntity.getIp(), id, e);
|
||||
return Result.ofFail(-1, e.getMessage());
|
||||
}
|
||||
return Result.ofSuccess(id);
|
||||
}
|
||||
|
||||
private boolean publishRules(String app, String ip, Integer port) {
|
||||
private CompletableFuture<Void> publishRules(String app, String ip, Integer port) {
|
||||
List<FlowRuleEntity> rules = repository.findAllByMachine(MachineInfo.of(app, ip, port));
|
||||
return sentinelApiClient.setFlowRuleOfMachine(app, ip, port, rules);
|
||||
return sentinelApiClient.setFlowRuleOfMachineAsync(app, ip, port, rules);
|
||||
}
|
||||
}
|
||||
+28
-49
@@ -15,43 +15,30 @@
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.controller;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
|
||||
import com.alibaba.csp.sentinel.dashboard.domain.Result;
|
||||
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
|
||||
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement;
|
||||
import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion;
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity;
|
||||
import com.alibaba.csp.sentinel.dashboard.domain.Result;
|
||||
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
|
||||
import com.alibaba.csp.sentinel.dashboard.util.VersionUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author Eric Zhao
|
||||
* @since 0.2.1
|
||||
@@ -69,9 +56,6 @@ public class ParamFlowRuleController {
|
||||
@Autowired
|
||||
private RuleRepository<ParamFlowRuleEntity, Long> repository;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
private boolean checkIfSupported(String app, String ip, int port) {
|
||||
try {
|
||||
return Optional.ofNullable(appManagement.getDetailApp(app))
|
||||
@@ -86,12 +70,10 @@ public class ParamFlowRuleController {
|
||||
}
|
||||
|
||||
@GetMapping("/rules")
|
||||
public Result<List<ParamFlowRuleEntity>> apiQueryAllRulesForMachine(HttpServletRequest request,
|
||||
@RequestParam String app,
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<ParamFlowRuleEntity>> apiQueryAllRulesForMachine(@RequestParam String app,
|
||||
@RequestParam String ip,
|
||||
@RequestParam Integer port) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app cannot be null or empty");
|
||||
}
|
||||
@@ -127,10 +109,8 @@ public class ParamFlowRuleController {
|
||||
}
|
||||
|
||||
@PostMapping("/rule")
|
||||
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(HttpServletRequest request,
|
||||
@RequestBody ParamFlowRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<ParamFlowRuleEntity> apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) {
|
||||
Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
|
||||
if (checkResult != null) {
|
||||
return checkResult;
|
||||
@@ -198,10 +178,9 @@ public class ParamFlowRuleController {
|
||||
}
|
||||
|
||||
@PutMapping("/rule/{id}")
|
||||
public Result<ParamFlowRuleEntity> apiUpdateParamFlowRule(HttpServletRequest request,
|
||||
@PathVariable("id") Long id,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<ParamFlowRuleEntity> apiUpdateParamFlowRule(@PathVariable("id") Long id,
|
||||
@RequestBody ParamFlowRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
if (id == null || id <= 0) {
|
||||
return Result.ofFail(-1, "Invalid id");
|
||||
}
|
||||
@@ -209,7 +188,7 @@ public class ParamFlowRuleController {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofFail(-1, "id " + id + " does not exist");
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
|
||||
Result<ParamFlowRuleEntity> checkResult = checkEntityInternal(entity);
|
||||
if (checkResult != null) {
|
||||
return checkResult;
|
||||
@@ -239,8 +218,8 @@ public class ParamFlowRuleController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/rule/{id}")
|
||||
public Result<Long> apiDeleteRule(HttpServletRequest request, @PathVariable("id") Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.DELETE_RULE)
|
||||
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id cannot be null");
|
||||
}
|
||||
@@ -248,7 +227,7 @@ public class ParamFlowRuleController {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort()).get();
|
||||
|
||||
+11
-21
@@ -18,10 +18,7 @@ package com.alibaba.csp.sentinel.dashboard.controller;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
@@ -51,8 +48,6 @@ public class SystemController {
|
||||
private RuleRepository<SystemRuleEntity, Long> repository;
|
||||
@Autowired
|
||||
private SentinelApiClient sentinelApiClient;
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
private <R> Result<R> checkBasicParams(String app, String ip, Integer port) {
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
@@ -71,11 +66,9 @@ public class SystemController {
|
||||
}
|
||||
|
||||
@GetMapping("/rules.json")
|
||||
public Result<List<SystemRuleEntity>> apiQueryMachineRules(HttpServletRequest request, String app, String ip,
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<SystemRuleEntity>> apiQueryMachineRules(String app, String ip,
|
||||
Integer port) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
|
||||
Result<List<SystemRuleEntity>> checkResult = checkBasicParams(app, ip, port);
|
||||
if (checkResult != null) {
|
||||
return checkResult;
|
||||
@@ -101,11 +94,10 @@ public class SystemController {
|
||||
}
|
||||
|
||||
@RequestMapping("/new.json")
|
||||
public Result<SystemRuleEntity> apiAdd(HttpServletRequest request, String app, String ip, Integer port,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<SystemRuleEntity> apiAdd(String app, String ip, Integer port,
|
||||
Double highestSystemLoad, Double highestCpuUsage, Long avgRt,
|
||||
Long maxThread, Double qps) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.WRITE_RULE);
|
||||
|
||||
Result<SystemRuleEntity> checkResult = checkBasicParams(app, ip, port);
|
||||
if (checkResult != null) {
|
||||
@@ -168,10 +160,9 @@ public class SystemController {
|
||||
}
|
||||
|
||||
@GetMapping("/save.json")
|
||||
public Result<SystemRuleEntity> apiUpdateIfNotNull(HttpServletRequest request,
|
||||
Long id, String app, Double highestSystemLoad, Double highestCpuUsage,
|
||||
Long avgRt, Long maxThread, Double qps) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
public Result<SystemRuleEntity> apiUpdateIfNotNull(Long id, String app, Double highestSystemLoad,
|
||||
Double highestCpuUsage, Long avgRt, Long maxThread, Double qps) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -179,7 +170,7 @@ public class SystemController {
|
||||
if (entity == null) {
|
||||
return Result.ofFail(-1, "id " + id + " dose not exist");
|
||||
}
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
|
||||
if (StringUtil.isNotBlank(app)) {
|
||||
entity.setApp(app.trim());
|
||||
}
|
||||
@@ -231,8 +222,8 @@ public class SystemController {
|
||||
}
|
||||
|
||||
@RequestMapping("/delete.json")
|
||||
public Result<?> delete(HttpServletRequest request, Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.DELETE_RULE)
|
||||
public Result<?> delete(Long id) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -240,7 +231,6 @@ public class SystemController {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 1999-2018 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.csp.sentinel.dashboard.controller;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.domain.Result;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author hisenyuan
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RestController
|
||||
public class VersionController {
|
||||
|
||||
private static final String VERSION_PATTERN = "-";
|
||||
|
||||
@Value("${sentinel.dashboard.version:}")
|
||||
private String sentinelDashboardVersion;
|
||||
|
||||
@GetMapping("/version")
|
||||
public Result<String> apiGetVersion() {
|
||||
if (StringUtil.isNotBlank(sentinelDashboardVersion)) {
|
||||
String res = sentinelDashboardVersion;
|
||||
if (sentinelDashboardVersion.contains(VERSION_PATTERN)) {
|
||||
res = sentinelDashboardVersion.substring(0, sentinelDashboardVersion.indexOf(VERSION_PATTERN));
|
||||
}
|
||||
return Result.ofSuccess(res);
|
||||
} else {
|
||||
return Result.ofFail(1, "getVersion failed: empty version");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-18
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.controller.gateway;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity;
|
||||
@@ -55,13 +56,9 @@ public class GatewayApiController {
|
||||
@Autowired
|
||||
private SentinelApiClient sentinelApiClient;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@GetMapping("/list.json")
|
||||
public Result<List<ApiDefinitionEntity>> queryApis(HttpServletRequest request, String app, String ip, Integer port) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.READ_RULE);
|
||||
@AuthAction(AuthService.PrivilegeType.READ_RULE)
|
||||
public Result<List<ApiDefinitionEntity>> queryApis(String app, String ip, Integer port) {
|
||||
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
@@ -84,16 +81,14 @@ public class GatewayApiController {
|
||||
}
|
||||
|
||||
@PostMapping("/new.json")
|
||||
@AuthAction(AuthService.PrivilegeType.WRITE_RULE)
|
||||
public Result<ApiDefinitionEntity> addApi(HttpServletRequest request, @RequestBody AddApiReqVo reqVo) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
|
||||
String app = reqVo.getApp();
|
||||
if (StringUtil.isBlank(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
}
|
||||
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
|
||||
|
||||
ApiDefinitionEntity entity = new ApiDefinitionEntity();
|
||||
entity.setApp(app.trim());
|
||||
|
||||
@@ -169,16 +164,13 @@ public class GatewayApiController {
|
||||
}
|
||||
|
||||
@PostMapping("/save.json")
|
||||
public Result<ApiDefinitionEntity> updateApi(HttpServletRequest request, @RequestBody UpdateApiReqVo reqVo) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
|
||||
@AuthAction(AuthService.PrivilegeType.WRITE_RULE)
|
||||
public Result<ApiDefinitionEntity> updateApi(@RequestBody UpdateApiReqVo reqVo) {
|
||||
String app = reqVo.getApp();
|
||||
if (StringUtil.isBlank(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
}
|
||||
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
|
||||
|
||||
Long id = reqVo.getId();
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
@@ -235,9 +227,9 @@ public class GatewayApiController {
|
||||
}
|
||||
|
||||
@PostMapping("/delete.json")
|
||||
public Result<Long> deleteApi(HttpServletRequest request, Long id) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(AuthService.PrivilegeType.DELETE_RULE)
|
||||
|
||||
public Result<Long> deleteApi(Long id) {
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
}
|
||||
@@ -247,8 +239,6 @@ public class GatewayApiController {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
|
||||
authUser.authTarget(oldEntity.getApp(), AuthService.PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
+9
-19
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.csp.sentinel.dashboard.controller.gateway;
|
||||
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
|
||||
import com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity;
|
||||
@@ -32,7 +33,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -59,13 +59,9 @@ public class GatewayFlowRuleController {
|
||||
@Autowired
|
||||
private SentinelApiClient sentinelApiClient;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@GetMapping("/list.json")
|
||||
public Result<List<GatewayFlowRuleEntity>> queryFlowRules(HttpServletRequest request, String app, String ip, Integer port) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.READ_RULE);
|
||||
@AuthAction(AuthService.PrivilegeType.READ_RULE)
|
||||
public Result<List<GatewayFlowRuleEntity>> queryFlowRules(String app, String ip, Integer port) {
|
||||
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
@@ -88,16 +84,14 @@ public class GatewayFlowRuleController {
|
||||
}
|
||||
|
||||
@PostMapping("/new.json")
|
||||
public Result<GatewayFlowRuleEntity> addFlowRule(HttpServletRequest request, @RequestBody AddFlowRuleReqVo reqVo) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(AuthService.PrivilegeType.WRITE_RULE)
|
||||
public Result<GatewayFlowRuleEntity> addFlowRule(@RequestBody AddFlowRuleReqVo reqVo) {
|
||||
|
||||
String app = reqVo.getApp();
|
||||
if (StringUtil.isBlank(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
}
|
||||
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
|
||||
|
||||
GatewayFlowRuleEntity entity = new GatewayFlowRuleEntity();
|
||||
entity.setApp(app.trim());
|
||||
|
||||
@@ -258,16 +252,14 @@ public class GatewayFlowRuleController {
|
||||
}
|
||||
|
||||
@PostMapping("/save.json")
|
||||
public Result<GatewayFlowRuleEntity> updateFlowRule(HttpServletRequest request, @RequestBody UpdateFlowRuleReqVo reqVo) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(AuthService.PrivilegeType.WRITE_RULE)
|
||||
public Result<GatewayFlowRuleEntity> updateFlowRule(@RequestBody UpdateFlowRuleReqVo reqVo) {
|
||||
|
||||
String app = reqVo.getApp();
|
||||
if (StringUtil.isBlank(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
}
|
||||
|
||||
authUser.authTarget(app, AuthService.PrivilegeType.WRITE_RULE);
|
||||
|
||||
Long id = reqVo.getId();
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
@@ -408,8 +400,8 @@ public class GatewayFlowRuleController {
|
||||
|
||||
|
||||
@PostMapping("/delete.json")
|
||||
public Result<Long> deleteFlowRule(HttpServletRequest request, Long id) {
|
||||
AuthService.AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(AuthService.PrivilegeType.DELETE_RULE)
|
||||
public Result<Long> deleteFlowRule(Long id) {
|
||||
|
||||
if (id == null) {
|
||||
return Result.ofFail(-1, "id can't be null");
|
||||
@@ -420,8 +412,6 @@ public class GatewayFlowRuleController {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
|
||||
authUser.authTarget(oldEntity.getApp(), AuthService.PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
+11
-19
@@ -18,10 +18,8 @@ package com.alibaba.csp.sentinel.dashboard.controller.v2;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthAction;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser;
|
||||
import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
|
||||
@@ -67,13 +65,9 @@ public class FlowControllerV2 {
|
||||
@Qualifier("flowRuleDefaultPublisher")
|
||||
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
|
||||
|
||||
@Autowired
|
||||
private AuthService<HttpServletRequest> authService;
|
||||
|
||||
@GetMapping("/rules")
|
||||
public Result<List<FlowRuleEntity>> apiQueryMachineRules(HttpServletRequest request, @RequestParam String app) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(app, PrivilegeType.READ_RULE);
|
||||
@AuthAction(PrivilegeType.READ_RULE)
|
||||
public Result<List<FlowRuleEntity>> apiQueryMachineRules(@RequestParam String app) {
|
||||
|
||||
if (StringUtil.isEmpty(app)) {
|
||||
return Result.ofFail(-1, "app can't be null or empty");
|
||||
@@ -141,9 +135,8 @@ public class FlowControllerV2 {
|
||||
}
|
||||
|
||||
@PostMapping("/rule")
|
||||
public Result<FlowRuleEntity> apiAddFlowRule(HttpServletRequest request, @RequestBody FlowRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
authUser.authTarget(entity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
@AuthAction(value = PrivilegeType.WRITE_RULE)
|
||||
public Result<FlowRuleEntity> apiAddFlowRule(@RequestBody FlowRuleEntity entity) {
|
||||
|
||||
Result<FlowRuleEntity> checkResult = checkEntityInternal(entity);
|
||||
if (checkResult != null) {
|
||||
@@ -166,10 +159,10 @@ public class FlowControllerV2 {
|
||||
}
|
||||
|
||||
@PutMapping("/rule/{id}")
|
||||
public Result<FlowRuleEntity> apiUpdateFlowRule(HttpServletRequest request,
|
||||
@PathVariable("id") Long id,
|
||||
@AuthAction(PrivilegeType.WRITE_RULE)
|
||||
|
||||
public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id,
|
||||
@RequestBody FlowRuleEntity entity) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
if (id == null || id <= 0) {
|
||||
return Result.ofFail(-1, "Invalid id");
|
||||
}
|
||||
@@ -180,7 +173,6 @@ public class FlowControllerV2 {
|
||||
if (entity == null) {
|
||||
return Result.ofFail(-1, "invalid body");
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.WRITE_RULE);
|
||||
|
||||
entity.setApp(oldEntity.getApp());
|
||||
entity.setIp(oldEntity.getIp());
|
||||
@@ -208,8 +200,8 @@ public class FlowControllerV2 {
|
||||
}
|
||||
|
||||
@DeleteMapping("/rule/{id}")
|
||||
public Result<Long> apiDeleteRule(HttpServletRequest request, @PathVariable("id") Long id) {
|
||||
AuthUser authUser = authService.getAuthUser(request);
|
||||
@AuthAction(PrivilegeType.DELETE_RULE)
|
||||
public Result<Long> apiDeleteRule(@PathVariable("id") Long id) {
|
||||
if (id == null || id <= 0) {
|
||||
return Result.ofFail(-1, "Invalid id");
|
||||
}
|
||||
@@ -217,7 +209,7 @@ public class FlowControllerV2 {
|
||||
if (oldEntity == null) {
|
||||
return Result.ofSuccess(null);
|
||||
}
|
||||
authUser.authTarget(oldEntity.getApp(), PrivilegeType.DELETE_RULE);
|
||||
|
||||
try {
|
||||
repository.delete(id);
|
||||
publishRules(oldEntity.getApp());
|
||||
|
||||
+6
-2
@@ -17,7 +17,7 @@ package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
|
||||
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
|
||||
import com.alibaba.csp.sentinel.util.AssertUtil;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
*/
|
||||
public class AuthorityRuleEntity extends AbstractRuleEntity<AuthorityRule> {
|
||||
|
||||
public AuthorityRuleEntity() {}
|
||||
public AuthorityRuleEntity() {
|
||||
}
|
||||
|
||||
public AuthorityRuleEntity(AuthorityRule authorityRule) {
|
||||
AssertUtil.notNull(authorityRule, "Authority rule should not be null");
|
||||
@@ -42,16 +43,19 @@ public class AuthorityRuleEntity extends AbstractRuleEntity<AuthorityRule> {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public String getLimitApp() {
|
||||
return rule.getLimitApp();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public String getResource() {
|
||||
return rule.getResource();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public int getStrategy() {
|
||||
return rule.getStrategy();
|
||||
}
|
||||
|
||||
+17
-4
@@ -15,22 +15,23 @@
|
||||
*/
|
||||
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowClusterConfig;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowItem;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||
import com.alibaba.csp.sentinel.util.AssertUtil;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eric Zhao
|
||||
* @since 0.2.1
|
||||
*/
|
||||
public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
|
||||
|
||||
public ParamFlowRuleEntity() {}
|
||||
public ParamFlowRuleEntity() {
|
||||
}
|
||||
|
||||
public ParamFlowRuleEntity(ParamFlowRule rule) {
|
||||
AssertUtil.notNull(rule, "Authority rule should not be null");
|
||||
@@ -46,61 +47,73 @@ public class ParamFlowRuleEntity extends AbstractRuleEntity<ParamFlowRule> {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public String getLimitApp() {
|
||||
return rule.getLimitApp();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public String getResource() {
|
||||
return rule.getResource();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public int getGrade() {
|
||||
return rule.getGrade();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public Integer getParamIdx() {
|
||||
return rule.getParamIdx();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public double getCount() {
|
||||
return rule.getCount();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public List<ParamFlowItem> getParamFlowItemList() {
|
||||
return rule.getParamFlowItemList();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public int getControlBehavior() {
|
||||
return rule.getControlBehavior();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public int getMaxQueueingTimeMs() {
|
||||
return rule.getMaxQueueingTimeMs();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public int getBurstCount() {
|
||||
return rule.getBurstCount();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public long getDurationInSec() {
|
||||
return rule.getDurationInSec();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public boolean isClusterMode() {
|
||||
return rule.isClusterMode();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@JSONField(serialize = false)
|
||||
public ParamFlowClusterConfig getClusterConfig() {
|
||||
return rule.getClusterConfig();
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class ResourceTreeNode {
|
||||
ResourceTreeNode node = fromNodeVo(vo);
|
||||
map.put(node.id, node);
|
||||
// real root
|
||||
if (node.parentId == null) {
|
||||
if (node.parentId == null || node.parentId.isEmpty()) {
|
||||
root = node;
|
||||
} else if (map.containsKey(node.parentId)) {
|
||||
map.get(node.parentId).children.add(node);
|
||||
|
||||
@@ -19,5 +19,9 @@ auth:
|
||||
username: sentinel
|
||||
password: sentinel
|
||||
filter:
|
||||
exclude-urls: /,/auth/login,/auth/logout,/registry/machine
|
||||
exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/version
|
||||
exclude-url-suffixes: htm,html,js,css,map,ico,ttf,woff,png
|
||||
|
||||
sentinel:
|
||||
dashboard:
|
||||
version: 1.7.1
|
||||
@@ -1,32 +0,0 @@
|
||||
# Sentinel Dashboard Frontend
|
||||
|
||||
## Env Requirement
|
||||
|
||||
- Node.js > 6.x
|
||||
|
||||
## Code Guide
|
||||
|
||||
- [Code Style Guide for HTML/CSS](https://codeguide.bootcss.com/)
|
||||
- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript/tree/es5-deprecated/es5)
|
||||
|
||||
## Install Packages
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
## Start Development
|
||||
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
||||
## Build for production
|
||||
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Credit
|
||||
|
||||
- [sb-admin-angular](https://github.com/start-angular/sb-admin-angular)
|
||||
@@ -1,32 +0,0 @@
|
||||
# Sentinel Dashboard Frontend
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Node.js > 6.x
|
||||
|
||||
## 编码规范
|
||||
|
||||
- HTML/CSS 遵循 [Bootstrap 编码规范](https://codeguide.bootcss.com/)
|
||||
- JavaScript 遵循 [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript/tree/es5-deprecated/es5) 以及最新的 ES 6 标准
|
||||
|
||||
## 安装依赖
|
||||
|
||||
```
|
||||
npm i
|
||||
```
|
||||
|
||||
## 开始本地开发
|
||||
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
||||
## 构建前端资源
|
||||
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Credit
|
||||
|
||||
- [sb-admin-angular](https://github.com/start-angular/sb-admin-angular)
|
||||
+5
-5
@@ -148,18 +148,18 @@ app.controller('FlowControllerV1', ['$scope', '$stateParams', 'FlowServiceV1', '
|
||||
getMachineRules();
|
||||
confirmDialog.close();
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function addNewRule(rule) {
|
||||
FlowService.newRule(rule).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
if (data.code === 0) {
|
||||
getMachineRules();
|
||||
flowRuleDialog.close();
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -173,7 +173,7 @@ app.controller('FlowControllerV1', ['$scope', '$stateParams', 'FlowServiceV1', '
|
||||
|
||||
function saveRule(rule, edit) {
|
||||
FlowService.saveRule(rule).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
if (data.code === 0) {
|
||||
getMachineRules();
|
||||
if (edit) {
|
||||
flowRuleDialog.close();
|
||||
@@ -181,7 +181,7 @@ app.controller('FlowControllerV1', ['$scope', '$stateParams', 'FlowServiceV1', '
|
||||
confirmDialog.close();
|
||||
}
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-7
@@ -98,7 +98,7 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
|
||||
let url = '/dashboard/flow/' + $scope.app;
|
||||
$location.path(url);
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
}).error((data, header, config, status) => {
|
||||
alert('未知错误');
|
||||
@@ -110,10 +110,10 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
|
||||
return;
|
||||
}
|
||||
FlowService.newRule(flowRuleDialogScope.currentRule).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
if (data.code === 0) {
|
||||
flowRuleDialog.close();
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -159,12 +159,12 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
|
||||
return;
|
||||
}
|
||||
DegradeService.newRule(degradeRuleDialogScope.currentRule).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
if (data.code === 0) {
|
||||
degradeRuleDialog.close();
|
||||
var url = '/dashboard/degrade/' + $scope.app;
|
||||
$location.path(url);
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -174,10 +174,10 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
|
||||
return;
|
||||
}
|
||||
DegradeService.newRule(degradeRuleDialogScope.currentRule).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
if (data.code === 0) {
|
||||
degradeRuleDialog.close();
|
||||
} else {
|
||||
alert('失败!');
|
||||
alert('失败:' + data.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-4
@@ -22,10 +22,7 @@ app.controller('LoginCtl', ['$scope', '$state', '$window', 'AuthService',
|
||||
|
||||
AuthService.login(param).success(function (data) {
|
||||
if (data.code == 0) {
|
||||
$window.localStorage.setItem('session_sentinel_admin', {
|
||||
username: data.data
|
||||
});
|
||||
|
||||
$window.localStorage.setItem('session_sentinel_admin', JSON.stringify(data.data));
|
||||
$state.go('dashboard');
|
||||
} else {
|
||||
alert(data.msg);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
<div class="header">
|
||||
<nav class="navbar navbar-fixed-top navbar-inverse" style="" role="navigation">
|
||||
<div class="navbar-brand">
|
||||
<span style="color: #fff;font-size: 26px;">Sentinel 控制台</span>
|
||||
<span style="color: #fff;font-size: 26px;" ng-model="dashboardVersion">Sentinel 控制台 {{dashboardVersion}}</span>
|
||||
</div>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<li ng-show="showLogout">
|
||||
<a href="javascript:void(0);" ng-click="logout()"
|
||||
style="margin: 3px 15px 0 0;"><span class="glyphicon glyphicon-log-out"></span> 注销</a>
|
||||
</li>
|
||||
|
||||
+27
-4
@@ -5,14 +5,37 @@
|
||||
* # adminPosHeader
|
||||
*/
|
||||
angular.module('sentinelDashboardApp')
|
||||
.directive('header', ['AuthService', function () {
|
||||
.directive('header', ['VersionService', 'AuthService', function () {
|
||||
return {
|
||||
templateUrl: 'app/scripts/directives/header/header.html',
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
controller: function ($scope, $state, $window, AuthService) {
|
||||
if (!$window.localStorage.getItem('session_sentinel_admin')) {
|
||||
$state.go('login');
|
||||
controller: function ($scope, $state, $window, VersionService, AuthService) {
|
||||
VersionService.version().success(function (data) {
|
||||
if (data.code == 0) {
|
||||
$scope.dashboardVersion = data.data;
|
||||
}
|
||||
});
|
||||
|
||||
if (!$window.localStorage.getItem("session_sentinel_admin")) {
|
||||
AuthService.check().success(function (data) {
|
||||
if (data.code == 0) {
|
||||
$window.localStorage.setItem('session_sentinel_admin', JSON.stringify(data.data));
|
||||
handleLogout($scope, data.data.id)
|
||||
} else {
|
||||
$state.go('login');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handleLogout($scope, JSON.parse($window.localStorage.getItem("session_sentinel_admin")).id)
|
||||
}
|
||||
|
||||
function handleLogout($scope, id) {
|
||||
if (id == 'FAKE_EMP_ID') {
|
||||
$scope.showLogout = false;
|
||||
} else {
|
||||
$scope.showLogout = true;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.logout = function () {
|
||||
|
||||
+7
@@ -1,6 +1,13 @@
|
||||
var app = angular.module('sentinelDashboardApp');
|
||||
|
||||
app.service('AuthService', ['$http', function ($http) {
|
||||
this.check = function () {
|
||||
return $http({
|
||||
url: '/auth/check',
|
||||
method: 'POST'
|
||||
});
|
||||
};
|
||||
|
||||
this.login = function (param) {
|
||||
return $http({
|
||||
url: '/auth/login',
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
var app = angular.module('sentinelDashboardApp');
|
||||
|
||||
app.service('VersionService', ['$http', function ($http) {
|
||||
this.version = function () {
|
||||
return $http({
|
||||
url: '/version',
|
||||
method: 'GET'
|
||||
});
|
||||
};
|
||||
}]);
|
||||
+1
-1
@@ -1 +1 @@
|
||||
"use strict";var app;angular.module("sentinelDashboardApp",["oc.lazyLoad","ui.router","ui.bootstrap","angular-loading-bar","ngDialog","ui.bootstrap.datetimepicker","ui-notification","rzTable","angular-clipboard","selectize","angularUtils.directives.dirPagination"]).factory("AuthInterceptor",["$window","$state",function(t,r){return{responseError:function(e){return 401===e.status&&(t.localStorage.removeItem("session_sentinel_admin"),r.go("login")),e},response:function(e){return e},request:function(e){return e},requestError:function(e){return e}}}]).config(["$stateProvider","$urlRouterProvider","$ocLazyLoadProvider","$httpProvider",function(e,t,r,a){a.interceptors.push("AuthInterceptor"),r.config({debug:!1,events:!0}),t.otherwise("/dashboard/home"),e.state("login",{url:"/login",templateUrl:"app/views/login.html",controller:"LoginCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/login.js"]})}]}}).state("dashboard",{url:"/dashboard",templateUrl:"app/views/dashboard/main.html",resolve:{loadMyDirectives:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/directives/header/header.js","app/scripts/directives/sidebar/sidebar.js","app/scripts/directives/sidebar/sidebar-search/sidebar-search.js"]})}]}}).state("dashboard.home",{url:"/home",templateUrl:"app/views/dashboard/home.html",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/main.js"]})}]}}).state("dashboard.flowV1",{templateUrl:"app/views/flow_v1.html",url:"/flow/:app",controller:"FlowControllerV1",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/flow_v1.js"]})}]}}).state("dashboard.flow",{templateUrl:"app/views/flow_v2.html",url:"/v2/flow/:app",controller:"FlowControllerV2",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/flow_v2.js"]})}]}}).state("dashboard.paramFlow",{templateUrl:"app/views/param_flow.html",url:"/paramFlow/:app",controller:"ParamFlowController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/param_flow.js"]})}]}}).state("dashboard.clusterAppAssignManage",{templateUrl:"app/views/cluster_app_assign_manage.html",url:"/cluster/assign_manage/:app",controller:"SentinelClusterAppAssignManageController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_assign_manage.js"]})}]}}).state("dashboard.clusterAppServerList",{templateUrl:"app/views/cluster_app_server_list.html",url:"/cluster/server/:app",controller:"SentinelClusterAppServerListController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_server_list.js"]})}]}}).state("dashboard.clusterAppClientList",{templateUrl:"app/views/cluster_app_client_list.html",url:"/cluster/client/:app",controller:"SentinelClusterAppTokenClientListController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_token_client_list.js"]})}]}}).state("dashboard.clusterSingle",{templateUrl:"app/views/cluster_single_config.html",url:"/cluster/single/:app",controller:"SentinelClusterSingleController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_single.js"]})}]}}).state("dashboard.authority",{templateUrl:"app/views/authority.html",url:"/authority/:app",controller:"AuthorityRuleController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/authority.js"]})}]}}).state("dashboard.degrade",{templateUrl:"app/views/degrade.html",url:"/degrade/:app",controller:"DegradeCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/degrade.js"]})}]}}).state("dashboard.system",{templateUrl:"app/views/system.html",url:"/system/:app",controller:"SystemCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/system.js"]})}]}}).state("dashboard.machine",{templateUrl:"app/views/machine.html",url:"/app/:app",controller:"MachineCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/machine.js"]})}]}}).state("dashboard.identity",{templateUrl:"app/views/identity.html",url:"/identity/:app",controller:"IdentityCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/identity.js"]})}]}}).state("dashboard.gatewayIdentity",{templateUrl:"app/views/gateway/identity.htmLine truncated
|
||||
"use strict";var app;angular.module("sentinelDashboardApp",["oc.lazyLoad","ui.router","ui.bootstrap","angular-loading-bar","ngDialog","ui.bootstrap.datetimepicker","ui-notification","rzTable","angular-clipboard","selectize","angularUtils.directives.dirPagination"]).factory("AuthInterceptor",["$window","$state",function(t,r){return{responseError:function(e){return 401===e.status&&(t.localStorage.removeItem("session_sentinel_admin"),r.go("login")),e},response:function(e){return e},request:function(e){return e},requestError:function(e){return e}}}]).config(["$stateProvider","$urlRouterProvider","$ocLazyLoadProvider","$httpProvider",function(e,t,r,a){a.interceptors.push("AuthInterceptor"),r.config({debug:!1,events:!0}),t.otherwise("/dashboard/home"),e.state("login",{url:"/login",templateUrl:"app/views/login.html",controller:"LoginCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/login.js"]})}]}}).state("dashboard",{url:"/dashboard",templateUrl:"app/views/dashboard/main.html",resolve:{loadMyDirectives:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/directives/header/header.js","app/scripts/directives/sidebar/sidebar.js","app/scripts/directives/sidebar/sidebar-search/sidebar-search.js"]})}]}}).state("dashboard.home",{url:"/home",templateUrl:"app/views/dashboard/home.html",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/main.js"]})}]}}).state("dashboard.flowV1",{templateUrl:"app/views/flow_v1.html",url:"/flow/:app",controller:"FlowControllerV1",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/flow_v1.js"]})}]}}).state("dashboard.flow",{templateUrl:"app/views/flow_v2.html",url:"/v2/flow/:app",controller:"FlowControllerV2",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/flow_v2.js"]})}]}}).state("dashboard.paramFlow",{templateUrl:"app/views/param_flow.html",url:"/paramFlow/:app",controller:"ParamFlowController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/param_flow.js"]})}]}}).state("dashboard.clusterAppAssignManage",{templateUrl:"app/views/cluster_app_assign_manage.html",url:"/cluster/assign_manage/:app",controller:"SentinelClusterAppAssignManageController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_assign_manage.js"]})}]}}).state("dashboard.clusterAppServerList",{templateUrl:"app/views/cluster_app_server_list.html",url:"/cluster/server/:app",controller:"SentinelClusterAppServerListController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_server_list.js"]})}]}}).state("dashboard.clusterAppClientList",{templateUrl:"app/views/cluster_app_client_list.html",url:"/cluster/client/:app",controller:"SentinelClusterAppTokenClientListController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_app_token_client_list.js"]})}]}}).state("dashboard.clusterSingle",{templateUrl:"app/views/cluster_single_config.html",url:"/cluster/single/:app",controller:"SentinelClusterSingleController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/cluster_single.js"]})}]}}).state("dashboard.authority",{templateUrl:"app/views/authority.html",url:"/authority/:app",controller:"AuthorityRuleController",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/authority.js"]})}]}}).state("dashboard.degrade",{templateUrl:"app/views/degrade.html",url:"/degrade/:app",controller:"DegradeCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/degrade.js"]})}]}}).state("dashboard.system",{templateUrl:"app/views/system.html",url:"/system/:app",controller:"SystemCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/system.js"]})}]}}).state("dashboard.machine",{templateUrl:"app/views/machine.html",url:"/app/:app",controller:"MachineCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/machine.js"]})}]}}).state("dashboard.identity",{templateUrl:"app/views/identity.html",url:"/identity/:app",controller:"IdentityCtl",resolve:{loadMyFiles:["$ocLazyLoad",function(e){return e.load({name:"sentinelDashboardApp",files:["app/scripts/controllers/identity.js"]})}]}}).state("dashboard.gatewayIdentity",{templateUrl:"app/views/gateway/identity.htmLine truncated
|
||||
@@ -43,6 +43,7 @@ const CSS_APP = [
|
||||
const JS_APP = [
|
||||
'app/scripts/app.js',
|
||||
'app/scripts/filters/filters.js',
|
||||
'app/scripts/services/version_service.js',
|
||||
'app/scripts/services/auth_service.js',
|
||||
'app/scripts/services/appservice.js',
|
||||
'app/scripts/services/flow_service_v1.js',
|
||||
|
||||
+29
-52
@@ -183,7 +183,7 @@
|
||||
},
|
||||
"archy": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/archy/download/archy-1.0.0.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/archy/download/archy-1.0.0.tgz",
|
||||
"integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=",
|
||||
"dev": true
|
||||
},
|
||||
@@ -213,7 +213,7 @@
|
||||
},
|
||||
"array-each": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npm.taobao.org/array-each/download/array-each-1.0.1.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/array-each/download/array-each-1.0.1.tgz",
|
||||
"integrity": "sha1-p5SvDAWrF1KEbudTofIRoFugxE8=",
|
||||
"dev": true
|
||||
},
|
||||
@@ -1222,7 +1222,7 @@
|
||||
},
|
||||
"for-own": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npm.taobao.org/for-own/download/for-own-1.0.0.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/for-own/download/for-own-1.0.0.tgz",
|
||||
"integrity": "sha1-xjMy9BXO3EsE2/5wz4NklMU8tEs=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -2416,9 +2416,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
},
|
||||
"lodash._basecopy": {
|
||||
"version": "3.0.1",
|
||||
@@ -2616,9 +2616,9 @@
|
||||
}
|
||||
},
|
||||
"lodash.merge": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/lodash.merge/download/lodash.merge-4.6.1.tgz",
|
||||
"integrity": "sha1-rcJdnLmbk5HFliTzefu6YNcRHVQ=",
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.restparam": {
|
||||
@@ -2837,9 +2837,9 @@
|
||||
"integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
|
||||
},
|
||||
"mixin-deep": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/mixin-deep/download/mixin-deep-1.3.1.tgz",
|
||||
"integrity": "sha1-pJ5yaNzhoNlpjkUybFYm3zVD0P4=",
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz",
|
||||
"integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"for-in": "^1.0.2",
|
||||
@@ -2848,8 +2848,8 @@
|
||||
"dependencies": {
|
||||
"is-extendable": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/is-extendable/download/is-extendable-1.0.1.tgz",
|
||||
"integrity": "sha1-p0cPnkJnM9gb2B4RVSZOOjUHyrQ=",
|
||||
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz",
|
||||
"integrity": "sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-plain-object": "^2.0.4"
|
||||
@@ -3007,7 +3007,7 @@
|
||||
},
|
||||
"object.defaults": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npm.taobao.org/object.defaults/download/object.defaults-1.1.0.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/object.defaults/download/object.defaults-1.1.0.tgz",
|
||||
"integrity": "sha1-On+GgzS0B96gbaFtiNXNKeQ1/s8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -3019,7 +3019,7 @@
|
||||
},
|
||||
"object.map": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npm.taobao.org/object.map/download/object.map-1.0.1.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/object.map/download/object.map-1.0.1.tgz",
|
||||
"integrity": "sha1-z4Plncj8wK1fQlDh94s7gb2AHTc=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -3102,7 +3102,7 @@
|
||||
},
|
||||
"parse-filepath": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npm.taobao.org/parse-filepath/download/parse-filepath-1.0.2.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/parse-filepath/download/parse-filepath-1.0.2.tgz",
|
||||
"integrity": "sha1-pjISf1Oq89FYdvWHLz/6x2PWyJE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -3161,7 +3161,7 @@
|
||||
},
|
||||
"path-root": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npm.taobao.org/path-root/download/path-root-0.1.1.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/path-root/download/path-root-0.1.1.tgz",
|
||||
"integrity": "sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -3170,7 +3170,7 @@
|
||||
},
|
||||
"path-root-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npm.taobao.org/path-root-regex/download/path-root-regex-0.1.2.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/path-root-regex/download/path-root-regex-0.1.2.tgz",
|
||||
"integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=",
|
||||
"dev": true
|
||||
},
|
||||
@@ -3274,7 +3274,7 @@
|
||||
},
|
||||
"pretty-hrtime": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npm.taobao.org/pretty-hrtime/download/pretty-hrtime-1.0.3.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/pretty-hrtime/download/pretty-hrtime-1.0.3.tgz",
|
||||
"integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=",
|
||||
"dev": true
|
||||
},
|
||||
@@ -3370,7 +3370,7 @@
|
||||
},
|
||||
"rechoir": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npm.taobao.org/rechoir/download/rechoir-0.6.2.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/rechoir/download/rechoir-0.6.2.tgz",
|
||||
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
@@ -3667,9 +3667,9 @@
|
||||
}
|
||||
},
|
||||
"set-value": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/set-value/download/set-value-2.0.0.tgz",
|
||||
"integrity": "sha1-ca5KiPD+77v1LR6mBPP7MV67YnQ=",
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz",
|
||||
"integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"extend-shallow": "^2.0.1",
|
||||
@@ -4190,43 +4190,20 @@
|
||||
},
|
||||
"unc-path-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npm.taobao.org/unc-path-regex/download/unc-path-regex-0.1.2.tgz",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/unc-path-regex/download/unc-path-regex-0.1.2.tgz",
|
||||
"integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=",
|
||||
"dev": true
|
||||
},
|
||||
"union-value": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/union-value/download/union-value-1.0.0.tgz",
|
||||
"integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=",
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
||||
"integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"arr-union": "^3.1.0",
|
||||
"get-value": "^2.0.6",
|
||||
"is-extendable": "^0.1.1",
|
||||
"set-value": "^0.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"extend-shallow": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/extend-shallow/download/extend-shallow-2.0.1.tgz",
|
||||
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-extendable": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"set-value": {
|
||||
"version": "0.4.3",
|
||||
"resolved": "http://registry.npm.alibaba-inc.com/set-value/download/set-value-0.4.3.tgz",
|
||||
"integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"extend-shallow": "^2.0.1",
|
||||
"is-extendable": "^0.1.1",
|
||||
"is-plain-object": "^2.0.1",
|
||||
"to-object-path": "^0.3.0"
|
||||
}
|
||||
}
|
||||
"set-value": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"unique-stream": {
|
||||
|
||||
@@ -30,12 +30,12 @@
|
||||
"angularjs-bootstrap-datetimepicker": "^1.1.4",
|
||||
"bootstrap-switch": "^3.3.4",
|
||||
"bootstrap-tagsinput": "~0.7.1",
|
||||
"lodash": "^4.17.15",
|
||||
"moment": "^2.12.0",
|
||||
"ng-dialog": "^0.6.6",
|
||||
"ng-tags-input": "~3.0.0",
|
||||
"oclazyload": "^1.1.0",
|
||||
"selectize": "^0.12.1",
|
||||
"lodash": ">=4.17.11"
|
||||
"selectize": "^0.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
<properties>
|
||||
<spring-boot.version>2.2.4.RELEASE</spring-boot.version>
|
||||
<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2.1.1.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring-cloud-alibaba.version>2.2.0.RELEASE</spring-cloud-alibaba.version>
|
||||
<spring-platform.version>Cairo-SR8</spring-platform.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<spring-boot-admin.version>2.2.1</spring-boot-admin.version>
|
||||
<spring-boot-admin.version>2.2.2</spring-boot-admin.version>
|
||||
<hutool.version>5.1.2</hutool.version>
|
||||
<kaptcha.version>1.6.2</kaptcha.version>
|
||||
<swagger.fox.version>2.9.2</swagger.fox.version>
|
||||
|
||||
Reference in new issue
Block a user