Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@
import io.opentdf.platform.policy.KasPublicKeyAlgEnum;
import io.opentdf.platform.policy.KeyAccessServer;
import io.opentdf.platform.policy.Value;
import io.opentdf.platform.policy.attributes.AttributesServiceClient;
import io.opentdf.platform.policy.attributes.AttributesServiceClientInterface;
import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsRequest;
import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsResponse;
import org.slf4j.Logger;
Expand DownExpand Up@@ -698,7 +698,7 @@ public static Granter newGranterFromAttributes(Value... attrValues) throws AutoC
}

// Gets a list of directory of KAS grants for a list of attribute FQNs
public static Granter newGranterFromService(AttributesServiceClient as, KASKeyCache keyCache, AttributeValueFQN... fqns) throws AutoConfigureException {
public static Granter newGranterFromService(AttributesServiceClientInterface as, KASKeyCache keyCache, AttributeValueFQN... fqns) throws AutoConfigureException {
GetAttributeValuesByFqnsRequest request = GetAttributeValuesByFqnsRequest.newBuilder()
.addAllFqns(Arrays.stream(fqns).map(AttributeValueFQN::toString).collect(Collectors.toList()))
.setWithValue(AttributeValueSelector.newBuilder().setWithKeyAccessGrants(true).build())
Expand Down
33 changes: 20 additions & 13 deletions sdk/src/main/java/io/opentdf/platform/sdk/SDK.java
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
package io.opentdf.platform.sdk;

import com.connectrpc.Interceptor;
import io.opentdf.platform.authorization.AuthorizationServiceClient;
import io.opentdf.platform.policy.attributes.AttributesServiceClient;
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceClient;
import io.opentdf.platform.policy.namespaces.NamespaceServiceClient;
import io.opentdf.platform.policy.resourcemapping.ResourceMappingServiceClient;
import io.opentdf.platform.policy.subjectmapping.SubjectMappingServiceClient;
import com.connectrpc.impl.ProtocolClient;
import io.opentdf.platform.authorization.AuthorizationServiceClientInterface;
import io.opentdf.platform.policy.attributes.AttributesServiceClientInterface;
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceClientInterface;
import io.opentdf.platform.policy.namespaces.NamespaceServiceClientInterface;
import io.opentdf.platform.policy.resourcemapping.ResourceMappingServiceClientInterface;
import io.opentdf.platform.policy.subjectmapping.SubjectMappingServiceClientInterface;
import io.opentdf.platform.sdk.nanotdf.NanoTDFType;

import javax.net.ssl.TrustManager;
Expand All@@ -28,6 +29,7 @@ public class SDK implements AutoCloseable {
private final TrustManager trustManager;
private final Interceptor authInterceptor;
private final String platformUrl;
private final ProtocolClient platformServicesClient;

/**
* Closes the SDK, including its associated services.
Expand DownExpand Up@@ -61,17 +63,17 @@ byte[] unwrap(Manifest.KeyAccess keyAccess, String policy,
* It extends the AutoCloseable interface, allowing for the release of resources when no longer needed.
*/
public interface Services extends AutoCloseable {
AttributesServiceClient attributes();
AttributesServiceClientInterface attributes();

NamespaceServiceClient namespaces();
NamespaceServiceClientInterface namespaces();

SubjectMappingServiceClient subjectMappings();
SubjectMappingServiceClientInterface subjectMappings();

ResourceMappingServiceClient resourceMappings();
ResourceMappingServiceClientInterface resourceMappings();

AuthorizationServiceClient authorization();
AuthorizationServiceClientInterface authorization();

KeyAccessServerRegistryServiceClient kasRegistry();
KeyAccessServerRegistryServiceClientInterface kasRegistry();

KAS kas();
}
Expand All@@ -84,11 +86,12 @@ public Optional<Interceptor> getAuthInterceptor() {
return Optional.ofNullable(authInterceptor);
}

SDK(Services services, TrustManager trustManager, Interceptor authInterceptor, String platformUrl) {
SDK(Services services, TrustManager trustManager, Interceptor authInterceptor, ProtocolClient platformServicesClient, String platformUrl) {
this.platformUrl = platformUrl;
this.services = services;
this.trustManager = trustManager;
this.authInterceptor = authInterceptor;
this.platformServicesClient = platformServicesClient;
}

public Services getServices() {
Expand All@@ -115,6 +118,10 @@ public void readNanoTDF(ByteBuffer nanoTDF, OutputStream out, Config.NanoTDFRead
ntdf.readNanoTDF(nanoTDF, out, config, platformUrl);
}

public ProtocolClient getPlatformServicesClient() {
return this.platformServicesClient;
}

/**
* Checks to see if this has the structure of a Z-TDF in that it is a zip file
* containing
Expand Down
9 changes: 6 additions & 3 deletions sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -217,13 +217,15 @@ private Interceptor getAuthInterceptor(RSAKey rsaKey) {
static class ServicesAndInternals {
final Interceptor interceptor;
final TrustManager trustManager;
final ProtocolClient protocolClient;

final SDK.Services services;

ServicesAndInternals(Interceptor interceptor, TrustManager trustManager, SDK.Services services) {
ServicesAndInternals(Interceptor interceptor, TrustManager trustManager, SDK.Services services, ProtocolClient protocolClient) {
this.interceptor = interceptor;
this.trustManager = trustManager;
this.services = services;
this.protocolClient = protocolClient;
}
}

Expand DownExpand Up@@ -297,7 +299,8 @@ public SDK.KAS kas() {
return new ServicesAndInternals(
authInterceptor,
sslFactory == null ? null : sslFactory.getTrustManager().orElse(null),
services);
services,
client);
}

@Nonnull
Expand All@@ -308,7 +311,7 @@ private KASClient getKASClient(RSAKey dpopKey, Interceptor interceptor) {

public SDK build() {
var services = buildServices();
return new SDK(services.services, services.trustManager, services.interceptor, platformEndpoint);
return new SDK(services.services, services.trustManager, services.interceptor, services.protocolClient, platformEndpoint);
}

private ProtocolClient getUnauthenticatedProtocolClient(String endpoint, OkHttpClient httpClient) {
Expand Down
9 changes: 9 additions & 0 deletions sdk/src/test/java/io/opentdf/platform/sdk/SDKTest.java
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
package io.opentdf.platform.sdk;

import com.connectrpc.impl.ProtocolClient;
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
import org.junit.jupiter.api.Test;

Expand All@@ -9,6 +10,7 @@
import java.util.Random;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

class SDKTest {

Expand All@@ -21,6 +23,13 @@ void testExaminingValidZTDF() throws IOException {
}
}

@Test
void testReadingProtocolClient() {
var platformServicesClient = mock(ProtocolClient.class);
var sdk = new SDK(new FakeServicesBuilder().build(), null, null, platformServicesClient, null);
assertThat(sdk.getPlatformServicesClient()).isSameAs(platformServicesClient);
}

@Test
void testExaminingInvalidFile() {
var chan = new SeekableByteChannel() {
Expand Down