mirror of https://github.com/grpc/grpc-java.git
Make clearer that AltsAuthContext is internal by renaming
This commit is contained in:
parent
7f3ddca30f
commit
4c5559d54f
|
|
@ -18,7 +18,7 @@ package io.grpc.alts;
|
||||||
|
|
||||||
import io.grpc.ServerCall;
|
import io.grpc.ServerCall;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.alts.internal.AltsAuthContext;
|
import io.grpc.alts.internal.AltsInternalContext;
|
||||||
import io.grpc.alts.internal.AltsProtocolNegotiator;
|
import io.grpc.alts.internal.AltsProtocolNegotiator;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
@ -34,8 +34,8 @@ public final class AuthorizationUtil {
|
||||||
*/
|
*/
|
||||||
public static Status clientAuthorizationCheck(
|
public static Status clientAuthorizationCheck(
|
||||||
ServerCall<?, ?> call, Collection<String> expectedServiceAccounts) {
|
ServerCall<?, ?> call, Collection<String> expectedServiceAccounts) {
|
||||||
AltsAuthContext altsContext =
|
AltsInternalContext altsContext =
|
||||||
(AltsAuthContext) call.getAttributes().get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
|
(AltsInternalContext) call.getAttributes().get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
|
||||||
if (altsContext == null) {
|
if (altsContext == null) {
|
||||||
return Status.PERMISSION_DENIED.withDescription("Peer ALTS AuthContext not found");
|
return Status.PERMISSION_DENIED.withDescription("Peer ALTS AuthContext not found");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@ package io.grpc.alts.internal;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/** AltsAuthContext contains security-related context information about an ALTs connection. */
|
/** AltsInternalContext contains security-related context information about an ALTs connection. */
|
||||||
public final class AltsAuthContext {
|
public final class AltsInternalContext {
|
||||||
final AltsContext context;
|
final AltsContext context;
|
||||||
|
|
||||||
/** Create a new AltsAuthContext. */
|
/** Create a new AltsInternalContext. */
|
||||||
public AltsAuthContext(HandshakerResult result) {
|
public AltsInternalContext(HandshakerResult result) {
|
||||||
context =
|
context =
|
||||||
AltsContext.newBuilder()
|
AltsContext.newBuilder()
|
||||||
.setApplicationProtocol(result.getApplicationProtocol())
|
.setApplicationProtocol(result.getApplicationProtocol())
|
||||||
|
|
@ -39,8 +39,8 @@ public final class AltsAuthContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static AltsAuthContext getDefaultInstance() {
|
public static AltsInternalContext getDefaultInstance() {
|
||||||
return new AltsAuthContext(HandshakerResult.newBuilder().build());
|
return new AltsInternalContext(HandshakerResult.newBuilder().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -334,24 +334,24 @@ public final class AltsProtocolNegotiator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SecurityDetails validatePeerObject(Object peerObject) throws GeneralSecurityException {
|
public SecurityDetails validatePeerObject(Object peerObject) throws GeneralSecurityException {
|
||||||
AltsAuthContext altsAuthContext = (AltsAuthContext) peerObject;
|
AltsInternalContext altsContext = (AltsInternalContext) peerObject;
|
||||||
// Checks peer Rpc Protocol Versions in the ALTS auth context. Fails the connection if
|
// Checks peer Rpc Protocol Versions in the ALTS auth context. Fails the connection if
|
||||||
// Rpc Protocol Versions mismatch.
|
// Rpc Protocol Versions mismatch.
|
||||||
RpcVersionsCheckResult checkResult =
|
RpcVersionsCheckResult checkResult =
|
||||||
RpcProtocolVersionsUtil.checkRpcProtocolVersions(
|
RpcProtocolVersionsUtil.checkRpcProtocolVersions(
|
||||||
RpcProtocolVersionsUtil.getRpcProtocolVersions(),
|
RpcProtocolVersionsUtil.getRpcProtocolVersions(),
|
||||||
altsAuthContext.getPeerRpcVersions());
|
altsContext.getPeerRpcVersions());
|
||||||
if (!checkResult.getResult()) {
|
if (!checkResult.getResult()) {
|
||||||
String errorMessage =
|
String errorMessage =
|
||||||
"Local Rpc Protocol Versions "
|
"Local Rpc Protocol Versions "
|
||||||
+ RpcProtocolVersionsUtil.getRpcProtocolVersions()
|
+ RpcProtocolVersionsUtil.getRpcProtocolVersions()
|
||||||
+ " are not compatible with peer Rpc Protocol Versions "
|
+ " are not compatible with peer Rpc Protocol Versions "
|
||||||
+ altsAuthContext.getPeerRpcVersions();
|
+ altsContext.getPeerRpcVersions();
|
||||||
throw Status.UNAVAILABLE.withDescription(errorMessage).asRuntimeException();
|
throw Status.UNAVAILABLE.withDescription(errorMessage).asRuntimeException();
|
||||||
}
|
}
|
||||||
return new SecurityDetails(
|
return new SecurityDetails(
|
||||||
SecurityLevel.PRIVACY_AND_INTEGRITY,
|
SecurityLevel.PRIVACY_AND_INTEGRITY,
|
||||||
new Security(new OtherSecurity("alts", Any.pack(altsAuthContext.context))));
|
new Security(new OtherSecurity("alts", Any.pack(altsContext.context))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ public final class AltsTsiHandshaker implements TsiHandshaker {
|
||||||
@Override
|
@Override
|
||||||
public Object extractPeerObject() throws GeneralSecurityException {
|
public Object extractPeerObject() throws GeneralSecurityException {
|
||||||
Preconditions.checkState(!isInProgress(), "Handshake is not complete.");
|
Preconditions.checkState(!isInProgress(), "Handshake is not complete.");
|
||||||
return new AltsAuthContext(handshaker.getResult());
|
return new AltsInternalContext(handshaker.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a new TsiHandshaker for use by the client. */
|
/** Creates a new TsiHandshaker for use by the client. */
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import io.grpc.Metadata;
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
import io.grpc.ServerCall;
|
import io.grpc.ServerCall;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.alts.internal.AltsAuthContext;
|
import io.grpc.alts.internal.AltsInternalContext;
|
||||||
import io.grpc.alts.internal.AltsProtocolNegotiator;
|
import io.grpc.alts.internal.AltsProtocolNegotiator;
|
||||||
import io.grpc.alts.internal.HandshakerResult;
|
import io.grpc.alts.internal.HandshakerResult;
|
||||||
import io.grpc.alts.internal.Identity;
|
import io.grpc.alts.internal.Identity;
|
||||||
|
|
@ -65,8 +65,8 @@ public final class AuthorizationUtilTest {
|
||||||
HandshakerResult.newBuilder()
|
HandshakerResult.newBuilder()
|
||||||
.setPeerIdentity(Identity.newBuilder().setServiceAccount(peerServiceAccount))
|
.setPeerIdentity(Identity.newBuilder().setServiceAccount(peerServiceAccount))
|
||||||
.build();
|
.build();
|
||||||
AltsAuthContext altsAuthContext = new AltsAuthContext(handshakerResult);
|
AltsInternalContext altsContext = new AltsInternalContext(handshakerResult);
|
||||||
attrsBuilder.set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, altsAuthContext);
|
attrsBuilder.set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, altsContext);
|
||||||
}
|
}
|
||||||
attrs = attrsBuilder.build();
|
attrs = attrsBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/** Unit tests for {@link AltsAuthContext}. */
|
/** Unit tests for {@link AltsInternalContext}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public final class AltsAuthContextTest {
|
public final class AltsInternalContextTest {
|
||||||
private static final int TEST_MAX_RPC_VERSION_MAJOR = 3;
|
private static final int TEST_MAX_RPC_VERSION_MAJOR = 3;
|
||||||
private static final int TEST_MAX_RPC_VERSION_MINOR = 5;
|
private static final int TEST_MAX_RPC_VERSION_MINOR = 5;
|
||||||
private static final int TEST_MIN_RPC_VERSION_MAJOR = 2;
|
private static final int TEST_MIN_RPC_VERSION_MAJOR = 2;
|
||||||
|
|
@ -75,16 +75,16 @@ public final class AltsAuthContextTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAltsAuthContext() {
|
public void testAltsInternalContext() {
|
||||||
AltsAuthContext authContext = new AltsAuthContext(handshakerResult);
|
AltsInternalContext context = new AltsInternalContext(handshakerResult);
|
||||||
assertEquals(TEST_APPLICATION_PROTOCOL, authContext.getApplicationProtocol());
|
assertEquals(TEST_APPLICATION_PROTOCOL, context.getApplicationProtocol());
|
||||||
assertEquals(TEST_RECORD_PROTOCOL, authContext.getRecordProtocol());
|
assertEquals(TEST_RECORD_PROTOCOL, context.getRecordProtocol());
|
||||||
assertEquals(TEST_SECURITY_LEVEL, authContext.getSecurityLevel());
|
assertEquals(TEST_SECURITY_LEVEL, context.getSecurityLevel());
|
||||||
assertEquals(TEST_PEER_SERVICE_ACCOUNT, authContext.getPeerServiceAccount());
|
assertEquals(TEST_PEER_SERVICE_ACCOUNT, context.getPeerServiceAccount());
|
||||||
assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, authContext.getLocalServiceAccount());
|
assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, context.getLocalServiceAccount());
|
||||||
assertEquals(rpcVersions, authContext.getPeerRpcVersions());
|
assertEquals(rpcVersions, context.getPeerRpcVersions());
|
||||||
assertEquals(testPeerAttributes, authContext.getPeerAttributes());
|
assertEquals(testPeerAttributes, context.getPeerAttributes());
|
||||||
assertEquals(TEST_PEER_ATTRIBUTES_VALUE, authContext.getPeerAttributes()
|
assertEquals(TEST_PEER_ATTRIBUTES_VALUE, context.getPeerAttributes()
|
||||||
.get(TEST_PEER_ATTRIBUTES_KEY));
|
.get(TEST_PEER_ATTRIBUTES_KEY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,8 +96,8 @@ public class AltsProtocolNegotiatorTest {
|
||||||
private Throwable caughtException;
|
private Throwable caughtException;
|
||||||
|
|
||||||
private TsiPeer mockedTsiPeer = new TsiPeer(Collections.<Property<?>>emptyList());
|
private TsiPeer mockedTsiPeer = new TsiPeer(Collections.<Property<?>>emptyList());
|
||||||
private AltsAuthContext mockedAltsContext =
|
private AltsInternalContext mockedAltsContext =
|
||||||
new AltsAuthContext(
|
new AltsInternalContext(
|
||||||
HandshakerResult.newBuilder()
|
HandshakerResult.newBuilder()
|
||||||
.setPeerRpcVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions())
|
.setPeerRpcVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions())
|
||||||
.build());
|
.build());
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ public class AltsTsiHandshakerTest {
|
||||||
TEST_SERVER_SERVICE_ACCOUNT,
|
TEST_SERVER_SERVICE_ACCOUNT,
|
||||||
clientPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue());
|
clientPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue());
|
||||||
|
|
||||||
AltsAuthContext clientContext = (AltsAuthContext) handshakerClient.extractPeerObject();
|
AltsInternalContext clientContext = (AltsInternalContext) handshakerClient.extractPeerObject();
|
||||||
assertEquals(TEST_APPLICATION_PROTOCOL, clientContext.getApplicationProtocol());
|
assertEquals(TEST_APPLICATION_PROTOCOL, clientContext.getApplicationProtocol());
|
||||||
assertEquals(TEST_RECORD_PROTOCOL, clientContext.getRecordProtocol());
|
assertEquals(TEST_RECORD_PROTOCOL, clientContext.getRecordProtocol());
|
||||||
assertEquals(TEST_SERVER_SERVICE_ACCOUNT, clientContext.getPeerServiceAccount());
|
assertEquals(TEST_SERVER_SERVICE_ACCOUNT, clientContext.getPeerServiceAccount());
|
||||||
|
|
@ -258,7 +258,7 @@ public class AltsTsiHandshakerTest {
|
||||||
TEST_CLIENT_SERVICE_ACCOUNT,
|
TEST_CLIENT_SERVICE_ACCOUNT,
|
||||||
serverPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue());
|
serverPeer.getProperty(AltsTsiHandshaker.TSI_SERVICE_ACCOUNT_PEER_PROPERTY).getValue());
|
||||||
|
|
||||||
AltsAuthContext serverContext = (AltsAuthContext) handshakerServer.extractPeerObject();
|
AltsInternalContext serverContext = (AltsInternalContext) handshakerServer.extractPeerObject();
|
||||||
assertEquals(TEST_APPLICATION_PROTOCOL, serverContext.getApplicationProtocol());
|
assertEquals(TEST_APPLICATION_PROTOCOL, serverContext.getApplicationProtocol());
|
||||||
assertEquals(TEST_RECORD_PROTOCOL, serverContext.getRecordProtocol());
|
assertEquals(TEST_RECORD_PROTOCOL, serverContext.getRecordProtocol());
|
||||||
assertEquals(TEST_CLIENT_SERVICE_ACCOUNT, serverContext.getPeerServiceAccount());
|
assertEquals(TEST_CLIENT_SERVICE_ACCOUNT, serverContext.getPeerServiceAccount());
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ public class FakeTsiHandshaker implements TsiHandshaker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object extractPeerObject() {
|
public Object extractPeerObject() {
|
||||||
return AltsAuthContext.getDefaultInstance();
|
return AltsInternalContext.getDefaultInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue