feat(java-cache): SecurityConfig() part 1/3
This commit is contained in:
1 parent
f564c3db22
commit
3e816dbd67
1 file changed
+40
+40
@@ -0,0 +1,40 @@
|
||||
package com.hoelee.platform.cache;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
/**
|
||||
* @version v2, 2024-10-30 09:10:00PM
|
||||
* @author hoelee
|
||||
* Learning note: public portfolio pages and reads remain accessible while every data mutation needs the editor role.
|
||||
*/
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
return http
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(authorize -> authorize
|
||||
.requestMatchers("/", "/index.html", "/css/**", "/js/**", "/actuator/health").permitAll()
|
||||
.requestMatchers(HttpMethod.GET, "/api/**").permitAll()
|
||||
.requestMatchers("/api/**").hasRole("EDITOR")
|
||||
.anyRequest().denyAll())
|
||||
.httpBasic(Customizer.withDefaults())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user