Created
June 29, 2024 08:28
-
-
Save jaimemin/dbf2d426b1fec4a7551528fe9cb4e687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableWebSecurity | |
public class SecurityConfig { | |
@Bean | |
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests(authorizeRequests -> | |
authorizeRequests | |
.antMatchers("/api/**").permitAll() | |
.anyRequest().authenticated() | |
) | |
.formLogin(formLogin -> | |
formLogin | |
.loginPage("/login") | |
.permitAll() | |
) | |
.logout(logout -> | |
logout | |
.permitAll() | |
); | |
return http.build(); | |
} | |
@Bean | |
public UserDetailsService userDetailsService() { | |
var user = User.withUsername("user") | |
.password("{noop}password") // {noop}은 비밀번호를 인코딩하지 않음을 나타냄 | |
.roles("USER") | |
.build(); | |
var admin = User.withUsername("admin") | |
.password("{noop}admin") | |
.roles("ADMIN") | |
.build(); | |
return new InMemoryUserDetailsManager(user, admin); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment