diff --git a/binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java b/binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java index 5b17ad35977..9594c644e0c 100644 --- a/binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java +++ b/binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java @@ -67,4 +67,25 @@ public final Status checkAuthorization(int uid) { * authorized. */ public abstract ListenableFuture checkAuthorizationAsync(int uid); + + /** + * Decides whether the given Android UID is authorized, without providing its raw integer value. + * + *

Calling this is equivalent to calling {@link SecurityPolicy#checkAuthorization(int)}, except + * the caller provides a {@link PeerUid} wrapper instead of the raw integer uid (known only to the + * transport). This allows a server to check additional application-layer security policy for + * itself *after* the call itself is authorized by the transport layer. Cross cutting application- + * layer checks could be done from a {@link io.grpc.ServerInterceptor}. Checks based on the + * substance of a request message could be done by the individual RPC method implementations + * themselves. + * + *

See #checkAuthorizationAsync(int) for details on the semantics. See {@link + * PeerUids#newPeerIdentifyingServerInterceptor()} for how to get a {@link PeerUid}. + * + * @param uid The Android UID to authenticate. + * @return A gRPC {@link Status} object, with OK indicating authorized. + */ + public final ListenableFuture checkAuthorizationAsync(PeerUid uid) { + return checkAuthorizationAsync(uid.getUid()); + } } diff --git a/binder/src/main/java/io/grpc/binder/SecurityPolicy.java b/binder/src/main/java/io/grpc/binder/SecurityPolicy.java index 261e5223a0f..3ad8903407f 100644 --- a/binder/src/main/java/io/grpc/binder/SecurityPolicy.java +++ b/binder/src/main/java/io/grpc/binder/SecurityPolicy.java @@ -53,4 +53,25 @@ protected SecurityPolicy() {} * @return A gRPC {@link Status} object, with OK indicating authorized. */ public abstract Status checkAuthorization(int uid); + + /** + * Decides whether the given Android UID is authorized, without providing its raw integer value. + * + *

Calling this is equivalent to calling {@link SecurityPolicy#checkAuthorization(int)}, except + * the caller provides a {@link PeerUid} wrapper instead of the raw integer uid (known only to the + * transport). This allows a server to check additional application-layer security policy for + * itself *after* the call itself is authorized by the transport layer. Cross cutting application- + * layer checks could be done from a {@link io.grpc.ServerInterceptor}. Checks based on the + * substance of a request message could be done by the individual RPC method implementations + * themselves. + * + *

See #checkAuthorizationAsync(int) for details on the semantics. See {@link + * PeerUids#newPeerIdentifyingServerInterceptor()} for how to get a {@link PeerUid}. + * + * @param uid The Android UID to authenticate. + * @return A gRPC {@link Status} object, with OK indicating authorized. + */ + public final Status checkAuthorization(PeerUid uid) { + return checkAuthorization(uid.getUid()); + } }