Initial commit

This commit is contained in:
2026-01-10 14:13:29 +01:00
commit 17ef2e4c94
17 changed files with 827 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package dev.mednikov.social.connections;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@SpringBootApplication
public class SocialConnectionsApplication {
public static void main(String[] args) {
SpringApplication.run(SocialConnectionsApplication.class, args);
}
}

View File

@@ -0,0 +1,25 @@
package dev.mednikov.social.connections.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.List;
@Configuration
public class CorsConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedOrigin("*");
configuration.setAllowedMethods(List.of("POST", "PUT", "GET", "OPTIONS", "DELETE"));
configuration.setAllowedHeaders(List.of("Authorization", "Content-Type", "Access-Control-Allow-Origin"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}

View File

@@ -0,0 +1,15 @@
package dev.mednikov.social.connections.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ObjectMapperConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper;
}
}

View File

@@ -0,0 +1,25 @@
package dev.mednikov.social.connections.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests(auth -> auth
.requestMatchers("/error/**").permitAll()
.anyRequest().authenticated())
.cors(Customizer.withDefaults())
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(Customizer.withDefaults()))
.build();
}
}

View File

@@ -0,0 +1,9 @@
package dev.mednikov.social.connections.exceptions;
public class ObjectAlreadyExistsException extends RuntimeException {
public ObjectAlreadyExistsException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,9 @@
package dev.mednikov.social.connections.exceptions;
public class ObjectDoesNotExistException extends RuntimeException {
public ObjectDoesNotExistException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,23 @@
package dev.mednikov.social.connections.web;
import dev.mednikov.social.connections.exceptions.ObjectAlreadyExistsException;
import dev.mednikov.social.connections.exceptions.ObjectDoesNotExistException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class ApplicationExceptionHandler {
@ExceptionHandler(ObjectAlreadyExistsException.class)
public ResponseEntity<String> handleObjectAlreadyExistsException(ObjectAlreadyExistsException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage());
}
@ExceptionHandler(ObjectDoesNotExistException.class)
public ResponseEntity<String> handleObjectDoesNotExistException(ObjectDoesNotExistException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage());
}
}