Commit a444e7de by Patryk Czarnik

SecurityConfig dla usługi restowej

parent 36e8ef77
...@@ -2,6 +2,7 @@ package sklep.security; ...@@ -2,6 +2,7 @@ package sklep.security;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer; import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
...@@ -17,7 +18,10 @@ public class SecurityConfig { ...@@ -17,7 +18,10 @@ public class SecurityConfig {
SecurityFilterChain setHttpSecurity(HttpSecurity httpSecurity) throws Exception { SecurityFilterChain setHttpSecurity(HttpSecurity httpSecurity) throws Exception {
httpSecurity httpSecurity
.authorizeHttpRequests((authz) -> authz .authorizeHttpRequests((authz) -> authz
.anyRequest().permitAll() .requestMatchers(HttpMethod.GET).permitAll()
.requestMatchers(HttpMethod.POST).hasRole("manager")
.requestMatchers(HttpMethod.PUT).hasRole("manager")
.requestMatchers(HttpMethod.DELETE).hasRole("manager")
) )
.httpBasic(Customizer.withDefaults()) .httpBasic(Customizer.withDefaults())
.csrf(config -> config.disable()); .csrf(config -> config.disable());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment