본문 바로가기
Spring/Security

Security 커스텀 로그인 설정

by 영기사전 2024. 2. 21.

LoginController /login경로 접근시 login폼 이동하게 작성

 

SecurityConfig에 다음과같이 코드를 추가한다.

http
	.formLogin((auth) -> auth.loginPage("/login")
    .loginProcessingUrl("/loginProc")
    .permitAll()
   	);
    
http
	.csrf((auth) -> auth.disable());

 

인가되지 않은 경로로 접근시 로그인하지않은 경우 "/login" 경로로 이동,

로그인진행은 /loginProc경로로 요청하며 로그인 이후 모든경로를 모두허용(hasRole권한이 없는 경로는 제외)한다.

csrf는 enable시 post요청시에 header에 토큰값을 보내주어야 하므로 임시적으로 disable 한다.

 

// 패스워드 단방향 해쉬 암호화 메서드
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
	return new BCryptPasswordEncoder();
}

 

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

Security 로그인 검증 로직 및 csrf 설정  (0) 2024.02.21
Security 로그인 검증 로직  (0) 2024.02.21
Security Config 설정  (0) 2024.02.21

댓글