Jun 28, 2024
pom.xmluser) and password (logged in console)
application.propertiesspring.security.user.name=user, spring.security.user.password=user@Configuration and @EnableWebSecuritySecurityFilterChain bean
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
// security configurations
return http.build();
}
http.authorizeRequests().antMatchers("/public/**").permitAll().antMatchers("/admin/**").hasRole("ADMIN");User entityCommandLineRunner to preload user datapasswordEncoder.encode(password)UserDetailsUser.withUsername(dbUser.getUsername()).password(dbUser.getPassword()).roles(dbUser.getRoles()).build();@EnableMethodSecurity annotation in configuration class@PreAuthorize on methods to specify role-based access@PreAuthorize("hasRole('ADMIN')")