본문 바로가기

Spring Security4

Security 인가 API 표현식 authenticated() 인증된 사용자의 접근을 허용 fullyAuthenticated() 인증된 사용자의 접근을 허용, rememberMe 인증은 허용하지 않음 permitAll() 무조건 접근을 허용 denyAll() 무조건 접근을 허용하지 않음 anonymous() 익명사용자만을 접근 허용(ROLE_ANONYMOUS 만 허용) rememberMe() 기억하기를 통해 인증된 사용자의 접근을 허용 access(String) 주어진 SpEL 표현식의 평가 결과가 trued이면 접근 허용 hasRole(String) 사용자의 Role이 일치하면 접근을 허용(ROLE_USER) hasAuthority(String) 사용자의 권한이 일치하면 접근을 허용(ROLE_USER에서 ROLE이 빠진 USER가 일치.. 2022. 3. 31.
Security - RememberMeAuthenticationFilter RememberMeAuthenticationFilter가 사용자 요청을 받아서 그 요청을 실행하는 조건이 있다. Authentication 인증 객체가 null일 경우 사용자 세션이 만료(session timeout)되거나 끊겨서(브라우저 종료) 더 이상 세션 안에서 SecurityContext를 찾지 못하고, SecurityContext가 존재하지 않기 때문에 Authentication 객체도 없는 경우 사용자가 Remember-Me 쿠키를 가지고 요청을 할 경우 동작 방식 사용자가 RememberMe 기능을 활성화시키고 요청을 하면 RememberMeAuthenticationFilter가 동작한다. RememberMeService 인터페이스의 구현체로 인증 처리한다. TokenBasedRemeberM.. 2022. 3. 29.
Security - LogoutFilter 로그아웃 요청을 하면 LogoutFilter가 요청을 받는다 AntPathRequestMatcher가 logout 요청 url 인지 확인한다. 일치하지 않으면 다음 필터로 넘어간다 일치하면 LogoutFilter가 SecurityContext로 부터 인증 객체 Authentication를 가져와서 LogoutHandler에게 전달한다. LogoutHandler가 몇개 있는데 그 중 SecurityContextLogoutHandler가 세션 무효화, 쿠키 삭제, SecurityContextHandler.clearContext()를 실행해서 인증객체를 null로 초기화한다. LogoutHandler가 성공적으로 종료가 되면 LogoutFilter는 SimpleUrlLogoutSuccessHandler를 호출.. 2022. 3. 29.
Security - Login Form 인증 요청이 들어오면 UsernamePasswordAuthenticationFilter를 거친다. AntPathRequestMatcher가 요청 URL 정보가 login(default) 인지 확인한다.(loginProcessingUrl("/login")) 매치되지 않는다면 다음 필터를 실행한다. URL 정보가 일치하면 Username + Password가 저장된 Authentication 인증 객체를 만든다. AuthenticationManager(인증 관리자)에 인증 객체를 넣어서 인증 처리를 실행한다. AuthenticationManager 내부에는 AuthenticationProvider 객체들을 가지고 있고, 그 중 하나를 선택해서 인증 처리를 위임한다. AuthenticationProvider 클래스.. 2022. 3. 29.