전체 글
Spring Security (4) - 기본설정과 JPA 연동
시큐리티 설정 Spring Security는 의존성만 추가해도 기본 인증 폼을 보내줍니다.(Spring boot 사용시 자동으로 auto config 되는 부분이 있음) ==> 자동 설정으로 id 가 user 이고 password 가 콘솔에 출력되는 유저를 생성합니다. Spring security 기본 설정 추가 org.springframework.boot spring-boot-starter-security // java 설정파일 // 시큐리티 설정 파일임을 나타냄 @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure..
Spring Security (3) - Authentication
Authentication 은 인증정보(Principal) 를 가지는 객체로 실제로 유효한 인증인지를 나타냅니다. 인증이 완료되기 전에는 사용자가 입력한 인증에 필요한 정보(username, password 등)를 가지고 있는 객체 인증이 완료되면, 인증 정보를 담는 객체 인증과정 인증되지 않은(로그인하지 않은) 상태에서 url 에 접근할 경우, AnonymousAuthenticationFilter 가 AnonymousAuthenticationToken(Authentication - 익명사용자를 나타내는 정보가 들어있음) 을 SecurityContextHolder 에 넣어줍니다. 인증을 요청하면 (로그인 요청) UsernamePasswordAuthenticationFilter (form login 시 인..
SpringSecurity - Test 작성
개요 Spring Test 를 작성하려고 하다보면, 인증이 필요한 부분이 있습니다. 인증이 필요한 부분에 간단하게 인증을 추가할 수 있는 방법을 소개하겠습니다. 해당 내용은 모두 스프링 공식 문서에서 확인할 수 있습니다.[https://docs.spring.io/spring-security/site/docs/current/reference/html5/#test-method] Annotation 기본적으로 SecrutityContext 는 method 테스트 직전에 초기화 되는데, 옵션을 통해 테스트 실행시에 한번만 초기화 되도록 할 수 있습니다@WithMockUser(setupBefore = TestExecutionEvent.TEST_EXECUTION) @WithMockUser username, role..
Swagger - API 문서 자동화
Swagger Swagger 는 annotation 기반의 REST API 문서를 만들어주는 프레임워크입니다. 간단하게 dependecy 를 추가하여 사용할 수 있습니다. io.springfox springfox-swagger2 2.9.2 Configration @Configuration @EnableSwagger2 public class Swagger2Configure implements WebMvcConfigurer { // Swagger SecurityConfiguration Bean 설정 @Bean public SecurityConfiguration security() { return SecurityConfigurationBuilder.builder() .scopeSeparator(",") .ad..
Spring Security(2) - SecurityContext
Security Filter 에서 인증된 정보를 저장하는 SecurityContext 에 대해 알아보겠습니다. SecurityContext 는 접근 주체와 인증에 대한 정보를 담고 있는 Context 입니다. 접근 주체인 Authentication 을 담고 있습니다. 정확히는 SecurityContextHolder 가 SecurityContextHolderStrategy 를 통해 SecurityContext 를 반환할 수 있고, SecurityContext 가 담고 있는 Authentication 정보를 가져올 수 있습니다. Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 위와 같은 형태로 P..