diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/AuthService.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthService.java similarity index 78% rename from sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/AuthService.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthService.java index 3a6c1e02..cdda6a3b 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/AuthService.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthService.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.csp.sentinel.dashboard.service; +package com.alibaba.csp.sentinel.dashboard.auth; /** - * Interface about authentication and authorization + * Interface for authentication and authorization. * * @author Carpenter Lee + * @since 1.5.0 */ public interface AuthService { + /** * Get the authentication user. * @@ -30,41 +32,42 @@ public interface AuthService { AuthUser getAuthUser(R request); /** - * privilege type. + * Privilege type. */ enum PrivilegeType { /** - * read rule + * Read rule */ READ_RULE, /** - * create or modify rule + * Create or modify rule */ WRITE_RULE, /** - * delete rule + * Delete rule */ DELETE_RULE, /** - * read metrics + * Read metrics */ READ_METRIC, /** - * add machine + * Add machine */ ADD_MACHINE, /** - * equals all privileges above + * All privileges above are granted. */ ALL } /** - * entity represents the current user + * Represents the current user. */ interface AuthUser { + /** - * query whether current user has the specific privilege to the target, the target + * Query whether current user has the specific privilege to the target, the target * may be an app name or an ip address, or other destination. *

* This method will use return value to represent whether user has the specific @@ -80,32 +83,31 @@ public interface AuthService { boolean authTarget(String target, PrivilegeType privilegeType); /** - * check whether current user is super user + * Check whether current user is a super-user. * * @return if current user is super user return true, else return false. */ boolean isSuperUser(); /** - * get current user's nick name. + * Get current user's nick name. * * @return current user's nick name. */ String getNickName(); /** - * get current user's login name. + * Get current user's login name. * * @return current user's login name. */ String getLoginName(); /** - * get current user's employ id. + * Get current user's ID. * - * @return current user's employ id. + * @return ID of current user */ - String getEmpId(); - + String getId(); } } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/FakeAuthServiceImpl.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/FakeAuthServiceImpl.java similarity index 94% rename from sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/FakeAuthServiceImpl.java rename to sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/FakeAuthServiceImpl.java index 6c1352f1..b40ea564 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/FakeAuthServiceImpl.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/FakeAuthServiceImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.csp.sentinel.dashboard.service; +package com.alibaba.csp.sentinel.dashboard.auth; import javax.servlet.http.HttpServletRequest; @@ -23,12 +23,13 @@ import org.springframework.stereotype.Component; * A fake AuthService implementation, which will pass all user auth checking. * * @author Carpenter Lee + * @since 1.5.0 */ @Component public class FakeAuthServiceImpl implements AuthService { + @Override public AuthUser getAuthUser(HttpServletRequest request) { - return new AuthUserImpl(); } @@ -57,7 +58,7 @@ public class FakeAuthServiceImpl implements AuthService { } @Override - public String getEmpId() { + public String getId() { return "FAKE_EMP_ID"; } } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java index 21853829..f91f7963 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java @@ -23,15 +23,15 @@ import org.apache.commons.lang.math.NumberUtils; import org.springframework.lang.NonNull; /** - * Dashboard config support + *

Dashboard local config support.

*

* Dashboard supports configuration loading by several ways by order:
* 1. System.properties
* 2. Env - * + *

+ * * @author jason * @since 1.5.0 - * */ public class DashboardConfig { diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java index 14a90b09..496e5da4 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/WebConfig.java @@ -27,8 +27,8 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; +import com.alibaba.csp.sentinel.dashboard.auth.AuthService; +import com.alibaba.csp.sentinel.dashboard.auth.AuthService.AuthUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,6 +47,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; public class WebConfig implements WebMvcConfigurer { private final Logger logger = LoggerFactory.getLogger(WebConfig.class); + @Autowired private AuthService authService; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java index 4f5d53b1..2b285eff 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java @@ -22,9 +22,9 @@ import javax.servlet.http.HttpServletRequest; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java index 9905d551..7733129a 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java @@ -22,9 +22,9 @@ import javax.servlet.http.HttpServletRequest; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java index 35315ea0..71e5b701 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/FlowControllerV1.java @@ -20,9 +20,9 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java index c603613a..d9529783 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java @@ -27,9 +27,9 @@ 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.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java index ad2ac2f4..815efcaf 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java @@ -20,9 +20,9 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java index 1b110811..41aea755 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java @@ -20,9 +20,9 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import com.alibaba.csp.sentinel.dashboard.service.AuthService; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.AuthUser; -import com.alibaba.csp.sentinel.dashboard.service.AuthService.PrivilegeType; +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; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;