source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/config/SecurityConfig.kt

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 2.4 KB
Line 
1package mk.ukim.finki.busngobackend.config
2
3import org.springframework.context.annotation.Bean
4import org.springframework.context.annotation.Configuration
5import org.springframework.http.HttpMethod
6import org.springframework.security.authentication.AuthenticationProvider
7import org.springframework.security.config.annotation.web.builders.HttpSecurity
8import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
9import org.springframework.security.config.http.SessionCreationPolicy
10import org.springframework.security.web.DefaultSecurityFilterChain
11import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
12
13@Configuration
14@EnableWebSecurity
15class SecurityConfig(
16 private val jwtAuthFilter: JwtAuthFilter,
17 private val authenticationProvider: AuthenticationProvider,
18) {
19 @Bean
20 fun securityFilterChain(
21 http: HttpSecurity,
22 jwtAuthFilter: JwtAuthFilter,
23 ): DefaultSecurityFilterChain =
24 http
25 .csrf {
26 it.disable()
27 }.authorizeHttpRequests {
28 it
29 .requestMatchers("/api/booking/populate")
30 .permitAll()
31 .requestMatchers("/api/booking/**")
32 .authenticated()
33 .requestMatchers(HttpMethod.GET, "/api/city/**")
34 .permitAll()
35 .requestMatchers("/api/city/**")
36 .authenticated()
37 .requestMatchers(HttpMethod.POST, "/api/properties/**")
38 .authenticated()
39 .requestMatchers(HttpMethod.GET, "/api/properties/{id}/for-review")
40 .authenticated()
41 .requestMatchers(HttpMethod.POST, "/api/property-image/{id}/save-file")
42 .permitAll()
43 .requestMatchers(HttpMethod.POST, "/api/property-image/**")
44 .authenticated()
45 .requestMatchers(HttpMethod.POST, "/api/reviews/**")
46 .authenticated()
47 .anyRequest()
48 .permitAll()
49 }.sessionManagement {
50 it.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
51 }.authenticationProvider(authenticationProvider)
52 .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter::class.java)
53 .build()
54}
Note: See TracBrowser for help on using the repository browser.