authentication interceptor
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package com.example.oneul.domain.user.dto;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import com.example.oneul.domain.user.domain.UserEntity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class LoginDTO {
|
||||
@NotBlank
|
||||
private String username;
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
public void setUsername(String username){
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.example.oneul.domain.user.dto;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import com.example.oneul.domain.user.domain.UserEntity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class SignUpDTO {
|
||||
@NotBlank
|
||||
private String username;
|
||||
@NotBlank
|
||||
private String password1;
|
||||
@NotBlank
|
||||
private String password2;
|
||||
|
||||
public void setUsername(String username ){
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.example.oneul.global.config.security;
|
||||
|
||||
import com.example.oneul.global.util.LoginCheckInterceptor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class InterceptorConfig implements WebMvcConfigurer {
|
||||
@Value("${login-page}")
|
||||
private String loginPage;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry interceptorRegistry){
|
||||
// TODO: 왜 exception이 다시 prehandler로 돌아가냐
|
||||
interceptorRegistry.addInterceptor(new LoginCheckInterceptor(loginPage))
|
||||
.excludePathPatterns("/user/login/**", "/user/signup/**");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.oneul.global.error;
|
||||
|
||||
import com.example.oneul.domain.user.exception.UserAlreadyExistException;
|
||||
import com.example.oneul.domain.user.exception.WrongUsernameAndPasswordException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -13,13 +14,19 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
protected String handleException(Exception e){
|
||||
log.debug(e.getMessage());
|
||||
log.info(e.getMessage());
|
||||
return e.toString();
|
||||
}
|
||||
|
||||
@ExceptionHandler(UserAlreadyExistException.class)
|
||||
protected String handleUserAlreadyExistException(UserAlreadyExistException e){
|
||||
log.debug(e.getMessage());
|
||||
log.info(e.getMessage());
|
||||
return e.toString();
|
||||
}
|
||||
|
||||
@ExceptionHandler(WrongUsernameAndPasswordException.class)
|
||||
protected String handleWrongUsernameAndPasswordException(WrongUsernameAndPasswordException e){
|
||||
log.info(e.getMessage());
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,16 @@ import com.example.oneul.domain.user.domain.UserEntity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
public class LoginCheckInterceptor implements HandlerInterceptor{
|
||||
@Value("${login-page}")
|
||||
private String loginPage;
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(LoginCheckInterceptor.class);
|
||||
|
||||
public LoginCheckInterceptor(String loginPage){
|
||||
this.loginPage = loginPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
log.info("login check prehandler");
|
||||
|
||||
@@ -30,4 +30,4 @@ logging:
|
||||
hibernate:
|
||||
SQL: DEBUG
|
||||
|
||||
log-in-page: www.naver.com
|
||||
login-page: https://www.naver.com
|
||||
@@ -31,4 +31,4 @@ logging:
|
||||
hibernate:
|
||||
SQL: DEBUG
|
||||
|
||||
log-in-page: www.naver.com
|
||||
login-page: https://www.google.com
|
||||
@@ -28,3 +28,5 @@ logging:
|
||||
org:
|
||||
hibernate:
|
||||
SQL: DEBUG
|
||||
|
||||
login-page: https://www.naver.com
|
||||
Reference in New Issue
Block a user