Initial commit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.mednikov.social.connections.exceptions;
|
||||
|
||||
public class ObjectAlreadyExistsException extends RuntimeException {
|
||||
|
||||
public ObjectAlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.mednikov.social.connections.exceptions;
|
||||
|
||||
public class ObjectDoesNotExistException extends RuntimeException {
|
||||
|
||||
public ObjectDoesNotExistException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
21
src/main/resources/application-dev.yml
Normal file
21
src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5433/social_connections_db
|
||||
username: social_connections_user
|
||||
password: secret1234
|
||||
rabbitmq:
|
||||
port: 5672
|
||||
host: localhost
|
||||
username: guest
|
||||
password: guest
|
||||
flyway:
|
||||
user: social_connections_user
|
||||
password: secret1234
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: http://localhost:8080/realms/social
|
||||
server:
|
||||
port: 8001
|
||||
|
||||
21
src/main/resources/application-prod.yml
Normal file
21
src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: ${APP_DATABASE_URL}
|
||||
username: ${APP_DATABASE_USER}
|
||||
password: ${APP_DATABASE_PASSWORD}
|
||||
rabbitmq:
|
||||
port: ${APP_RABBITMQ_PORT}
|
||||
host: ${APP_RABBITMQ_HOST}
|
||||
username: ${APP_RABBITMQ_USER}
|
||||
password: ${APP_RABBITMQ_PASSWORD}
|
||||
flyway:
|
||||
user: ${APP_DATABASE_USER}
|
||||
password: ${APP_DATABASE_PASSWORD}
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: ${APP_KEYCLOAK_URL}
|
||||
server:
|
||||
port: ${APP_PORT}
|
||||
|
||||
8
src/main/resources/application.yml
Normal file
8
src/main/resources/application.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
spring:
|
||||
application:
|
||||
name: social-connections
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
profiles:
|
||||
active: dev
|
||||
Reference in New Issue
Block a user