diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java index 1cae8a60..4de6898c 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java @@ -29,12 +29,12 @@ import javax.servlet.http.HttpSession; @Component public class SimpleWebAuthServiceImpl implements AuthService { - 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; } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java index 58be6f65..e8f3f748 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java @@ -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; @@ -47,7 +47,7 @@ public class AuthController { private String authPassword; @PostMapping("/login") - public Result login(HttpServletRequest request, String username, String password) { + public Result login(HttpServletRequest request, String username, String password) { if (StringUtils.isNotBlank(DashboardConfig.getAuthUsername())) { authUsername = DashboardConfig.getAuthUsername(); } @@ -63,17 +63,17 @@ 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) { + public Result logout(HttpServletRequest request) { request.getSession().invalidate(); return Result.ofSuccess(null); } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java index 255acdfd..69d66ea1 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java @@ -16,31 +16,34 @@ 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.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * @author hisenyuan - * @date 2019-05-30 10:47:50 + * @since 1.7.0 */ @RestController -@RequestMapping(value = "/") public class VersionController { - @Value("${sentinel.dashboard.version:''}") + + private static final String VERSION_PATTERN = "-"; + + @Value("${sentinel.dashboard.version:}") private String sentinelDashboardVersion; - private static String VERSION_PATTERN = "-"; - @RequestMapping(value = "/getVersion") - public Result getVersion() { - if (sentinelDashboardVersion != null) { + @GetMapping("/version") + public Result 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"); + return Result.ofFail(1, "getVersion failed: empty version"); } } } diff --git a/sentinel-dashboard/src/main/resources/application.properties b/sentinel-dashboard/src/main/resources/application.properties index f15544dd..edab1027 100755 --- a/sentinel-dashboard/src/main/resources/application.properties +++ b/sentinel-dashboard/src/main/resources/application.properties @@ -10,10 +10,11 @@ logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - % #logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n #auth settings -auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine +auth.filter.exclude-urls=/,/auth/login,/auth/logout,/registry/machine,/version auth.filter.exclude-url-suffixes=htm,html,js,css,map,ico,ttf,woff,png auth.username=sentinel auth.password=sentinel -# get the project version for index +# Inject the dashboard version. It's required to enable +# filtering in pom.xml for this resource file. sentinel.dashboard.version=${project.version} \ No newline at end of file