Commit 205094b0 by Patryk Czarnik

reguły dostępu za pomocą antMatchers

parent 5298fa20
...@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import sklep.model.Product; import sklep.model.Product;
import sklep.repository.ProductRepository;
@Controller @Controller
@RequestMapping("/alt8") @RequestMapping("/alt8")
......
...@@ -3,6 +3,7 @@ package sklep.security; ...@@ -3,6 +3,7 @@ package sklep.security;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
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.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.ObjectPostProcessor; import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
...@@ -15,9 +16,17 @@ public class SecurityConfig { ...@@ -15,9 +16,17 @@ public class SecurityConfig {
@Bean @Bean
SecurityFilterChain setHttpSecurity(HttpSecurity httpSecurity) throws Exception { SecurityFilterChain setHttpSecurity(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeHttpRequests() httpSecurity.authorizeHttpRequests()
.anyRequest().authenticated() // .antMatchers(HttpMethod.POST).authenticated()
.and() .antMatchers("/", "/whoami", "/*.css").permitAll()
.httpBasic() .antMatchers("/hello", "/time").permitAll()
.antMatchers("/alt?/**").authenticated() // zalogowany jako ktokolwiek
.antMatchers("/products/new", "/products/*/edit").hasAuthority("ROLE_manager")
.antMatchers("/products/**").permitAll()
.antMatchers("/customers/new", "/customers/*/edit").hasAuthority("ROLE_manager")
.antMatchers("/customers/**").authenticated()
.anyRequest().denyAll()
.and()
.formLogin()
; ;
return httpSecurity.build(); return httpSecurity.build();
} }
......
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