Java/Spring Boot Security
Sprng boot Security 적용
바리새인
2024. 5. 26. 20:37
pom.xml
# dependabct 추가
# thymeleaf 추가
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
# spring security 추가
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
# spring boot 3.2.5에 포함되어 있음
<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>
환경설정 추가
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
}
}
또는
@Controller
public class Controller {
@GetMapping("/")
public String home() {
return "home";
}
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
기본 인증정보
App을 기동하면 'user' 계정의 비밀번호가 로그에 출력됨(재기동할때마다 달라짐)
Using generated security password: 93d706d1-753d-4473-b998-38e8192d5d8c
This generated password is for development use only. Your security configuration must be updated before running your application in production.
기본 인증정보 설정
application.yml에 인증정보 추가
spring:
security:
user:
name: {ID}
password: {비밀번호}