Bläddra i källkod

添加检查登录状态的接口

NorthLan 6 år sedan
förälder
incheckning
b749ae7085

+ 1 - 2
zen-api/src/main/kotlin/com/gxzc/zen/umps/config/ShiroConfig.kt

@@ -83,9 +83,8 @@ class ShiroConfig {
              * user  表示用户不一定已通过认证,只要曾被Shiro记住过登录状态的用户就可以正常发起请求,比如rememberMe
              */
             filterChainDefinitionMap = linkedMapOf<String, String>( // BUG 此处一定要使用 linkedHashMap 否则顺序有问题
-                    "/auth/login" to "canon", // 登陆
                     "/auth/setcookie" to "canon", // 设置cookie
-                    "/auth/hello" to "canon", // 获取cookie
+                    "/auth/check" to "canon", // 检查登录状态
 //                    "/auth/logout" to "logout", // 登出
                     "/test/**" to "canon", // 测试 免登录
                     "/upload/**" to "canon", // 上传免登录

+ 1 - 0
zen-core/src/main/kotlin/com/gxzc/zen/common/dto/ResponseDto.kt

@@ -15,6 +15,7 @@ import java.util.*
 @JsonInclude(JsonInclude.Include.NON_NULL)
 class ResponseDto {
     var data: Any? = null
+    var code: Int? = 200
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     var time: Date = Dates.today

+ 13 - 0
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/AuthController.kt

@@ -43,4 +43,17 @@ class AuthController : BaseController() {
 //        SSOHelper.clearLogin(getRequest(), getResponse())
         return ResponseEntity.ok(ResponseDto())
     }
+
+    @ApiOperation(value = "验证登录状态")
+    @GetMapping("/check")
+    fun check(): ResponseEntity<*> {
+        val subject = SecurityUtils.getSubject()
+        return if (subject != null && subject.isAuthenticated) {
+            ResponseEntity.ok(ResponseDto())
+        } else {
+            ResponseEntity.ok(ResponseDto().apply {
+                code = 401
+            })
+        }
+    }
 }