728x90
반응형
##스프링 시큐리티
: 로그인 회원가입 등 여러 기능 제공
##스프링 시큐리티' 프레임워크 추가
build.gradle -> dependencies 에 추가
1
2
3
4
|
// 스프링 시큐리티
implementation 'org.springframework.boot:spring-boot-starter-security'
// Thymeleaf (뷰 템플릿 엔진)
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
cs |
##'스프링 시큐리티' 활성화
src > main > com.sparta.springcore.security > WebSecurityConfig
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
|
package com.sparta_spring.sparta_springcore_week01.security;
import org.springframework.context.annotation.Configuration;
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;
@Configuration
@EnableWebSecurity // 스프링 Security 지원을 가능하게 함
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.headers().frameOptions().disable();
http.authorizeRequests()
.anyRequest().authenticated() // 어떤 요청도 모두 인증
.and()
.formLogin() // 로그인 페이지는
.defaultSuccessUrl("/")
.permitAll() // 모두 허용
.and() // 그리고
.logout()//로그아웃도
.permitAll(); //모두허용
}
}
|
cs |
##스프링 시큐리티의 default 로그인 기능
- Username: user
- Password: spring 로그 확인 (서버 시작 시마다 변경됨)
반응형
'SpringBoot > 스파르타 스프링 심화' 카테고리의 다른 글
[스파르타 스프링 심화] 02.08 패스워드 암호화 구현 (0) | 2021.08.16 |
---|---|
[스파르타 스프링 심화] 02.06 회원 가입 UI 반영 (0) | 2021.08.14 |
[스파르타 스프링 심화] 02.04. 회원 관리 기능 요구사항 및 설계 (0) | 2021.08.13 |
[스파르타 스프링 심화] 02.03. 쿠키와 세션 (0) | 2021.08.13 |
[스파르타 스프링 심화] 02.02 웹의 인증(Authentication ) 및 인가(Authorization) (0) | 2021.08.13 |