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.Status;
|
||||
import io.grpc.alts.internal.AltsAuthContext;
|
||||
import io.grpc.alts.internal.AltsInternalContext;
|
||||
import io.grpc.alts.internal.AltsProtocolNegotiator;
|
||||
import java.util.Collection;
|
||||
|
||||
|
|
@ -34,8 +34,8 @@ public final class AuthorizationUtil {
|
|||
*/
|
||||
public static Status clientAuthorizationCheck(
|
||||
ServerCall<?, ?> call, Collection<String> expectedServiceAccounts) {
|
||||
AltsAuthContext altsContext =
|
||||
(AltsAuthContext) call.getAttributes().get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
|
||||
AltsInternalContext altsContext =
|
||||
(AltsInternalContext) call.getAttributes().get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
|
||||
if (altsContext == null) {
|
||||
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 java.util.Map;
|
||||
|
||||
/** AltsAuthContext contains security-related context information about an ALTs connection. */
|
||||
public final class AltsAuthContext {
|
||||
/** AltsInternalContext contains security-related context information about an ALTs connection. */
|
||||
public final class AltsInternalContext {
|
||||
final AltsContext context;
|
||||
|
||||
/** Create a new AltsAuthContext. */
|
||||
public AltsAuthContext(HandshakerResult result) {
|
||||
/** Create a new AltsInternalContext. */
|
||||
public AltsInternalContext(HandshakerResult result) {
|
||||
context =
|
||||
AltsContext.newBuilder()
|
||||
.setApplicationProtocol(result.getApplicationProtocol())
|
||||
|
|
@ -39,8 +39,8 @@ public final class AltsAuthContext {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static AltsAuthContext getDefaultInstance() {
|
||||
return new AltsAuthContext(HandshakerResult.newBuilder().build());
|
||||
public static AltsInternalContext getDefaultInstance() {
|
||||
return new AltsInternalContext(HandshakerResult.newBuilder().build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -334,24 +334,24 @@ public final class AltsProtocolNegotiator {
|
|||
|
||||
@Override
|
||||
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
|
||||
// Rpc Protocol Versions mismatch.
|
||||
RpcVersionsCheckResult checkResult =
|
||||
RpcProtocolVersionsUtil.checkRpcProtocolVersions(
|
||||
RpcProtocolVersionsUtil.getRpcProtocolVersions(),
|
||||
altsAuthContext.getPeerRpcVersions());
|
||||
altsContext.getPeerRpcVersions());
|
||||
if (!checkResult.getResult()) {
|
||||
String errorMessage =
|
||||
"Local Rpc Protocol Versions "
|
||||
+ RpcProtocolVersionsUtil.getRpcProtocolVersions()
|
||||
+ " are not compatible with peer Rpc Protocol Versions "
|
||||
+ altsAuthContext.getPeerRpcVersions();
|
||||
+ altsContext.getPeerRpcVersions();
|
||||
throw Status.UNAVAILABLE.withDescription(errorMessage).asRuntimeException();
|
||||
}
|
||||
return new SecurityDetails(
|
||||
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
|
||||
public Object extractPeerObject() throws GeneralSecurityException {
|
||||
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. */
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import io.grpc.Metadata;
|
|||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.ServerCall;
|
||||
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.HandshakerResult;
|
||||
import io.grpc.alts.internal.Identity;
|
||||
|
|
@ -65,8 +65,8 @@ public final class AuthorizationUtilTest {
|
|||
HandshakerResult.newBuilder()
|
||||
.setPeerIdentity(Identity.newBuilder().setServiceAccount(peerServiceAccount))
|
||||
.build();
|
||||
AltsAuthContext altsAuthContext = new AltsAuthContext(handshakerResult);
|
||||
attrsBuilder.set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, altsAuthContext);
|
||||
AltsInternalContext altsContext = new AltsInternalContext(handshakerResult);
|
||||
attrsBuilder.set(AltsProtocolNegotiator.AUTH_CONTEXT_KEY, altsContext);
|
||||
}
|
||||
attrs = attrsBuilder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link AltsAuthContext}. */
|
||||
/** Unit tests for {@link AltsInternalContext}. */
|
||||
@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_MINOR = 5;
|
||||
private static final int TEST_MIN_RPC_VERSION_MAJOR = 2;
|
||||
|
|
@ -75,16 +75,16 @@ public final class AltsAuthContextTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAltsAuthContext() {
|
||||
AltsAuthContext authContext = new AltsAuthContext(handshakerResult);
|
||||
assertEquals(TEST_APPLICATION_PROTOCOL, authContext.getApplicationProtocol());
|
||||
assertEquals(TEST_RECORD_PROTOCOL, authContext.getRecordProtocol());
|
||||
assertEquals(TEST_SECURITY_LEVEL, authContext.getSecurityLevel());
|
||||
assertEquals(TEST_PEER_SERVICE_ACCOUNT, authContext.getPeerServiceAccount());
|
||||
assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, authContext.getLocalServiceAccount());
|
||||
assertEquals(rpcVersions, authContext.getPeerRpcVersions());
|
||||
assertEquals(testPeerAttributes, authContext.getPeerAttributes());
|
||||
assertEquals(TEST_PEER_ATTRIBUTES_VALUE, authContext.getPeerAttributes()
|
||||
public void testAltsInternalContext() {
|
||||
AltsInternalContext context = new AltsInternalContext(handshakerResult);
|
||||
assertEquals(TEST_APPLICATION_PROTOCOL, context.getApplicationProtocol());
|
||||
assertEquals(TEST_RECORD_PROTOCOL, context.getRecordProtocol());
|
||||
assertEquals(TEST_SECURITY_LEVEL, context.getSecurityLevel());
|
||||
assertEquals(TEST_PEER_SERVICE_ACCOUNT, context.getPeerServiceAccount());
|
||||
assertEquals(TEST_LOCAL_SERVICE_ACCOUNT, context.getLocalServiceAccount());
|
||||
assertEquals(rpcVersions, context.getPeerRpcVersions());
|
||||
assertEquals(testPeerAttributes, context.getPeerAttributes());
|
||||
assertEquals(TEST_PEER_ATTRIBUTES_VALUE, context.getPeerAttributes()
|
||||
.get(TEST_PEER_ATTRIBUTES_KEY));
|
||||
}
|
||||
}
|
||||
|
|
@ -96,8 +96,8 @@ public class AltsProtocolNegotiatorTest {
|
|||
private Throwable caughtException;
|
||||
|
||||
private TsiPeer mockedTsiPeer = new TsiPeer(Collections.<Property<?>>emptyList());
|
||||
private AltsAuthContext mockedAltsContext =
|
||||
new AltsAuthContext(
|
||||
private AltsInternalContext mockedAltsContext =
|
||||
new AltsInternalContext(
|
||||
HandshakerResult.newBuilder()
|
||||
.setPeerRpcVersions(RpcProtocolVersionsUtil.getRpcProtocolVersions())
|
||||
.build());
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ public class AltsTsiHandshakerTest {
|
|||
TEST_SERVER_SERVICE_ACCOUNT,
|
||||
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_RECORD_PROTOCOL, clientContext.getRecordProtocol());
|
||||
assertEquals(TEST_SERVER_SERVICE_ACCOUNT, clientContext.getPeerServiceAccount());
|
||||
|
|
@ -258,7 +258,7 @@ public class AltsTsiHandshakerTest {
|
|||
TEST_CLIENT_SERVICE_ACCOUNT,
|
||||
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_RECORD_PROTOCOL, serverContext.getRecordProtocol());
|
||||
assertEquals(TEST_CLIENT_SERVICE_ACCOUNT, serverContext.getPeerServiceAccount());
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public class FakeTsiHandshaker implements TsiHandshaker {
|
|||
|
||||
@Override
|
||||
public Object extractPeerObject() {
|
||||
return AltsAuthContext.getDefaultInstance();
|
||||
return AltsInternalContext.getDefaultInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue