1. 참조: https://kitty-geno.tistory.com/131

  2. 부트 3.0 참조: https://nahwasa.com/entry/스프링부트-30이상-Spring-Security-기본-세팅-스프링-시큐리티

  3. filter 순서 참조: https://velog.io/@ewan/Spring-Security-Custom-Authentication-Provider

  4. 프로젝트 참조: https://velog.io/@dailylifecoding/Spring-Security-Custom-Form-Login-practice-2

  5. gradle

    implementation: 'org.springframework.boot:spring-boot-starter-security'
    
  6. HttpSecurity Config

    Untitled

    1. security설정은 기본적으로 WebSecurityConfigurerAdapter를 구현하고 해당 객체의 메서드를 재정의해서 config를 설정

    2. CSRF

      Untitled

      1. 참조: https://memo-the-day.tistory.com/145
      2. .csrf().disable()를 통해 csrf를 비활성화
      3. CSRF란 웹 앱의 취약점 중 하나, 인터넷 사용자가 자신의 의지와는 달리 공격자가 의도한 행위(수정, 삭제 등)을 특정 웹사이트로 요청하는 것
      4. 예시로는 SNS계정을 해킹하여 광고를 업로드하는 행위
      5. 현재는 비활성화 상태이며, 예제처럼 csrf토큰을 form에 작성하고 해당 token으로 사용자의 요청을 구분
    3. .antMatchers()

      1. .permitAll(): antMatchers()메서드에 나열된 URL에 대해 모든 사용자의 접근 허용
      2. .authenticated(): antMatchers()메서드네 나열된 URL에 대해 인증된 사용자의 접근만 허용
      3. .anyRequest()antMatchers()에서 작성되지 않은 URL모두 포함
    4. .formLogin()

      1. form을 이용한 로그인 활성화
      2. .loginPage()기본적으로 기본 form을 제공하지만 커스텀 form을 사용하는 경우 사용
      3. .loginProcessingUrl() 해당 URL로 POST요청을 하면 시큐리티가 가로채서 로그인 처리
      4. .successHandler() 로그인 성공시 핸들러(SimpleUrlAuthenticationSuccessHandler 구현체 등록)
      5. .failureHadler() 로그인 실패시 핸들러(SimpleUrlAuthenticationFailureHandler 구현체 등록)
    5. .logout()

      1. 로그아웃 활성화
      2. .logoutRequestMatcher(new AntPathRequestMatcher()) 로그아웃 URL 등록
      3. .logoutSuccessUrl() 로그아웃 성공시 Redirect URL 작성
      4. .invalidateHttpSession() 인증정보, 세션을 무효화(boolean 타입)
      5. .deleteCookies() 특정 쿠키를 삭제(key를 전달)
    6. sessionManagement()

      1. 세션 관리 활성화
      2. .maximumSessions() 세션 최대 허용 수(-1인 경우 무제한 세션)
      3. .maxSessionPreventsLogin() true → 중복 로그인 제한/false → 이전 로그인 세션 해체
      4. .expireUrl() 세션이 만료된 경우 이동 할 페이지
    7. .rememberMe()

      1. 로그인 유지, JSESSIONID같은 쿠키가 없더라도 사용자를 기억하는 기
      2. .alwaysRemember() true → 항상 기억 / false → 항상 기억하지 않음
      3. .tokenValiditySeconds() 저장 시간(초단위)
      4. .rememberMe() 전달한 키 값으로 저장
      5. .userDetailsService() 기능을 사용할 때 사용자 정보
  7. AuthenticationManagerBuilder Config

    Untitled

    1. 로그인시 내부적으로 비밀번호를 복호화하고 비교하는 로직이 포함됨
    2. userDetailsServiceUserDetailsService 인터페이스를 구현한 객체를 전달
    3. 해당 객체의 loadUserByUsername()메서드를 활용
  8. SecurityContextHolder

    1. SecurityContextHolder