1. [Spring Boot] WebSecurityConfigurerAdapter가 Deprecated 되었으므로 코드 변경
기존 스프링 시큐리티 환경 설정 클래스
@Configuration
@EnableWebSecurity
public class JBlogWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
// 사용자가 입력한 username으로 사용자를 인증하는 객체
@Autowired
private UserDetailsServiceImpl userDetailsService;
// 사용자가 입력한 username으로 사용자를 인증하는 객체 (구글 용)
@Autowired private OAuth2UserDetailsServiceImpl oauth2DetailsService;
// 순환 참조 문제를 해결하기 위해 JBlogWebCommonConfiguration에서 PasswordEncoder를 받아온다
@Autowired private PasswordEncoder passwordEncoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
// 인증 없이 접근을 허용하는 경로
http.authorizeRequests().antMatchers("/webjars/**", "/js/**", "/image/**", "/", "/auth/**").permitAll();
// 나머지 경로의 접근은 인증이 필요하다
http.authorizeRequests().anyRequest().authenticated();
// CSRF 토큰을 받지 않음
http.csrf().disable();
// 사용자 정의 로그인 화면 제공
http.formLogin().loginPage("/auth/login");
http.formLogin().loginProcessingUrl("/auth/securitylogin");
// 로그아웃 설정
http.logout().logoutUrl("/auth/logout").logoutSuccessUrl("/");
// 구글 로그인 설정을 시작
http.oauth2Login()
.userInfoEndpoint() // OAuth2로 사용자 정보를 가져온다
.userService(oauth2DetailsService);
// 가져온 사용자 정보를 이용해서 oauth2DetailsService 객체로 사후처리한다
}
// 사용자가 입력한 username으로 User 객체를 검색하고, password를 비교한다
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
SecurityFilterChain을 @Bean 으로 등록하는 방법으로 변경된 코드
// WebSecurityConfigurerAdapter 가 Deprecated 되었으므로, 대체한다
@Configuration
@EnableWebSecurity
public class JBlogWebSecurityConfiguration {
// 사용자가 입력한 username으로 사용자를 인증하는 객체 (카카오 용)
@Autowired private UserDetailsServiceImpl userDetailsService;
// 사용자가 입력한 username으로 사용자를 인증하는 객체 (구글 용)
@Autowired private OAuth2UserDetailsServiceImpl oauth2DetailsService;
// 순환 참조 문제를 해결하기 위해 JBlogWebCommonConfiguration에서 PasswordEncoder를 받아온다
@Autowired private PasswordEncoder passwordEncoder;
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// 인증 없이 접근을 허용하는 경로
http.authorizeRequests().antMatchers("/webjars/**", "/js/**",
"/image/**", "/", "/auth/**", "/oauth/**").permitAll();
// 나머지 경로의 접근은 인증이 필요하다
http.authorizeRequests().anyRequest().authenticated();
// CSRF 토큰을 받지 않음
http.csrf().disable();
// 사용자 정의 로그인 화면 제공
http.formLogin().loginPage("/auth/login");
http.formLogin().loginProcessingUrl("/auth/securitylogin");
// 로그아웃 설정
http.logout().logoutUrl("/auth/logout").logoutSuccessUrl("/");
// 구글 로그인 설정을 시작
http.oauth2Login()
.userInfoEndpoint() // OAuth2로 사용자 정보를 가져온다
.userService(oauth2DetailsService);
// 가져온 사용자 정보를 이용해서 oauth2DetailsService 객체로 사후처리한다
return http.build();
}
// AuthenticationManager도 Bean으로 생성한다
@Bean
AuthenticationManager authenticationManager(
AuthenticationConfiguration authenticationConfiguration) throws Exception {
return authenticationConfiguration.getAuthenticationManager();
}
}
2. IntelliJ에서 Maven 빌드하는 2가지 방법
https://hianna.tistory.com/801
[IntelliJ] 인텔리제이 maven 빌드하는 2가지 방법
IntelliJ에서 maven 빌드 2가지 방법 maven 도구 창 이용하기 configuration 설정하기 1. maven 도구 창 이용하기 간단하게 maven 도구창에서 원하는 lifecycle을 더블클릭하여 빌드할 수 있습니다. compile, test, pac
hianna.tistory.com
3. AWS Elastic Beanstalk 에서 환경 생성할 때 주의사항
새로운 AWS 계정이거나, EC2 키페어/EC2 인스턴스 프로파일을 생성하지 않았다면
AWS Elastic Beanstalk으로 배포하기
IAM 인스턴스? 생성 방법 그 링크키페어 생성방법생활코딩 AWS Elastic Beanstalkhttps://www.youtube.com/watch?v=g7W5LK1DM8o&t=498sDB연동 방법 및 워크벤치 연결 오류 디버깅https://yout
velog.io
이 글의 7번 단락을 참고하여 EC2 키페어, EC2 인스턴스 프로파일을 반드시 생성해야
책에서는 설명하지 않는 서비스 액세스를 구성할 수 있고, 환경을 생성할 수 있다.
4. MySQL 연동할 때 에러
<!-- DBMS를 H2 -> MySQL을 사용하기 위해서 MySQL Connector 추가 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<version>을 지정하자!