본문 바로가기
Spring/Security

Security 로그인 검증 로직 및 csrf 설정

by 영기사전 2024. 2. 21.
@Service
public class CustomUserDetailsService implements UserDetailsService {

	@Autowired
    private UserRepository userRepository;
    
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    
    	UserEntity userEntity = userRepository.findByUsername(username);
        
        if (userEntity != null) { //널이아니면 user가 있는것
        	return new CustomUserDetails(userEntity);
        }
        
        return null;
    
    }

}

 

dto 폴더에 CustomUserDetails.java 생성

CustomUserDetails implements UserDetails {

	@Override
    .....

}

 

개발환경에서는 csrf.disable()되어있지만 배포시에는 enable로 설정후 배포

enable설정시 스프링 시큐리티는 CsrfFilter를 통해 POST,PUT,DELETE 요청에 대해서 토큰 검증을 진행한다.

 

 

 

'Spring > Security' 카테고리의 다른 글

Security 로그인 검증 로직  (0) 2024.02.21
Security 커스텀 로그인 설정  (0) 2024.02.21
Security Config 설정  (0) 2024.02.21

댓글