|
@@ -1,9 +1,23 @@ |
|
|
package com.ningdatech.pmapi.user.controller; |
|
|
package com.ningdatech.pmapi.user.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
|
import com.ningdatech.basic.util.StrPool; |
|
|
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
|
|
import com.ningdatech.pmapi.user.security.auth.constants.SessionTimeConstant; |
|
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
|
|
|
|
import javax.servlet.http.Cookie; |
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* <p> |
|
|
* <p> |
|
@@ -13,8 +27,58 @@ import org.springframework.stereotype.Controller; |
|
|
* @author Liuxinxin |
|
|
* @author Liuxinxin |
|
|
* @since 2023-01-04 |
|
|
* @since 2023-01-04 |
|
|
*/ |
|
|
*/ |
|
|
@Controller |
|
|
|
|
|
@RequestMapping("/pmapi.user/user-auth") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
|
|
@RequestMapping("/api/v1/user/auth") |
|
|
|
|
|
@Api(tags = {"用户鉴权-相关接口"}) |
|
|
|
|
|
@RequiredArgsConstructor |
|
|
public class UserAuthController { |
|
|
public class UserAuthController { |
|
|
|
|
|
|
|
|
|
|
|
private final ObjectMapper objectMapper; |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/login/password", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) |
|
|
|
|
|
@ApiOperation(value = "账号密码的登陆方式") |
|
|
|
|
|
@ApiImplicitParams({ |
|
|
|
|
|
@ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "form", dataType = "String"), |
|
|
|
|
|
@ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "form", dataType = "String"), |
|
|
|
|
|
@ApiImplicitParam(name = "loginPlatform", value = "PC_PLATFORM PC 端,DRIVER_PLATFORM 驾驶员端,ENTERPRISE_PLATFORM 企业端" |
|
|
|
|
|
, required = true, paramType = "form", dataType = "String")}) |
|
|
|
|
|
public void loginByUsernameAndPassword(@RequestParam("username") String username, |
|
|
|
|
|
@RequestParam("password") String password, |
|
|
|
|
|
@RequestParam("loginPlatform") String loginPlatform) { |
|
|
|
|
|
// 不实现任何内容,只是为了出api文档 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/logout") |
|
|
|
|
|
@ApiOperation(value = "退出登陆") |
|
|
|
|
|
public void logout() { |
|
|
|
|
|
// 不实现任何内容,具体实现交由Spring Security进行管理 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 当需要身份认证时,跳转到这里 |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("/auth-require") |
|
|
|
|
|
@CrossOrigin(originPatterns = "*", allowCredentials = "true", maxAge = 3600) |
|
|
|
|
|
public void requireAuthentication(HttpServletResponse response) throws IOException { |
|
|
|
|
|
response.setContentType(StrPool.CONTENT_TYPE); |
|
|
|
|
|
response.setStatus(HttpStatus.UNAUTHORIZED.value()); |
|
|
|
|
|
response.getWriter().write(objectMapper.writeValueAsString(BizConst.UNAUTHENTICATED)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 设置session失效 |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("/invalid-session") |
|
|
|
|
|
@CrossOrigin(originPatterns = "*", allowCredentials = "true", maxAge = 3600) |
|
|
|
|
|
public void invalidSession(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
|
|
|
|
response.setContentType(StrPool.CONTENT_TYPE); |
|
|
|
|
|
Cookie cookie = new Cookie(BizConst.COOKIE_KEY, null); |
|
|
|
|
|
cookie.setPath(request.getContextPath() + "/"); |
|
|
|
|
|
cookie.setMaxAge(SessionTimeConstant.SESSION_TIME_SECONDS); |
|
|
|
|
|
response.addCookie(cookie); |
|
|
|
|
|
response.setStatus(HttpStatus.UNAUTHORIZED.value()); |
|
|
|
|
|
response.getWriter().write(objectMapper.writeValueAsString(BizConst.UNAUTHENTICATED)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |