Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions datamodel-dynamodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# datamodel-dynamodb

This module provides an AWS [DynamoDB](https://aws.amazon.com/dynamodb/) implementation of the the data model interfaces so that the underlying implementation can be swapped out as a runtime dependency.

For additional details on this module see, please visit the [Datamodel DynamoDB documentation](/docs/modules/datamodel/dynamodb.md).
110 changes: 110 additions & 0 deletions datamodel-dynamodb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.unitvectory</groupId>
<artifactId>serviceauthcentral</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<groupId>com.unitvectory.serviceauthcentral</groupId>
<artifactId>datamodel-dynamodb</artifactId>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>com.unitvectory</groupId>
<artifactId>consistgen</artifactId>
</dependency>
<dependency>
<groupId>com.unitvectory.serviceauthcentral</groupId>
<artifactId>util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.unitvectory.serviceauthcentral</groupId>
<artifactId>datamodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb-enhanced</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/generated-sources/annotations</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- Required as this is a library that needs to not be repackaged -->
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${lombok-mapstruct-binding.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions datamodel-dynamodb/src/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This tells lombok this directory is the root,
# no need to look somewhere else for java code.
config.stopBubbling = true
# This will add the @lombok.Generated annotation
# to all the code generated by Lombok,
# so it can be excluded from coverage by jacoco.
lombok.addLombokGeneratedAnnotation = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.unitvectory.serviceauthcentral.datamodel.dynamodb.config;

import java.net.URI;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;

/**
* The data model config for AWS DynamoDB client
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
@Profile("datamodel-dynamodb")
public class DatamodelDynamoDbClientConfig {

@Value("${aws.region:us-east-1}")
private String awsRegion;

@Value("${aws.dynamodb.endpoint:}")
private String dynamoDbEndpoint;

@Bean
public DynamoDbClient dynamoDbClient() {
DynamoDbClientBuilder builder = DynamoDbClient.builder()
.region(Region.of(awsRegion));

if (dynamoDbEndpoint != null && !dynamoDbEndpoint.isEmpty()) {
// For local DynamoDB testing
builder.endpointOverride(URI.create(dynamoDbEndpoint))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("dummy", "dummy")));
} else {
builder.credentialsProvider(DefaultCredentialsProvider.create());
}

return builder.build();
}

@Bean
public DynamoDbEnhancedClient dynamoDbEnhancedClient(DynamoDbClient dynamoDbClient) {
return DynamoDbEnhancedClient.builder()
.dynamoDbClient(dynamoDbClient)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.unitvectory.serviceauthcentral.datamodel.dynamodb.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.unitvectory.consistgen.epoch.EpochTimeProvider;
import com.unitvectory.serviceauthcentral.datamodel.dynamodb.repository.DynamoDbAuthorizationRepository;
import com.unitvectory.serviceauthcentral.datamodel.dynamodb.repository.DynamoDbClientRepository;
import com.unitvectory.serviceauthcentral.datamodel.dynamodb.repository.DynamoDbJwkCacheRepository;
import com.unitvectory.serviceauthcentral.datamodel.dynamodb.repository.DynamoDbLoginCodeRepository;
import com.unitvectory.serviceauthcentral.datamodel.dynamodb.repository.DynamoDbLoginStateRepository;
import com.unitvectory.serviceauthcentral.datamodel.repository.AuthorizationRepository;
import com.unitvectory.serviceauthcentral.datamodel.repository.ClientRepository;
import com.unitvectory.serviceauthcentral.datamodel.repository.JwkCacheRepository;
import com.unitvectory.serviceauthcentral.datamodel.repository.LoginCodeRepository;
import com.unitvectory.serviceauthcentral.datamodel.repository.LoginStateRepository;

import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;

/**
* The data model config for AWS DynamoDB
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
@Profile("datamodel-dynamodb")
public class DatamodelDynamoDbConfig {

@Autowired
private DynamoDbEnhancedClient dynamoDbEnhancedClient;

@Autowired
private EpochTimeProvider epochTimeProvider;

@Value("${sac.datamodel.dynamodb.table.authorizations:sac-authorizations}")
private String tableAuthorizations;

@Value("${sac.datamodel.dynamodb.table.clients:sac-clients}")
private String tableClients;

@Value("${sac.datamodel.dynamodb.table.keys:sac-keys}")
private String tableKeys;

@Value("${sac.datamodel.dynamodb.table.logincodes:sac-loginCodes}")
private String tableLoginCodes;

@Value("${sac.datamodel.dynamodb.table.loginstates:sac-loginStates}")
private String tableLoginStates;

@Bean
public AuthorizationRepository authorizationRepository() {
return new DynamoDbAuthorizationRepository(this.dynamoDbEnhancedClient, this.tableAuthorizations,
this.epochTimeProvider);
}

@Bean
public ClientRepository clientRepository() {
return new DynamoDbClientRepository(this.dynamoDbEnhancedClient, this.tableClients,
this.epochTimeProvider);
}

@Bean
public JwkCacheRepository jwkCacheRepository() {
return new DynamoDbJwkCacheRepository(this.dynamoDbEnhancedClient, this.tableKeys);
}

@Bean
public LoginCodeRepository loginCodeRepository() {
return new DynamoDbLoginCodeRepository(this.dynamoDbEnhancedClient, this.tableLoginCodes);
}

@Bean
public LoginStateRepository loginStateRepository() {
return new DynamoDbLoginStateRepository(this.dynamoDbEnhancedClient, this.tableLoginStates);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.unitvectory.serviceauthcentral.datamodel.dynamodb.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import com.unitvectory.serviceauthcentral.datamodel.dynamodb.model.CachedJwkRecord;
import com.unitvectory.serviceauthcentral.datamodel.model.CachedJwk;

/**
* The mapper for the CachedJwkRecord
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Mapper
public interface CachedJwkRecordMapper {

CachedJwkRecordMapper INSTANCE = Mappers.getMapper(CachedJwkRecordMapper.class);

@Mapping(target = "pk", ignore = true)
@Mapping(target = "url", source = "url")
@Mapping(target = "ttl", source = "ttl")
@Mapping(target = "valid", source = "jwk.valid")
@Mapping(target = "kid", source = "jwk.kid")
@Mapping(target = "kty", source = "jwk.kty")
@Mapping(target = "alg", source = "jwk.alg")
@Mapping(target = "use", source = "jwk.use")
@Mapping(target = "n", source = "jwk.n")
@Mapping(target = "e", source = "jwk.e")
CachedJwkRecord cachedJwkToCachedJwkRecord(String url, long ttl, CachedJwk jwk);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.unitvectory.serviceauthcentral.datamodel.dynamodb.mapper;

import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import com.unitvectory.serviceauthcentral.datamodel.dynamodb.model.ClientScopeRecord;
import com.unitvectory.serviceauthcentral.datamodel.model.ClientScope;

/**
* The mapper for ClientScopeRecord
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Mapper
public interface ClientScopeMapper {

ClientScopeMapper INSTANCE = Mappers.getMapper(ClientScopeMapper.class);

@Mapping(target = "scope", source = "scope")
@Mapping(target = "description", source = "description")
ClientScopeRecord clientScopeToClientScopeRecord(ClientScope clientScope);

List<ClientScopeRecord> clientScopeToClientScopeRecord(List<ClientScope> clientScopes);
}
Loading