땃쥐네

[Spring Security] 스프링부트 시큐리티 의존성 추가로 일어나는 일들 본문

Spring/Spring Security

[Spring Security] 스프링부트 시큐리티 의존성 추가로 일어나는 일들

ttasjwi 2024. 3. 9. 13:36
dependencies {
    // spring security
    implementation("org.springframework.boot:spring-boot-starter-security")
    testImplementation("org.springframework.security:spring-security-test")
}

 

gradle의 경우 buiild.gradle 또는 build.gradle.kts

maven의 경우 pom.xml 파일에

 

스프링부트 시큐리티 의존성을 추가 해보면 여러가지 일들이 일어난다.

 

 

이를 가장 정확히 설명하는 문서는 스프링 시큐리티의 공식 문서의 getting-started - Runtime Expectations 단락에 있다.

여기선 간단하게 당장 개발하면서 체감할 수 있는 내용만 작성할 예정.

Using generated security password: 201aeffe-e657-4543-b787-0a35ea5f1800
This generated password is for development use only. Your security configuration must be updated before running your application in production.
  • 서버가 기동되면 스프링 시큐리티의 초기화 작업 및 보안 설정이 이루어진다.
  • 별도의 보안 설정, 구현을 하지 않아도 스프링 부트는 기본 필터를 적용하고, 모든 엔드포인트에 보안 기능이 적용된다.
    • 모든 요청은 인증이 되어야 자원에 접근이 가능하다.
    • 인증 방식으로는 Form 로그인 방식, HttpBasic 로그인 방식이 지원된다.
    • 기본 로그인 페이지가 제공된다.
    • 기본 계정이 하나 제공된다. (username: user / password : 콘솔에 출력되는 랜덤 문자열)
  • 웹 브라우저를 통해 루트 페이지로 접근하면, /login 으로 리다이렉트 된다. (기본 로그인 페이지)
$ curl -i localhost:8080

HTTP/1.1 401
Set-Cookie: JSESSIONID=0EF030C3ABB26D86ED4981C0E14F8E77; Path=/; HttpOnly
WWW-Authenticate: Basic realm="Realm"
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
WWW-Authenticate: Basic realm="Realm"
Content-Length: 0
Date: Sun, 09 Jul 2023 09:22:24 GMT
  • curl 명령어를 통해 API 요청을 하면, 401 UnAuthorized 응답이 온다.
  • 해당 엔드포인트로 들어오는 요청을 다루는 핸들러를 개발하지 않았음에도 말이다

참고자료

- 스프링 시큐리티 공식문서

Comments