본문 바로가기

개발 관련 지식/Spring Framework Basic16

Security - Authorization 인가 개념 스프링 시큐리티가 지원하는 권한 계층 웹 계층 URL 요청에 따른 메뉴 혹은 화면 단위의 레벨 보안 url에 접근 가능한 권한과 사용자의 권한을 비교해서 인가 처리 서비스 계층 화면 단위가 아닌 메소드 같은 기능 단위의 레벨 보안 도메인 계층 객체 단위의 레벨 보안 인가 프로세스 사용자 요청 FilterSecurityInterceptor가 요청을 받아서 인증 여부를 체크한다 SecurityMetadataSource 클래스가 자원에 접근하기 위해 필요한 권한 정보를 조회한다. 접근에 필요한 권한 정보가 따로 없으면 자원에 접근 허용한다. 권한 정보를 AccessDecisionManager에서 내부적으로 AccessDecisionVoter가 승인/거부 결과를 AccessDecisionManager에게 반환한.. 2022. 4. 3.
Security - 인증 Flow 클라이언트가 로그인 요청 Form 인증 방식 요청이면 UsernamePasswordAuthenticationFilter가 로그인 요청을 받아서 Authentication 인증 객체를 생성한다. Authentication : username + password 담은 인증 전 토큰 객체 생성 UsernamePasswordAuthenticationFilter는 AuthenticationManager에 인증 객체를 전달하며 인증 처리를 맡긴다. AuthenticationManager는 AuthenticationProvider에게 실제 인증을 위임한다. AuthenticationProvider가 여러개 있는데 그 중 하나에 실제 인증을 위임하는 것이 manager의 역할 AuthenticationProvier는 .. 2022. 4. 3.
Security - Authentication(인증) 개념 사용자의 인증정보를 저장하는 토큰 개념 인증 시 id와 password를 담고 인증 검증을 위해 전달되어 사용된다. 인증 후 최종 인증 결과(user 객체, 권한 정보)를 담고 SecurityContext에 저장되어 전역적으로 참조 가능 Authentication authentication = SecurityContextHolder.getContext().getAuthentication() 구조 principal : 사용자의 아이디 혹은 User 객체를 저장 credentials : 사용자 비밀번호 authorities : 인증된 사용자의 권한 목록 details : 인증 부가 정보 authenticated : 인증 여부 인증 흐름 로그인 요청(username + password) UsernamePass.. 2022. 4. 3.
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.