Modify 주석 추가
This commit is contained in:
14
build.gradle
14
build.gradle
@@ -19,17 +19,27 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// spring data jpa
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
// security
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
// 웹 페이지를 쉽게 생성하기 위한 thymeleaf
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||||
|
// spring web mvc
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
// Thymeleaf에서 SpringSecurity를 Integration
|
||||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
|
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
|
||||||
|
// lombok
|
||||||
compileOnly 'org.projectlombok:lombok'
|
compileOnly 'org.projectlombok:lombok'
|
||||||
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
|
||||||
runtimeOnly 'com.h2database:h2'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
// h2
|
||||||
|
runtimeOnly 'com.h2database:h2'
|
||||||
|
// starter test
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
// security test
|
||||||
testImplementation 'org.springframework.security:spring-security-test'
|
testImplementation 'org.springframework.security:spring-security-test'
|
||||||
|
// junit test
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.example.springsecuritystudy;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpringSecurity 학습용 Application
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class SpringSecurityStudyApplication {
|
public class SpringSecurityStudyApplication {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.example.springsecuritystudy.common;
|
package com.example.springsecuritystudy.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 이미 등록된 유저를 재등록하려고 할때 발생하는 Exception
|
||||||
|
*/
|
||||||
public class AlreadyRegisteredUserException extends RuntimeException {
|
public class AlreadyRegisteredUserException extends RuntimeException {
|
||||||
|
|
||||||
public AlreadyRegisteredUserException(String message) {
|
public AlreadyRegisteredUserException(String message) {
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.example.springsecuritystudy.common;
|
package com.example.springsecuritystudy.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 유저를 찾을 수 없을 때 발생하는 Exception
|
||||||
|
*/
|
||||||
public class UserNotFoundException extends RuntimeException {
|
public class UserNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
public UserNotFoundException(String message) {
|
public UserNotFoundException(String message) {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import com.example.springsecuritystudy.user.UserService;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 초기 상태 등록 Config
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Profile(value = "!test")
|
@Profile(value = "!test")
|
||||||
@@ -21,6 +24,12 @@ public class InitializeConfig {
|
|||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
private final NoticeService noticeService;
|
private final NoticeService noticeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>유저 등록</h2>
|
||||||
|
* 1. user / user<br/> 2. admin / admin
|
||||||
|
* <h2>게시글 등록 4개</h2>
|
||||||
|
* <h2>공지사항 등록 2개</h2>
|
||||||
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void adminAccount() {
|
public void adminAccount() {
|
||||||
User user = userService.signup("user", "user");
|
User user = userService.signup("user", "user");
|
||||||
@@ -30,5 +39,6 @@ public class InitializeConfig {
|
|||||||
postService.savePost(user, "테스트3", "테스트3입니다.");
|
postService.savePost(user, "테스트3", "테스트3입니다.");
|
||||||
postService.savePost(user, "여름 여행계획", "여름 여행계획 작성중...");
|
postService.savePost(user, "여름 여행계획", "여름 여행계획 작성중...");
|
||||||
noticeService.saveNotice("환영합니다", "환영합니다 여러분");
|
noticeService.saveNotice("환영합니다", "환영합니다 여러분");
|
||||||
|
noticeService.saveNotice("게시글 작성 방법 공지", "1. 회원가입\n2. 로그인\n3. 게시글 작성\n4. 저장\n* 본인 외에는 게시글을 볼 수 없습니다.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package com.example.springsecuritystudy.config;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JPA auditor enable
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJpaAuditing
|
@EnableJpaAuditing
|
||||||
public class AuditorConfig {
|
public class JpaAuditorConfig {
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,9 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebMVC Config
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class MvcConfig {
|
public class MvcConfig {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PasswordEncoder Config
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class PasswordEncoderConfig {
|
public class PasswordEncoderConfig {
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Security 설정 Config
|
||||||
|
*/
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ import com.example.springsecuritystudy.post.PostDto;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 공지사항 서비스 Controller
|
||||||
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping("/notice")
|
@RequestMapping("/notice")
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ public class AdminController {
|
|||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 어드민인 경우 게시글 조회
|
||||||
|
* @return admin/index.html
|
||||||
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String getPostForAdmin(Authentication authentication, Model model) {
|
public String getPostForAdmin(Authentication authentication, Model model) {
|
||||||
User user = (User) authentication.getPrincipal();
|
User user = (User) authentication.getPrincipal();
|
||||||
|
|||||||
Reference in New Issue
Block a user