-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Something not work correctly before, but I added something and now it seems good * config but not ok * add docker and config to run * config pipeline
- Loading branch information
Showing
13 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM eclipse-temurin:21-jre-alpine | ||
COPY target/sun-rise*.jar app.jar | ||
ENTRYPOINT ["java", "-jar", "/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
services: | ||
sunrise: | ||
build: . | ||
environment: | ||
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/mock_project | ||
- SERVER_SERVLET_CONTEXT_PATH=/sun | ||
- SUN_SERVICES_MEDIA | ||
# - SERVER_PORT | ||
ports: | ||
- "8086:8086" | ||
volumes: | ||
- ./deployment/app-config:/app-config | ||
networks: | ||
- sun-network | ||
|
||
postgres: | ||
image: debezium/postgres:15-alpine | ||
build: src/docker/postgres | ||
hostname: ${POSTGRES_HOST} | ||
ports: | ||
- "${POSTGRES_PORT}:${POSTGRES_PORT}" | ||
volumes: | ||
- ./docker/postgres/postgresql.conf.sample:/usr/share/postgresql/postgresql.conf.sample | ||
- ./postgres_init.sql:/docker-entrypoint-initdb.d/postgres_init.sql | ||
- postgres:/var/lib/postgresql/data | ||
command: postgres -c 'max_connections=500' | ||
environment: | ||
- POSTGRES_USER | ||
- POSTGRES_PASSWORD | ||
networks: | ||
- sun-network | ||
|
||
pgadmin: | ||
image: dpage/pgadmin4:6.20 | ||
volumes: | ||
- pgadmin:/var/lib/pgadmin | ||
environment: | ||
PGADMIN_DEFAULT_EMAIL: admin@sun.com | ||
PGADMIN_DEFAULT_PASSWORD: admin | ||
ports: | ||
- "8081:80" | ||
networks: | ||
- sun-network | ||
|
||
networks: | ||
sun-network: | ||
driver: bridge | ||
name: sun-network | ||
|
||
volumes: | ||
postgres: | ||
pgadmin: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE DATABASE mock_project WITH OWNER = admin ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION | ||
LIMIT = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM debezium/postgres:15-alpine | ||
ENV WAL2JSON_TAG=wal2json_2_5 | ||
RUN apk add --no-cache --virtual .debezium-build-deps gcc clang15 llvm15 git make musl-dev pkgconf \ | ||
&& git clone https://github.com/eulerto/wal2json -b master --single-branch \ | ||
&& (cd /wal2json && git checkout tags/$WAL2JSON_TAG -b $WAL2JSON_TAG && make && make install) \ | ||
&& rm -rf wal2json \ | ||
&& apk del .debezium-build-deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# LOGGING | ||
# log_min_error_statement = fatal | ||
# log_min_messages = DEBUG1 | ||
|
||
# CONNECTION | ||
listen_addresses = '*' | ||
|
||
# MODULES | ||
shared_preload_libraries = 'decoderbufs,wal2json' | ||
|
||
# REPLICATION | ||
wal_level = logical # minimal, archive, hot_standby, or logical (change requires restart) | ||
max_wal_senders = 20 # max number of walsender processes (change requires restart) | ||
#wal_keep_segments = 4 # in logfile segments, 16MB each; 0 disables | ||
#wal_sender_timeout = 60s # in milliseconds; 0 disables | ||
max_replication_slots = 20 # max number of replication slots (change requires restart) |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/fjb/sunrise/config/AuditorAwareStringImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.fjb.sunrise.config; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AuditorAwareStringImpl implements AuditorAware<String> { | ||
@Override | ||
public Optional<String> getCurrentAuditor() { | ||
|
||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
if (authentication == null || !authentication.isAuthenticated()) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(authentication.getName()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/fjb/sunrise/config/security/CustomUserDetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.fjb.sunrise.config.security; | ||
|
||
import com.fjb.sunrise.models.User; | ||
import com.fjb.sunrise.repositories.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomUserDetailService implements UserDetailsService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
User user = userRepository.findByUsername(username); | ||
if (user == null) { | ||
throw new UsernameNotFoundException(username); | ||
} | ||
return org.springframework.security.core.userdetails.User.withUsername(user.getUsername()) | ||
.password(user.getPassword()) | ||
.build(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/com/fjb/sunrise/config/security/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.fjb.sunrise.config.security; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
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.annotation.web.configurers.HeadersConfigurer; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
|
||
private final CustomUserDetailService userDetailsService; | ||
|
||
static final String[] PUBLIC_ENDPOINTS = {"/img/**", "/css/**", "/js/**"}; | ||
|
||
static final String[] ALLOWED_METHODS = {"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}; | ||
|
||
static final String[] ALLOWED_ORIGINS = {"*"}; | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
http | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.cors(cors -> cors.configurationSource(request -> { | ||
var corsConfiguration = new CorsConfiguration(); | ||
corsConfiguration.setAllowedOrigins(List.of(ALLOWED_ORIGINS)); | ||
corsConfiguration.setAllowedMethods(List.of(ALLOWED_METHODS)); | ||
corsConfiguration.setAllowedHeaders(List.of("Authorization", "Content-Type")); | ||
return corsConfiguration; | ||
})) | ||
.authorizeHttpRequests(requests -> requests | ||
.requestMatchers(PUBLIC_ENDPOINTS).permitAll() | ||
.anyRequest().authenticated() | ||
) | ||
.formLogin(form -> form | ||
// .loginPage("/sun/login") | ||
.defaultSuccessUrl("/health", true) | ||
.permitAll() | ||
) | ||
.logout(logout -> logout | ||
.logoutUrl("/logout") | ||
// .logoutSuccessUrl("/login") | ||
.permitAll()) | ||
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin)); | ||
|
||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public SpringSecurityDialect springSecurityDialect() { | ||
return new SpringSecurityDialect(); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters