Sween의 개발 블로그
close
프로필 배경
프로필 로고

Sween의 개발 블로그

  • 분류 전체보기 (13)
    • Spring (1)
      • Spring Security (10)
      • Spring Data JPA (0)
      • Test (1)
    • Flutter (0)
    • 생각정리 (0)
    • IntelliJ (0)
    • 설계 (0)
    • Figma (0)
    • PM (0)
    • WIL (1)
  • 홈
  • 태그
  • 방명록

부록: JPA 엔티티에 UserDetails, OAuth2User 구현하지 말기

이전에 UserDetails와 OAuth2User를 바로 엔티티에 구현했던 적이 있었다.JPA는 하이버네이트 프록시 클래스 인스턴스를 생성해 반환하는 것을 알고난 후 그만두게 되었다.영속성 범위에 따라 fetch 문제가 생길 수 있다.물론 다음과같은 방법으로 실제 인스턴스를 반환받아 사용할 수도 있다.Hibernate.unproxy(paymentReceipt.getPayment());참고:https://www.baeldung.com/hibernate-proxy-to-real-entity-object 하지만 코드에 직관성이 떨어지며 해당 Principal로 반환된 인스턴스가 하이버네이트 프록시인지 아닌지 다른 로직에서 검사해야하는 골치아픔이 남게된다. 필드가 프록시인지 아닌지 항상 의심해야하는 상황이 발생..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 9. 1.
  • textsms

부록: 빈 생성 기능과 필터체인 분리

개요간혹 필터체인에서 참조하는 컴포넌트에서 PasswordEncoder 등 필터체인이 정의된 Configuration에 정의된 Bean을 사용해야해 문제가 발생하는 경우가 있다. 바로 하위가 아니더라도 UserService라던지... 회원가입 로직에서 사용하거나 할경우 발생한 적이 많았다. 그래서 다음과 같이 분리하는 방법을 자주 애용한다.@Configurationclass SecurityBeanGenerator { @Bean public UserDetailsService userDetailsService(UserRepository userRepository) { return username -> { UserEntity userEntity = userReposi..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 9. 1.
  • textsms

Spring Security 6 - OAuth 2 Client 간편 로그인 | 카카오 로그인

결과물 GitHub - jsween5723/spring-security-tistory: 티스토리 블로깅을 위한 예제티스토리 블로깅을 위한 예제. Contribute to jsween5723/spring-security-tistory development by creating an account on GitHub.github.com변경된 커밋UserDetails 클래스에 ID 추가https://github.com/jsween5723/spring-security-tistory/commit/59d32f5543bcdb69b98e93ab7864330938dbf222 * refactor · jsween5723/spring-security-tistory@59d32f5jsween5723 committed Aug 31,..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 8. 31.
  • textsms
Spring Security 6 - 일반 로그인 | 폼 로그인

Spring Security 6 - 일반 로그인 | 폼 로그인

질문은 자유롭게 남겨주세요!추가된 코드와 커밋private final ObjectMapper objectMapper; @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.cors(AbstractHttpConfigurer::disable).csrf(AbstractHttpConfigurer::disable).formLogin( conf -> conf.loginProcessingUrl("/api/v1/auth/login").successHandler( ((request, response, authenticat..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 8. 30.
  • textsms

Spring Security 6 - 컴포넌트 빈 정의

AuthenticationManager내부적으로 AuthenticationProvider를 사용해 인증하고 인증된 Authentication 인스턴스를 반환합니다.AuthenticationProvider에서 던져진 예외에 대한 처리도 담당합니다.구현체로는 ProviderManager가 있습니다. 단순히 정상적인 Authentication이 반환되거나 예외가 던져질 때까지 주입된 AuthenticationProvider들을 순차 실행합니다.AuthenticationProvider내부로직을 통해 인증된 Authentication 객체를 생성합니다.(isAuthenticated=true, 일반로그인 섹션 UsernamePasswordAuthenticationFilter에서 추가설명 예정)기본 주입 빈으로는 D..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 8. 29.
  • textsms

Spring Security 6 시리즈 작성계획

개요 스프링을 접하고 구글링을 하면서 항상 들었던 생각이 스프링 시큐리티가 변화된 것에 비해 블로그나 타 예제는 레거시한 컨텐츠가 재생산되고 있다는 것입니다. 특히 JWT 필터의 경우 Spring Security의 서드파티라고 볼 수 있는 oauth2 resource server 패키지에서 제공을 해주는데도 직접 구현을 하여 불필요한 버그가 발생되는 경우가 많았습니다. 처음 공부할 때 시큐리티가 오히려 어렵다고 느껴지는 원인중 하나였습니다. 이 시리즈에서는 입문자 입장에서 시큐리티로 쉽게 구현할 수 있는 기능들을 살펴보고 순차적으로 구현해보도록 할 것입니다. REST API일 때를 기준으로 어떤 방식으로 구현하는지 알아보겠습니다. 사용되는 예제는 레포지터리에서 각 커밋으로 확인하실 수 있습니다.목차1. ..

  • format_list_bulleted Spring/Spring Security
  • · 2024. 8. 29.
  • textsms
  • navigate_before
  • 1
  • 2
  • navigate_next
공지사항
전체 카테고리
  • 분류 전체보기 (13)
    • Spring (1)
      • Spring Security (10)
      • Spring Data JPA (0)
      • Test (1)
    • Flutter (0)
    • 생각정리 (0)
    • IntelliJ (0)
    • 설계 (0)
    • Figma (0)
    • PM (0)
    • WIL (1)
최근 글
인기 글
최근 댓글
태그
전체 방문자
오늘
어제
전체
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바