authentication interceptor
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
package com.example.oneul.domain.user.dto;
|
package com.example.oneul.domain.user.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
import com.example.oneul.domain.user.domain.UserEntity;
|
import com.example.oneul.domain.user.domain.UserEntity;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class LoginDTO {
|
public class LoginDTO {
|
||||||
|
@NotBlank
|
||||||
private String username;
|
private String username;
|
||||||
|
@NotBlank
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public void setUsername(String username){
|
public void setUsername(String username){
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package com.example.oneul.domain.user.dto;
|
package com.example.oneul.domain.user.dto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
import com.example.oneul.domain.user.domain.UserEntity;
|
import com.example.oneul.domain.user.domain.UserEntity;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class SignUpDTO {
|
public class SignUpDTO {
|
||||||
|
@NotBlank
|
||||||
private String username;
|
private String username;
|
||||||
|
@NotBlank
|
||||||
private String password1;
|
private String password1;
|
||||||
|
@NotBlank
|
||||||
private String password2;
|
private String password2;
|
||||||
|
|
||||||
public void setUsername(String username ){
|
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/**");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,8 +19,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity httpSecurity) throws Exception {
|
protected void configure(HttpSecurity httpSecurity) throws Exception {
|
||||||
httpSecurity.cors().disable()
|
httpSecurity.cors().disable()
|
||||||
.csrf().disable()
|
.csrf().disable()
|
||||||
.formLogin().disable()
|
.formLogin().disable()
|
||||||
.headers().frameOptions().disable();
|
.headers().frameOptions().disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.oneul.global.error;
|
package com.example.oneul.global.error;
|
||||||
|
|
||||||
import com.example.oneul.domain.user.exception.UserAlreadyExistException;
|
import com.example.oneul.domain.user.exception.UserAlreadyExistException;
|
||||||
|
import com.example.oneul.domain.user.exception.WrongUsernameAndPasswordException;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -13,13 +14,19 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
protected String handleException(Exception e){
|
protected String handleException(Exception e){
|
||||||
log.debug(e.getMessage());
|
log.info(e.getMessage());
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(UserAlreadyExistException.class)
|
@ExceptionHandler(UserAlreadyExistException.class)
|
||||||
protected String handleUserAlreadyExistException(UserAlreadyExistException e){
|
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();
|
return e.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,16 @@ import com.example.oneul.domain.user.domain.UserEntity;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
public class LoginCheckInterceptor implements HandlerInterceptor{
|
public class LoginCheckInterceptor implements HandlerInterceptor{
|
||||||
@Value("${login-page}")
|
|
||||||
private String loginPage;
|
private String loginPage;
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(LoginCheckInterceptor.class);
|
private final Logger log = LoggerFactory.getLogger(LoginCheckInterceptor.class);
|
||||||
|
|
||||||
|
public LoginCheckInterceptor(String loginPage){
|
||||||
|
this.loginPage = loginPage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
log.info("login check prehandler");
|
log.info("login check prehandler");
|
||||||
|
|||||||
@@ -30,4 +30,4 @@ logging:
|
|||||||
hibernate:
|
hibernate:
|
||||||
SQL: DEBUG
|
SQL: DEBUG
|
||||||
|
|
||||||
log-in-page: www.naver.com
|
login-page: https://www.naver.com
|
||||||
@@ -31,4 +31,4 @@ logging:
|
|||||||
hibernate:
|
hibernate:
|
||||||
SQL: DEBUG
|
SQL: DEBUG
|
||||||
|
|
||||||
log-in-page: www.naver.com
|
login-page: https://www.google.com
|
||||||
@@ -27,4 +27,6 @@ logging:
|
|||||||
web: DEBUG
|
web: DEBUG
|
||||||
org:
|
org:
|
||||||
hibernate:
|
hibernate:
|
||||||
SQL: DEBUG
|
SQL: DEBUG
|
||||||
|
|
||||||
|
login-page: https://www.naver.com
|
||||||
Reference in New Issue
Block a user