분류 전체보기
[Spring Batch] 배치 도메인 이해
[Spring Batch] 배치 도메인 이해
2024.06.30@SpringBootApplication@EnableBatchProcessing(dataSourceRef = "batchDataSource", transactionManagerRef = "batchTransactionManager")public class SpringBatchMasterApplication { public static void main(String[] args) { SpringApplication.run(SpringBatchMasterApplication.class, args); }} 스프링 배치 애플리케이션을 활성화하려면 @EnableBatchProcessing 애너테이션을 메인 클래스 위에 붙여줘야 한다. 애너테이션은 4개의 설정 클래스를 실행시켜 스프링 배치 초기 설정과 초기화를..
[Spring Security] 인가 프로세스
[Spring Security] 인가 프로세스
2024.06.22스프링 시큐리티는 요청과 메서드 단위로 권한을 부여해 보안을 관리한다. 요청 기반 권한 부여는 HttpServletRequest에 대한 권한 부여를 모델링해 HttpSecurity 인스턴스를 사용해 권한 규칙을 선언할 수 있다. http.authorizeHttpRequests(authorize -> authorize .requestMatchers("/user").hasAuthority("USER") .requestMatchers("/mypage/**").hasAuthority("USER") .requestMatchers(HttpMethod.GET, "/**").hasAuthority("read") .requestMatchers(RegexRequestMatcher.regexMatch..
[Spring Security] 인증 실패 오류 다루기
[Spring Security] 인증 실패 오류 다루기
2024.06.20스프링 시큐리티에서는 인증 관련 예외가 발생한 경우 AbstractUserDetailsAuthenticationProvider 가 클래스 내부의 hideUserNotFountExceptions 변수를 확인하고 발생한 예외를 BadCredentialsException 예외로 변환해 어떤 예외가 종류의 예외가 발생했는지 감춘다. // AbstractUserDetailsAuthenticationProvider.class@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Assert.isInstanceOf(UsernamePasswordAuthenticationToken..
[Spring Security] 예외 처리
[Spring Security] 예외 처리
2024.06.12스프링 시큐리티에서 발생하는 예외는 AuthenticationException과 AccessDeniedException으로 나뉘며, ExceptionTranslationFilter가 예외를 처리한다. AuthenticationException 발생 시 SecurityContext 에서 인증 정보를 삭제하고 Authentication을 초기화한다. 필터는 authenticationEntryPoint를 실행해 인증 실패를 공통적으로 처리하고 인증을 요청할 수 있는 화면으로 이동시킨다.인증 프로세스의 요청 정보는 RequestCache, SavedRequest에 저장해 사용자가 인증을 마친 후 재사용한다. AccessDeniedException 발생 시 필터는 사용자가 익명 사용자인지를 먼저 판단하고, 익명 ..
[Spring Security] 인증 상태 영속성
[Spring Security] 인증 상태 영속성
2024.06.10사용자가 인증을 마친 이후 인증을 유지하기 위해 SecurityContextRepository 클래스를 사용한다.인증 정보와 권한은 SecurityContext에 저장되고, SecurityContext는 다시 HttpSession에 저장돼 요청 간 영속이 이루어진다. SpringContextRepository 인터페이스를 구현한 구현체로는 두 가지가 있는데, 그 중 하나가 HttpSession에 인증 상태를 저장하는 역할을 수행한다. 인증을 마친 후 요청할 때는 SecurityCOntextHolderFilter에서 컨텍스트를 로드해 인증 상태가 저장되어있는지 확인한다. public interface SecurityContextRepository { @Deprecated SecurityCon..
[Spring Security] 인증 아키텍처
[Spring Security] 인증 아키텍처
2024.06.08사용자가 요청하면 서블릿 필터인 DelegatingFilterProxy가 요청을 받아 스프링 필터 쪽으로 요청을 넘긴다. AuthenticationFilter는 Authentication 객체를 만들어 AuthenticationManager에게 넘겨준다. Manager는Provider에게 인증을 위임해 사용자의 ID / PASSWORD를 검증시키는데, 이 때 UserDetailsService 객체로 사용자 정보를 가져온다. 인증에 성공했다면 UserDetailService는UserDeatils 타입의 객체를 만들고, 이 객체는 다시 Provider로 올라간 후 Authentication 객체를 만든다. 만들어진 Authentication 객체는 SecurityContextHolder를 통해 Securi..
[SQL Server] 지원하지 않는 TLS 버전 설정
[SQL Server] 지원하지 않는 TLS 버전 설정
2024.06.05datasource: db1: jdbc-url: jdbc:sqlserver://192.168.10.224:1433;encrypt=true;integratedSecurity=true;trustServerCertificate=true; username: dbuser password: 1234 # driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver 스프링부트에서 SQL Server를 사용할 때 사용하는 설정이다. encrypt : 연결을 암호화할지를 결정한다. 서버(SQL Server)는 SSL ..
[Spring Security] 인증 메커니즘
[Spring Security] 인증 메커니즘
2024.05.30기본적으로 HTTP 기반 form 로그인 인증을 사용한다. @Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) .formLogin((form) -> form .loginPage("/login") .loginProcessingUrl("/loginProcess") .defaultSuccessUrl("/", true) .failureUrl("/failed") ..
[Spring Security] 초기화 과정
[Spring Security] 초기화 과정
2024.05.27스프링 시큐리티는 애플리케이션 시작 시 수행되는 초기화 과정에서 인증이나 인가에 관련된 여러 작업을 수행한다. 스프링 시큐리티 의존성을 추가한 후 애플리케이션을 실행하면 의존성으로 내려받은 SpringBootWebSecurityConfiguration 클래스를 통해 초기 설정을 진행한다. @Configuration(proxyBeanMethods = false)@ConditionalOnDefaultWebSecuritystatic class SecurityFilterChainConfiguration { @Bean @Order(SecurityProperties.BASIC_AUTH_ORDER) SecurityFilterChain defaultSecurityFilterChain(HttpSecu..
[Redis] 동시성 제어
[Redis] 동시성 제어
2024.05.25Redis는 캐시 저장소로 사용되지만.. 일단 "데이터베이스" 이니 일관성, 동시성, 신뢰성을 보장하기 위해 트랜잭션을 지원한다. await isolatedClient.watch(itemsKey(attrs.itemId));return isolatedClient .multi() .rPush(bidHistoryKey(attrs.itemId), serialized) .hSet(itemsKey(item.id), { bids:item.bids + 1, price: attrs.amount, highestBidUserId: attrs.userId }) .zAdd(itemsByPriceKey(), { value: item.id, ..
[Redis] 파이프라인과 자료구조
[Redis] 파이프라인과 자료구조
2024.05.15자바, 파이썬, 자바스크립트 등 백엔드를 구축할 때 사용되는 다양한 프로그래밍 언어와 프레임워크 수준에서 Redis를 사용할 수 있도록 지원하는 라이브러리를 제공한다. 자바는 Jedis 라이브러리로 Redis를 사용하는 직관적인 API를 제공하고, 스프링 프레임워크는 Spring Data Redis 라이브러리를 사용해 스프링에서 Redis를 더 쉽게 다룰 수 있다. 이 라이브러리들은 내부적으로 Redis 명령어를 사용해 Redis 서버와 상호작용하니.. Redis의 명령어 구성을 추상화하고 프로그래밍 언어와 프레임워크의 특성에 맞춘 직관적인 API를 제공한다고 생각하면 된다. const cacheRoutes = [ '/about', '/privacy', '/auth/signin', '/auth/..
[Redis] 캐시 서버와 명령어
[Redis] 캐시 서버와 명령어
2024.04.27Redis는 다른 데이터베이스들과 마찬가지로 데이터를 저장하고 쿼리를 통해 데이터를 가져올 수 있는 데이터베이스지만, Redis의 몇 가지 특징 덕분에 다른 데이터베이스들보다 속도가 빠르다. 기본적으로 많은 DBMS는 데이터를 HDD나 SSD에 저장해 데이터의 영속성을 보장한다.반면 Redis는 데이터를 RAM에 저장해 HDD나 SSD에 데이터를 저장할 때 보다 읽기 및 쓰기 작업을 훨씬 빠르게 수행할 수 있다. 이 외에도 다른 DBMS와는 다르게 Redis는 스키마 대신 key-value 쌍으로 데이터를 저장하고 각 key에 대해 여러 자료구조를 선택해서 사용할 수 있는 등 여러 차별화된 특징을 가지고, 이 특징 덕분에 높은 성능을 보장한다. Redis에서는 문자열인 키..