diff --git a/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/GrpcConversionUtils.java b/java-spiffe-core/src/main/java/spiffe/workloadapi/GrpcConversionUtils.java similarity index 89% rename from java-spiffe-core/src/main/java/spiffe/workloadapi/internal/GrpcConversionUtils.java rename to java-spiffe-core/src/main/java/spiffe/workloadapi/GrpcConversionUtils.java index 46d710a..78d9206 100644 --- a/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/GrpcConversionUtils.java +++ b/java-spiffe-core/src/main/java/spiffe/workloadapi/GrpcConversionUtils.java @@ -1,4 +1,4 @@ -package spiffe.workloadapi.internal; +package spiffe.workloadapi; import com.google.protobuf.ByteString; import lombok.val; @@ -11,7 +11,6 @@ import spiffe.exception.X509SvidException; import spiffe.spiffeid.SpiffeId; import spiffe.spiffeid.TrustDomain; import spiffe.svid.x509svid.X509Svid; -import spiffe.workloadapi.X509Context; import spiffe.workloadapi.grpc.Workload; import java.security.KeyException; @@ -23,16 +22,16 @@ import java.util.Map; /** * Utility methods for converting GRPC objects to JAVA-SPIFFE domain objects. */ -public class GrpcConversionUtils { +class GrpcConversionUtils { - public static X509Context toX509Context(Workload.X509SVIDResponse x509SVIDResponse) throws CertificateException, X509SvidException { + static X509Context toX509Context(Workload.X509SVIDResponse x509SVIDResponse) throws CertificateException, X509SvidException { List x509SvidList = getListOfX509Svid(x509SVIDResponse); List x509BundleList = getListOfX509Bundles(x509SVIDResponse); X509BundleSet bundleSet = X509BundleSet.of(x509BundleList); return new X509Context(x509SvidList, bundleSet); } - private static List getListOfX509Bundles(Workload.X509SVIDResponse x509SVIDResponse) throws CertificateException { + static List getListOfX509Bundles(Workload.X509SVIDResponse x509SVIDResponse) throws CertificateException { List x509BundleList = new ArrayList<>(); for (Workload.X509SVID x509SVID : x509SVIDResponse.getSvidsList()) { SpiffeId spiffeId = SpiffeId.parse(x509SVID.getSpiffeId()); diff --git a/java-spiffe-core/src/main/java/spiffe/workloadapi/WorkloadApiClient.java b/java-spiffe-core/src/main/java/spiffe/workloadapi/WorkloadApiClient.java index 2fa0461..a4ab036 100644 --- a/java-spiffe-core/src/main/java/spiffe/workloadapi/WorkloadApiClient.java +++ b/java-spiffe-core/src/main/java/spiffe/workloadapi/WorkloadApiClient.java @@ -17,7 +17,6 @@ import spiffe.workloadapi.grpc.SpiffeWorkloadAPIGrpc; import spiffe.workloadapi.grpc.SpiffeWorkloadAPIGrpc.SpiffeWorkloadAPIBlockingStub; import spiffe.workloadapi.grpc.SpiffeWorkloadAPIGrpc.SpiffeWorkloadAPIStub; import spiffe.workloadapi.grpc.Workload; -import spiffe.workloadapi.internal.GrpcConversionUtils; import spiffe.workloadapi.internal.GrpcManagedChannelFactory; import spiffe.workloadapi.internal.ManagedChannelWrapper; import spiffe.workloadapi.internal.SecurityHeaderInterceptor; diff --git a/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/SecurityHeaderInterceptor.java b/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/SecurityHeaderInterceptor.java index 64c83bc..8e8bd20 100644 --- a/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/SecurityHeaderInterceptor.java +++ b/java-spiffe-core/src/main/java/spiffe/workloadapi/internal/SecurityHeaderInterceptor.java @@ -10,13 +10,13 @@ public class SecurityHeaderInterceptor implements ClientInterceptor { * Intercepts the call to the WorkloadAPI and add the required security header */ @Override - public ClientCall interceptCall(MethodDescriptor method, CallOptions callOptions, Channel next) { - return new ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOptions)) { + public ClientCall interceptCall(MethodDescriptor method, CallOptions callOptions, Channel next) { + return new ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOptions)) { @Override - public void start(Listener responseListener, Metadata headers) { + public void start(Listener responseListener, Metadata headers) { Metadata.Key headerKey = Metadata.Key.of(SECURITY_HEADER, Metadata.ASCII_STRING_MARSHALLER); headers.put(headerKey, "true"); - super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener(responseListener) {}, headers); + super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener(responseListener) {}, headers); } }; } diff --git a/java-spiffe-provider/src/main/java/spiffe/provider/SpiffeTrustManagerFactory.java b/java-spiffe-provider/src/main/java/spiffe/provider/SpiffeTrustManagerFactory.java index 8440ea6..23cd471 100644 --- a/java-spiffe-provider/src/main/java/spiffe/provider/SpiffeTrustManagerFactory.java +++ b/java-spiffe-provider/src/main/java/spiffe/provider/SpiffeTrustManagerFactory.java @@ -43,13 +43,9 @@ public class SpiffeTrustManagerFactory extends TrustManagerFactorySpi { */ @Override public TrustManager[] engineGetTrustManagers() { - SpiffeTrustManager spiffeTrustManager = - null; + SpiffeTrustManager spiffeTrustManager = null; try { - spiffeTrustManager = new SpiffeTrustManager( - X509SourceManager.getX509Source(), - this::getAcceptedSpiffeIds - ); + spiffeTrustManager = new SpiffeTrustManager(X509SourceManager.getX509Source(), this::getAcceptedSpiffeIds); } catch (X509SourceException e) { throw new SpiffeProviderException("The X509 source could not be created", e); } catch (SocketEndpointAddressException e) { @@ -79,7 +75,7 @@ public class SpiffeTrustManagerFactory extends TrustManagerFactorySpi { * with a function verify a chain of certificates using a to validate the SPIFFE IDs * of the peer's certificates, and a supplier of accepted SPIFFE IDs. * - * @param x509BundleSource a {@link X509BundleSource} to provide the X.509-Bundles + * @param x509BundleSource a {@link X509BundleSource} to provide the X.509-Bundles * @param acceptedSpiffeIdsSupplier a Supplier to provide a List of SPIFFE IDs that are accepted * @return a TrustManager array with an initialized TrustManager. */ @@ -87,17 +83,10 @@ public class SpiffeTrustManagerFactory extends TrustManagerFactorySpi { X509BundleSource x509BundleSource, Supplier> acceptedSpiffeIdsSupplier) { - Supplier> spiffeIdsSupplier; - if (acceptedSpiffeIdsSupplier != null) { - spiffeIdsSupplier = acceptedSpiffeIdsSupplier; - } else { - spiffeIdsSupplier = this::getAcceptedSpiffeIds; - } - val spiffeTrustManager = - new SpiffeTrustManager( - x509BundleSource, - spiffeIdsSupplier - ); + final Supplier> spiffeIdsSupplier = + acceptedSpiffeIdsSupplier != null ? acceptedSpiffeIdsSupplier : this::getAcceptedSpiffeIds; + + val spiffeTrustManager = new SpiffeTrustManager(x509BundleSource, spiffeIdsSupplier); return new TrustManager[]{spiffeTrustManager}; }