시간의화살
Recent Posts
-
[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") ..