thymeleaf 예제 추가
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.example.springsecuritystudy;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
@@ -16,4 +17,11 @@ public class HomeController {
|
||||
return "admin";
|
||||
}
|
||||
|
||||
@GetMapping("/example")
|
||||
public String example(Model model) {
|
||||
model.addAttribute("name", "정우성");
|
||||
model.addAttribute("age", 51);
|
||||
return "example";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.example.springsecuritystudy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -12,16 +11,19 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@EnableWebSecurity
|
||||
@RequiredArgsConstructor
|
||||
public class SecurityConfig {
|
||||
|
||||
@Autowired
|
||||
PasswordEncoder passwordEncoder;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeHttpRequests(authorize -> authorize
|
||||
.antMatchers("/", "/example").permitAll()
|
||||
.antMatchers("/user").hasRole("USER")
|
||||
.antMatchers("/admin").hasRole("ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
|
||||
Reference in New Issue
Block a user