[스프링부트] Spring Security 이용

Urther·2021년 9월 26일
0
 <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-security</artifactId>
 </dependency>

yml 파일에 security 를 추가해준다.

localhost:8080 접속시

ID 는 user, PW는 위에 괄호 친거 복사해서 붙여넣으면 된다.

  1. 어노테이션 추가
    @EnableWebSecurity
    @Configuration
  2. 상속

    extends WebSecurityConfigurerAdapter

@Override
protected void configure(HttpSecurity http) throws Exception {
 
 super.configure(http);
 
    }

intellij에서 ctrl + o 누르면 override할 수 있는 메소드 볼 수 있다

      http.authorizeRequests()
                .antMatchers("/","/**")
                        .permitAll();

root 만 permit 하게 해주었는데 permit 되지 않은 부분은 로그인 없이 들어갈 수 없다.

profile
이전해요 ☘️ https://mei-zy.tistory.com

0개의 댓글