2023-11-27 21:08:28 -08:00
|
|
|
package com.wisemapping.config.rest;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
|
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.configurers.AbstractHttpConfigurer;
|
|
|
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
|
|
|
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
|
|
|
|
2024-01-15 07:59:04 -08:00
|
|
|
import static org.springframework.security.config.Customizer.withDefaults;
|
|
|
|
|
2023-11-27 21:08:28 -08:00
|
|
|
|
|
|
|
@SpringBootApplication
|
|
|
|
@EnableWebSecurity
|
2024-01-15 07:59:04 -08:00
|
|
|
@ComponentScan({"com.wisemapping.rest"})
|
2023-11-27 21:08:28 -08:00
|
|
|
public class RestAppConfig {
|
|
|
|
@Bean
|
2024-01-15 16:36:29 -08:00
|
|
|
MvcRequestMatcher.Builder mvc(HandlerMappingIntrospector introspector) {
|
|
|
|
return new MvcRequestMatcher.Builder(introspector);
|
|
|
|
}
|
|
|
|
@Bean
|
|
|
|
SecurityFilterChain apiSecurityFilterChain(@NotNull final HttpSecurity http, @NotNull final MvcRequestMatcher.Builder mvc) throws Exception {
|
|
|
|
return http
|
|
|
|
.authorizeHttpRequests(auth -> auth
|
|
|
|
.requestMatchers(mvc.pattern("/api/restfull/users/")).permitAll()
|
|
|
|
.requestMatchers(mvc.pattern("/api/restfull/users/resetPassword")).permitAll()
|
|
|
|
.requestMatchers(mvc.pattern("/api/restfull/oauth2/googlecallback")).permitAll()
|
|
|
|
.requestMatchers(mvc.pattern("/api/restfull/oauth2/confirmaccountsync")).permitAll()
|
|
|
|
.requestMatchers(mvc.pattern("/api/restfull/admin/**")).hasAnyRole("ADMIN")
|
|
|
|
.requestMatchers(mvc.pattern("/**")).hasAnyRole("USER", "ADMIN")
|
|
|
|
.anyRequest().authenticated()
|
|
|
|
)
|
|
|
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
|
.httpBasic(withDefaults())
|
|
|
|
.csrf(AbstractHttpConfigurer::disable)
|
|
|
|
.build();
|
2023-11-27 21:08:28 -08:00
|
|
|
}
|
|
|
|
}
|