Skip to content

Commit

Permalink
GMS-79 System status cache removed + samples created + repositories m…
Browse files Browse the repository at this point in the history
…arked with Repository annotation
  • Loading branch information
peter-szrnka committed Dec 5, 2023
1 parent cad40d8 commit 49ab1c9
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 53 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ To start a new container, you have to set up a bunch of environment properties.

For further information & sample configurations, please check the sub folders under the "db" folder.

## Caching

2 types of cache provided:

- Built-in cache
- Redis

## Authentication

- [Database](batch-files/db-authentication)
Expand Down Expand Up @@ -65,7 +72,7 @@ Currently only AES encryption is supported. In the future this will be configur

# Code samples

You can find client code examples for Java, Python and Node.js [here](client-samples/README.md).
You can find client code examples for Java, Go, Python and Node.js [here](client-samples/README.md).


# Donate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker compose --env-file env-postgresql-with-redis.txt -p give-my-secret up -d
46 changes: 46 additions & 0 deletions batch-files/redis-cache/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: "3.9"
services:
gms-app:
#build: .
container_name: gms-app-${SELECTED_DB}-${SELECTED_AUTH}
image: ghcr.io/peter-szrnka/give-my-secret:latest
ports:
- "8080:8080"
- "8443:8443"
environment:
- SPRING_PROFILE
- DB_JDBC_URL
- DB_USERNAME
- DB_CREDENTIAL
- DB_SHOW_SQL
- DB_MAX_LIFETIME
- SSL_KEYSTORE
- SSL_KEYSTORE_PATH
- SSL_KEYSTORE_ALIAS
- SSL_KEYSTORE_PASSWORD
- KEYSTORE_PATH
- KEYSTORE_TEMP_DEFAULT_PATH
- LDAP_BASE_DN
- LDAP_CREDENTIAL
- LDAP_URL
- LDAP_USERNAME
- LDAP_PASSWORD_ENCODER
- SELECTED_DB
- SELECTED_AUTH
- HTTPS_PORT
- CONFIG_SECRET_JWT
- CONFIG_SECRET_CRYPTO
- CONFIG_ENCRYPTION_IV
- EVENT_OLD_LIMIT
- MESSAGE_OLD_LIMIT
- ENABLE_SECRET_ROTATION
- ENABLE_EVENT_MAINTENANCE
- ENABLE_MESSAGE_CLEANUP
- ENABLE_REDIS_CACHE
- REDIS_HOST
- REDIS_PORT

volumes:
- "D:/dev/projects/open-source/keystores/:/usr/share/ssl/"
- "D:/dev/projects/open-source/ks/:/usr/share/keystore/"
- "D:/dev/projects/open-source/temp-ks/:/usr/share/keystore-temp/"
43 changes: 43 additions & 0 deletions batch-files/redis-cache/env-postgresql-with-redis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
SELECTED_DB=postgresql
SELECTED_AUTH=db
SPRING_PROFILE=${SELECTED_DB},${SELECTED_AUTH},https

# HTTPS configuration
SSL_KEYSTORE_TYPE=PKCS12
SSL_KEYSTORE_PATH=/usr/share/ssl/
SSL_KEYSTORE=${SSL_KEYSTORE_PATH}test.p12
SSL_KEYSTORE_PASSWORD=Test1234
SSL_KEYSTORE_ALIAS=test
HTTPS_PORT=8443

# Secrets
CONFIG_SECRET_JWT=MTIzNDU2NzgxMjM0NTY3ODEyMzQ1Njc4MTIzNDU2Nzg=
CONFIG_SECRET_CRYPTO=MTIzNDU2NzgxMjM0NTY3ODEyMzQ1Njc4MTIzNDU2Nzg=
CONFIG_ENCRYPTION_IV=R4nd0mIv1234567!

# LDAP
LDAP_BASE_DN=dc=givemysecret,dc=szrnkapeter,dc=hu
LDAP_URL=ldap://host.docker.internal:11389
LDAP_USERNAME=uid=admin,ou=system
LDAP_CREDENTIAL=secret
LDAP_PASSWORD_ENCODER=CRYPT

# Common db configuration
DB_SHOW_SQL=false

# MS SQL configuration
DB_JDBC_URL=jdbc:postgresql://host.docker.internal:5432/gms?currentSchema=gms&schema=gms
DB_USERNAME=postgres
DB_CREDENTIAL=Secret

# Keystore storage path
KEYSTORE_PATH=/usr/share/keystore/
KEYSTORE_TEMP_DEFAULT_PATH=/usr/share/keystore-temp/

# Redis
ENABLE_REDIS_CACHE=true
REDIS_HOST=localhost
REDIS_PORT=6379

# Windows specific settings
COMPOSE_CONVERT_WINDOWS_PATHS=1
1 change: 1 addition & 0 deletions code/gms-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.gms.common.config;

import java.io.IOException;
import java.time.Clock;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
Expand All @@ -18,8 +18,8 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.io.IOException;
import java.time.Clock;

/**
* @author Peter Szrnka
Expand All @@ -28,6 +28,7 @@
@Configuration
@EnableScheduling
@EnableAsync
@ComponentScan(basePackages = "io.github.gms")
@EnableJpaRepositories(basePackages = "io.github.gms.secure.repository")
public class ApplicationConfig implements WebMvcConfigurer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CacheConfig implements CachingConfigurer {
@Override
@Bean
public CacheManager cacheManager() {
ConcurrentMapCacheManager manager = new ConcurrentMapCacheManager("systemStatusCache", CACHE_USER, "systemPropertyCache", CACHE_API);
ConcurrentMapCacheManager manager = new ConcurrentMapCacheManager(CACHE_USER, "systemPropertyCache", CACHE_API);
manager.setAllowNullValues(false);
return manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connec
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(connectionFactory)
.withCacheConfiguration("systemStatusCache",
RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(10)) // TTL set to 10 minutes
)
.withCacheConfiguration(CACHE_USER,
RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(10)) // TTL set to 10 minutes
Expand All @@ -67,10 +63,6 @@ public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
@Bean
public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() {
return (builder) -> builder
.withCacheConfiguration("systemStatusCache",
RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(10)) // TTL set to 10 minutes
)
.withCacheConfiguration(CACHE_USER,
RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(10)) // TTL set to 10 minutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import io.github.gms.secure.entity.AnnouncementEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface AnnouncementRepository extends JpaRepository<AnnouncementEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import io.github.gms.common.enums.EntityStatus;
import io.github.gms.secure.dto.IdNamePairDto;
import io.github.gms.secure.entity.ApiKeyEntity;
import org.springframework.stereotype.Repository;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface ApiKeyRepository extends JpaRepository<ApiKeyEntity, Long> {

ApiKeyEntity findByValueAndStatus(String value, EntityStatus status);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.github.gms.secure.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import io.github.gms.secure.entity.ApiKeyRestrictionEntity;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface ApiKeyRestrictionRepository extends JpaRepository<ApiKeyRestrictionEntity, Long> {

List<ApiKeyRestrictionEntity> findAllByUserIdAndSecretId(Long userId, Long secretId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package io.github.gms.secure.repository;

import java.time.ZonedDateTime;
import java.util.List;

import io.github.gms.secure.entity.EventEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import io.github.gms.secure.entity.EventEntity;
import java.time.ZonedDateTime;
import java.util.List;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface EventRepository extends JpaRepository<EventEntity, Long> {

@Query("select e from EventEntity e where e.eventDate < :eventDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
Expand All @@ -13,6 +14,7 @@
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface KeystoreAliasRepository extends JpaRepository<KeystoreAliasEntity, Long> {

List<KeystoreAliasEntity> findAllByKeystoreId(Long keystoreId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
Expand All @@ -16,6 +17,7 @@
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface KeystoreRepository extends JpaRepository<KeystoreEntity, Long> {

Optional<KeystoreEntity> findByIdAndUserId(Long id, Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.time.ZonedDateTime;
Expand All @@ -18,6 +19,7 @@
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface MessageRepository extends JpaRepository<MessageEntity, Long> {

Optional<MessageEntity> findByIdAndUserId(Long id, Long userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package io.github.gms.secure.repository;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;

import io.github.gms.common.enums.EntityStatus;
import io.github.gms.secure.entity.SecretEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import io.github.gms.common.enums.EntityStatus;
import io.github.gms.secure.entity.SecretEntity;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface SecretRepository extends JpaRepository<SecretEntity, Long> {

Optional<SecretEntity> findByUserIdAndSecretIdAndStatus(Long userId, String secretId, EntityStatus status);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.github.gms.secure.repository;

import java.util.Optional;

import io.github.gms.common.enums.SystemProperty;
import io.github.gms.secure.entity.SystemPropertyEntity;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import io.github.gms.common.enums.SystemProperty;
import io.github.gms.secure.entity.SystemPropertyEntity;
import jakarta.transaction.Transactional;
import java.util.Optional;

/**
* @author Peter Szrnka
* @since 1.0
*/
@Repository
public interface SystemPropertyRepository extends JpaRepository<SystemPropertyEntity, Long> {

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

Expand All @@ -15,6 +16,7 @@
* @author Peter Szrnka
* @since 1.0
*/
@Repository
@CacheConfig(cacheNames = CACHE_USER)
public interface UserRepository extends JpaRepository<UserEntity, Long> {

Expand Down
Loading

0 comments on commit 49ab1c9

Please sign in to comment.