일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Gradle
- 프로그래머스
- 이분탐색
- 백트래킹
- DBASE&
- oracle ansi sql
- 이중우선순위큐 자바
- 프로그래머스 이중우선순위큐 java
- Spring Boot
- JPA
- SQL
- ansi sql 장점
- IT 면접 준비
- oracle ansi
- ansi sql 단점
- 백준
- CJ DBASE&
- 디베이스앤 인턴 후기
- 면접 필수 질문
- 프로그래머스 이중우선순위큐
- 디베이스앤
- BFS
- 위상정렬
- 그리디
- 개발자 면접 준비
- DP
- DFS
- 프로그래머스 이중우선순위큐 자바
- 이중우선순위큐 java
- Java
- Today
- Total
쉬운 프로그래밍
[Spring Boot] Spring Security Security Config 본문
package com.mkl.book.config.auth;
import com.mkl.book.user.domain.Role;
import lombok.RequiredArgsConstructor;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@RequiredArgsConstructor
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final CustomOAuth2UserService customOAuth2UserService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/", "/css/**", "/images/**", "/js/**")
.permitAll()
.antMatchers("api/v1/**")
.hasRole(Role.USER.name())
.anyRequest().authenticated()
.and()
.logout()
.logoutSuccessUrl("/")
.and()
.oauth2Login()
.userInfoEndpoint()
.userService(customOAuth2UserService);
}
}
* @EnableWebSecurity : Spring Securiry 설정 활성화
* authorizeRequests
- URL별 권한 관리를 설정하는 옵션의 시작점
- authorizeRequests가 선언되어야만 antMatchers 옵션 활성화 가능
* antMatchers
- 권한 관리 대상 옵션 지정
- URL / HTTP 메소드별로 지정 가능
- 위에서는 "/" 등 지정된 URL은 permitAll() 옵션을 통해 전체 열람 가능
- api/... URL은 USER ROLE을 가진 사람만 열람 가능하도록함
* anyRequest
- 설정한 값 외에 나머지 URL 나타냄
- 위에서는 authenticated()를 통해 로그인 한 사용자만 접속 가능하도록함
* logout().logoutSuccessUrl("/")
- 로그아웃 성공시 "/" 주소로 이동함
* oauth2Login
- OAuth 2.0 로그인 기능에 대한 여러 설정의 진입점
* userInfoEndpoint
- OAuth 2.0 로그인 성공 이후 사용자 정보를 가져올 때의 설정들을 담당함
* userService
- 소셜 로그인 성공 시 후속 조치를 진행할 UserService 인터페이스의 구현체 등록
- 소셜 서비스에서 사용자 정보를 가져온 상태에서 추가로 진행하고자 하는 기능 명시 가능
추가
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/")
* loginPage -> 로그인 페이지 설정
* defaultSuccessURL -> 로그인 성공 후 리다이렉트 주소
'Programming > Spring Boot' 카테고리의 다른 글
[Spring Boot] ResponseEntity와 TestRestTemplate (0) | 2021.02.17 |
---|---|
[Spring Boot] 인텔리제이 Live Reload 설정 (0) | 2021.02.07 |
[Lombok] @RequiredArgsConstructor (0) | 2021.02.01 |
[Spring Boot] OAuth 2.0 기본 세팅 (2) | 2021.01.29 |
REST API (0) | 2021.01.26 |