package com.dbnt.kcscbackend.auth; import com.dbnt.kcscbackend.auth.service.EgovLoginService; import com.dbnt.kcscbackend.config.common.BaseController; import com.dbnt.kcscbackend.auth.entity.LoginVO; import com.dbnt.kcscbackend.config.common.ResponseCode; import com.dbnt.kcscbackend.config.common.ResultVO; import com.dbnt.kcscbackend.config.egov.EgovMessageSource; import com.dbnt.kcscbackend.config.jwt.EgovJwtTokenUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; import org.springframework.validation.FieldError; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.HashMap; import java.util.List; /** * 일반 로그인을 처리하는 컨트롤러 클래스 * @author 공통서비스 개발팀 박지욱 * @since 2009.03.06 * @version 1.0 * @see * *
 * << 개정이력(Modification Information) >>
 *
 *  수정일      수정자      수정내용
 *  -------            --------        ---------------------------
 *  2009.03.06  박지욱     최초 생성
 *  2011.08.31  JJY            경량환경 템플릿 커스터마이징버전 생성
 *
 *  
*/ @Slf4j @RestController @RequestMapping("/auth") @Tag(name="EgovLoginApiController",description = "로그인 관련") public class EgovLoginApiController extends BaseController { /** EgovLoginService */ @Resource(name = "loginService") private EgovLoginService loginService; /** EgovMessageSource */ @Resource(name = "egovMessageSource") EgovMessageSource egovMessageSource; /** JWT */ @Autowired private EgovJwtTokenUtil jwtTokenUtil; @Operation( summary = "JWT 로그인", description = "JWT 로그인 처리", tags = {"EgovLoginApiController"} ) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "가입 성공"), @ApiResponse(responseCode = "300", description = "가입 실패") }) @PostMapping(value = "/join") public HashMap actionJoin(@RequestBody @Valid LoginVO loginVO, Errors errors, HttpServletRequest request) throws Exception { HashMap resultMap = new HashMap(); if(errors.hasErrors()){ StringBuilder msg = new StringBuilder(); for(FieldError error: errors.getFieldErrors()){ msg.append(error.getDefaultMessage()); msg.append("\n"); } resultMap.put("resultCode", "300"); resultMap.put("resultMessage", msg.toString()); }else if(!loginVO.getPassword().equals(loginVO.getPasswordChk())){ resultMap.put("resultCode", "300"); resultMap.put("resultMessage", "비밀번호 확인이 잘못 입력되었습니다."); }else{ Integer insertResult = loginService.insertUser(loginVO); if(insertResult!=null){ resultMap.put("resultCode", "200"); resultMap.put("resultMessage", "저장 되었습니다."); }else{ resultMap.put("resultCode", "300"); resultMap.put("resultMessage", "저장에 실패하였습니다."); } } return resultMap; } /** * 로그아웃한다. * @return resultVO * @exception Exception */ @Operation( summary = "로그아웃", description = "로그아웃 처리(JWT,일반 관계 없이)", tags = {"EgovLoginApiController"} ) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "로그아웃 성공"), }) @GetMapping(value = "/logout") public ResultVO actionLogoutJSON(HttpServletRequest request, HttpServletResponse response) throws Exception { ResultVO resultVO = new ResultVO(); new SecurityContextLogoutHandler().logout(request, response, null); resultVO.setResultCode(ResponseCode.SUCCESS.getCode()); resultVO.setResultMessage(ResponseCode.SUCCESS.getMessage()); return resultVO; } }