Ver código fonte

修改退出登录后的返回值

master
WendyYang 6 meses atrás
pai
commit
a7705cac75
2 arquivos alterados com 8 adições e 4 exclusões
  1. +2
    -2
      kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java
  2. +6
    -2
      kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java

+ 2
- 2
kq-vas-api/src/main/java/com/ningdatech/kqapi/security/handler/DefaultLogoutSuccessHandler.java Ver arquivo

@@ -1,7 +1,7 @@
package com.ningdatech.kqapi.security.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.kqapi.user.controller.UserAuthController;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
@@ -30,6 +30,6 @@ public class DefaultLogoutSuccessHandler implements LogoutSuccessHandler {
throws IOException {
// 退出成功后返回 和前端约定的Json
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(objectMapper.writeValueAsString(ApiResponse.ofSuccess()));
response.getWriter().write(objectMapper.writeValueAsString(UserAuthController.LOGOUT_RET));
}
}

+ 6
- 2
kq-vas-api/src/main/java/com/ningdatech/kqapi/user/controller/UserAuthController.java Ver arquivo

@@ -2,6 +2,7 @@ package com.ningdatech.kqapi.user.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.kqapi.common.constant.BizConst;
import com.ningdatech.kqapi.common.util.StrPool;
import com.ningdatech.kqapi.security.constant.AuthConst;
@@ -31,6 +32,9 @@ public class UserAuthController {

private final ObjectMapper objectMapper;

public static final ApiResponse<Void> LOGOUT_RET = ApiResponse.of(HttpStatus.UNAUTHORIZED.value(), "已退出登录");


@PostMapping(value = "/login/password", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ApiOperation(value = "账号密码的登陆方式")
@ApiImplicitParams({
@@ -70,8 +74,8 @@ public class UserAuthController {
cookie.setPath(request.getContextPath() + "/");
cookie.setMaxAge(AuthConst.SESSION_EXPIRED);
response.addCookie(cookie);
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.getWriter().write(objectMapper.writeValueAsString(BizConst.UNAUTHENTICATED));
response.setStatus(HttpStatus.OK.value());
response.getWriter().write(objectMapper.writeValueAsString(LOGOUT_RET));
}

}

Carregando…
Cancelar
Salvar