스프링시큐리티 3

[Thymeleaf] 타임리프로 화면단에서 사용자 시큐리티 정보 가져오기

스프링 시큐리티 인증을 받은 로그인 한 사용자의 정보를 타임리프에서 사용하고 싶을 때 사용합니다. .gradle 설정 implementation 'org.springframework.boot:spring-boot-starter-security' // 타임리프에서 스프링시큐리티의 문법이나 형식을 지원하는 확장팩 라이브러리 implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' 우선 네임스페이스를 등록합니다. 사용 예시 출력 결과 1. 사용자 이름 2. 사용자 권한 3. 사용자 인증여부 추가로 아래는 조건의 결과를 true, false로 if와 같은 기능으로 사용 가능합니다. 참조. Thymeleaf + Spring Security in..

Thymeleaf 2021.11.10

[Security] Remember Me 인증 필터 (RememberMeAuthenticationFilter)

rememberMe기능을 활성화하여 로그인할 경우 사용자는 인증 객체를 담은 session과 함께 remember-me 쿠키를 받아 자원에 접근하게 된다. * rememberMe의 다양한 설정의 api들은 차후에 다뤄보자. 이후로 사용자의 세션이 만료되거나 사용자 브라우저 종료로 인하여 세션이 끊긴 경우 즉, 세션이 활성화되지 않아 인증 객체를 SecurityContext에서 찾지 못하는 경우 자동적으로 사용자의 인증을 유지하기 위하여 RememberMeAuthenticationFilter가 실행된다. 즉, 정리해보면 다음과 같이 2가지 조건이 충족해야 RememberMeAuthenticationFilter가 실행된다. * 필터가 작동하는 경우 1. Authentication 객체가 null일 경우. (..

Spring Security 2021.10.05

[Security] Form Login 인증 필터 (UsernamePasswordAuthenticationFilter)

사용자가 로그인을 실행하면 인증처리가 이루어지는데 인증처리를 담당하고 그에 관련된 요청을 처리하는 필터가 UsernamePasswordAuthenticationFilter 이다. UsernamePasswordAuthenticationFilter 내부적으로 각각의 인증처리의 역할에 따라서 여러 클래스를 호출하여 처리하게 되며 전체적인 인증처리의 흐름을 살펴보자. 1. 인증 처리 전 작업 우선 처음 사용자 인증 시도를 하면 UsernamePasswordAuthenticationFilter가 요청을 받는다 그리고 AntPathRequestMatcher(/login)에서 사용자가 요청한 요청 정보가 매칭이 되는지 확인한다. (Default는 "/login"이다.) 매칭 실패 시 chain.doFilter으로 호..

Spring Security 2021.10.04