1 | package mk.ukim.finki.busngobackend.config
|
---|
2 |
|
---|
3 | import org.springframework.context.annotation.Bean
|
---|
4 | import org.springframework.context.annotation.Configuration
|
---|
5 | import org.springframework.http.HttpMethod
|
---|
6 | import org.springframework.security.authentication.AuthenticationProvider
|
---|
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
---|
8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
|
---|
9 | import org.springframework.security.config.http.SessionCreationPolicy
|
---|
10 | import org.springframework.security.web.DefaultSecurityFilterChain
|
---|
11 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
|
---|
12 |
|
---|
13 | @Configuration
|
---|
14 | @EnableWebSecurity
|
---|
15 | class 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 | }
|
---|