|
@@ -2,16 +2,21 @@ package com.its.op.controller.its;
|
|
|
|
|
|
import com.its.op.dto.its.LoginDto;
|
|
|
import com.its.op.service.its.LoginService;
|
|
|
+import com.its.op.webapp.config.WebConfig;
|
|
|
+import com.its.utils.CookieUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
-import javax.validation.Valid;
|
|
|
+import javax.servlet.http.Cookie;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
@@ -31,16 +36,79 @@ public class LoginController {
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
- @ApiOperation(value = "로그인", response = LoginDto.class)
|
|
|
- @PostMapping(value = "/login", produces = {"application/json; charset=utf8"})
|
|
|
- public LoginDto login(@RequestBody @Valid final LoginDto.LoginReqDto req) {
|
|
|
- return this.service.login(req);
|
|
|
+// @ApiOperation(value = "로그인", response = LoginDto.class)
|
|
|
+// @PostMapping(value = "/login", produces = {"application/json; charset=utf8"})
|
|
|
+// public LoginDto login(@RequestBody @Valid final LoginDto.LoginReqDto req) {
|
|
|
+// return this.service.login(req);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 로그인
|
|
|
+ * @param login
|
|
|
+ * @param model
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/login.do")
|
|
|
+ public String postLogin(@ModelAttribute LoginDto.LoginReqDto login, Model model) {
|
|
|
+ log.error("{}", login.toString());
|
|
|
+ log.error("{}", model.toString());
|
|
|
+ model.addAttribute("login", login);
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+// @ApiOperation(value = "로그아웃")
|
|
|
+// @PostMapping(value = "/logout", produces = {"application/json; charset=utf8"})
|
|
|
+// public void logout(@RequestBody @Valid final LoginDto.LogoutReqDto req) {
|
|
|
+// this.service.logout(req);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 로그아웃
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping({"/logout.do"})
|
|
|
+ public ModelAndView getLogout(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ Cookie[] cookies = request.getCookies();
|
|
|
+ log.error("{}", cookies.length);
|
|
|
+ for (int ii = 0; ii < cookies.length; ii++) {
|
|
|
+ log.error("{}, {}", cookies[ii].getName(), cookies[ii].getValue());
|
|
|
+ }
|
|
|
+ String encUserId = "";
|
|
|
+ String loginHms = "";
|
|
|
+ if (cookies!= null && cookies.length > 0) {
|
|
|
+ try {
|
|
|
+ encUserId = CookieUtils.getCookie(request, WebConfig.USER_UUID);
|
|
|
+ loginHms = CookieUtils.getCookie(request, WebConfig.USER_TIME);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!"".equals(encUserId)) {
|
|
|
+ String userId = WebConfig.decUserId(encUserId);
|
|
|
+ LoginDto.LogoutReqDto req = LoginDto.LogoutReqDto.builder()
|
|
|
+ .user_id(WebConfig.decUserId(userId))
|
|
|
+ .login_hms(loginHms)
|
|
|
+ .build();
|
|
|
+ log.info("logout: {}", req.toString());
|
|
|
+ this.service.logout(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
|
+ if(auth != null) {
|
|
|
+ expiredCookie(response, WebConfig.USER_UUID);
|
|
|
+ expiredCookie(response, WebConfig.USER_TIME);
|
|
|
+ new SecurityContextLogoutHandler().logout(request, response, auth);
|
|
|
+ }
|
|
|
+ return new ModelAndView("forward:/application/login/login.html");
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "로그아웃")
|
|
|
- @PostMapping(value = "/logout", produces = {"application/json; charset=utf8"})
|
|
|
- public void logout(@RequestBody @Valid final LoginDto.LogoutReqDto req) {
|
|
|
- this.service.logout(req);
|
|
|
+ private void expiredCookie(HttpServletResponse response, String cookieName) {
|
|
|
+ Cookie cookie = new Cookie(cookieName, null);
|
|
|
+ cookie.setMaxAge(0);
|
|
|
+ response.addCookie(cookie);
|
|
|
}
|
|
|
|
|
|
}
|