|
|
@@ -6,8 +6,12 @@ import com.jzg.config.JzgTokenService;
|
|
|
import com.jzg.config.JzgUserDetailsService;
|
|
|
import com.jzg.config.JzgUsernamePasswordAuthenticationToken;
|
|
|
import com.jzg.entity.SysUser;
|
|
|
+import com.jzg.entity.vo.LoginFormVo;
|
|
|
import com.jzg.handler.JzgAuthenticationSuccessHandler;
|
|
|
import com.jzg.service.SysUserService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
+import io.swagger.v3.oas.models.annotations.OpenAPI30;
|
|
|
import jakarta.servlet.ServletException;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
@@ -15,9 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
@@ -41,16 +43,22 @@ public class AuthController {
|
|
|
|
|
|
/**
|
|
|
* 登录接口
|
|
|
- * @param userName
|
|
|
- * @param passWord
|
|
|
+ * @param loginFormVo
|
|
|
* @throws ServletException
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- @GetMapping("/login")
|
|
|
- public void login(String userName,String passWord,String system) throws ServletException, IOException {
|
|
|
+ @Operation(
|
|
|
+ summary = "登录接口",
|
|
|
+ description = "登录接口",
|
|
|
+ responses = {
|
|
|
+ @ApiResponse(responseCode = "200",description = "登录成功"),
|
|
|
+ @ApiResponse(responseCode = "403",description = "登录失败")
|
|
|
+ })
|
|
|
+ @PostMapping("/login")
|
|
|
+ public void login(@RequestBody LoginFormVo loginFormVo) throws ServletException, IOException {
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
|
|
- JzgUsernamePasswordAuthenticationToken authentication = new JzgUsernamePasswordAuthenticationToken(userName,passWord,system);
|
|
|
+ JzgUsernamePasswordAuthenticationToken authentication = new JzgUsernamePasswordAuthenticationToken(loginFormVo.getUserName(),loginFormVo.getPassWord(),loginFormVo.getSystem());
|
|
|
Authentication authenticate = authenticationManager.authenticate(authentication);
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticate);
|
|
|
JzgAuthenticationSuccessHandler successHandler = new JzgAuthenticationSuccessHandler(tokenStore);
|