https://spring.io/guides/gs/securing-web
Getting Started | Securing a Web Application
Suppose that you want to prevent unauthorized users from viewing the greeting page at /hello. As it is now, if visitors click the link on the home page, they see the greeting with no barriers to stop them. You need to add a barrier that forces the visitor
spring.io
기본은 역시 공식 홈페이지일것 같습니다.
이번에 새로 공부하게 되면서 2024년도 5월 내용을 정리해보게 되었습니다.
해당페이지 내용은 java 17 이상 Gradle 7.5 또는 Maven 3.5 이상이 필요하다고 하네요.
추정되는 내용은 spring boot 3.x 기준으로 보입니다.
※ 레퍼런스 문서 확인하니 버전정보를 확인할 수 있었습니다.
제가 참고한 버전은 다음과 같습니다.
Spring Security 6.2.4 , spring version 6.1.6, Spring boot 3.2.5
스프링 부트 프로젝트 3.2는 스프링 프레임웍 6.1로 되어 있으며, 스프링 시큐리티 6.2는 스프링 부트 3.1 이후 버전을 지원한다고 합니다.
믿을 수 없지만 15분 정도면 사용이 가능하다는 것 같네요. 10시7분 정리 시작해 봅니다.
1. 스프링 초기설정 프로젝트를 생성하거나 git clone방식으로 준비
git clone https://github.com/spring-guides/gs-securing-web.git
## 해당 깃 내용 중 발췌
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2. 랜딩페이지 작성및 환영페이지 작성
3. 라우팅 관련 초기 설정
------------------
4. Spring Security 설정
implementation 'org.springframework.boot:spring-boot-starter-security'
// Temporary explicit version to fix Thymeleaf bug
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE'
testImplementation 'org.springframework.security:spring-security-test'
------------------------------------------------------------------------------
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-security'
// Temporary explicit version to fix Thymeleaf bug
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>securing-web-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>securing-web-complete</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
<!-- Temporary explicit version to fix Thymeleaf bug -->
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
여기서 thymeleaf, web,security, thymeleaf extras springsecurity6 이정도 구성이라고 보면 될것 같네요.
5. 시큐리티 설정(WebSecurityConfig.java)
5.1 여기서 봐야 할것은 로그인을 안하고 접근 가능한 페이지 리스트 설정
5.2 로그인 페이지
5.3 로그 아웃 페이지
흠음... 가볍게 정리한다고 정리하면서 따라 해봤는데 10시 48분.... 약 40분 정도 걸렸네요.
내용을 어느정도 정리하면서 이것 저것 보다 보니 시간이 늘어지기는 해도 해당 내용만 적용하는데는 공식 홈페이지에 나온 시간 안에 할 수 있을 것 같네요.
문제는 관련 내용을 알아보면서 하는 것이 맞을까 아니면 빠르게 가이드를 숙지하는 것이 먼저일지는 글을 읽는 사람의 선택일것 같습니다.
'프로그램 > Web' 카테고리의 다른 글
| 온라인강좌 사이트 만들기 1단계 분석(2024.07.09~10) (0) | 2024.07.10 |
|---|---|
| Spring Security 6.2.4- Servlet -Architecture(2024.05) (0) | 2024.05.12 |
| window에서 https 서비스 테스트(2023.08.09) (0) | 2023.08.09 |
| vscode 에서 mvn 명령사용을 위한 설정(2023.08.09) (0) | 2023.08.09 |
| 우분투 날짜 파일명 만들기(2023.07.19 마리아DB 백업) (0) | 2023.07.19 |