로그인 에러 처리 변경
This commit is contained in:
+9
@@ -33,4 +33,13 @@ public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler
|
||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ExceptionHandler(UserNotLoginException.class)
|
||||
public ResponseEntity<CustomErrorResponse> customHandleUserNotLogin(Exception ex, WebRequest request) {
|
||||
CustomErrorResponse errors = new CustomErrorResponse();
|
||||
errors.setTimestamp(LocalDateTime.now());
|
||||
errors.setError(ex.getMessage());
|
||||
errors.setStatus(HttpStatus.UNAUTHORIZED.value());
|
||||
return new ResponseEntity<>(errors, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-6
@@ -1,13 +1,12 @@
|
||||
package com.eactive.httpmockserver.common.interceptor;
|
||||
|
||||
|
||||
import com.eactive.httpmockserver.common.exception.UserNotLoginException;
|
||||
import com.eactive.httpmockserver.common.util.SecurityUtil;
|
||||
import com.eactive.httpmockserver.user.entity.AnonymousUser;
|
||||
import com.eactive.httpmockserver.user.entity.User;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.ModelAndViewDefiningException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -48,8 +47,7 @@ public class AuthenticInterceptor implements AsyncHandlerInterceptor {
|
||||
User currentUser = SecurityUtil.getCurrentUser();
|
||||
|
||||
if (currentUser == null || currentUser instanceof AnonymousUser) {
|
||||
ModelAndView redirectLoginView = new ModelAndView("redirect:/login");
|
||||
throw new ModelAndViewDefiningException(redirectLoginView);
|
||||
throw new UserNotLoginException();
|
||||
}
|
||||
|
||||
boolean found = findPattern(request.getRequestURI());
|
||||
@@ -58,8 +56,7 @@ public class AuthenticInterceptor implements AsyncHandlerInterceptor {
|
||||
if (currentUser.getUserSecurity() != null && "ROLE_ADMIN".equals(currentUser.getUserSecurity())) {
|
||||
return true;
|
||||
} else {
|
||||
ModelAndView redirectLoginView = new ModelAndView("redirect:/");
|
||||
throw new ModelAndViewDefiningException(redirectLoginView);
|
||||
throw new UserNotLoginException();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -60,7 +60,6 @@ public class LoginController {
|
||||
|
||||
/**
|
||||
* 세션타임아웃 시간을 연장한다.
|
||||
* Cookie에 egovLatestServerTime, egovExpireSessionTime 기록하도록 한다.
|
||||
*
|
||||
* @return result - String
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user