mirror of https://github.com/grpc/grpc-java.git
binder: Let apps call SecurityPolicy.checkAuthorization() by PeerUid (#12257)
This allows a server with access to PeerUid to check additional application-layer security policy *after* the call itself is authorized by the transport layer. Cross cutting application-layer checks could be done from a ServerInterceptor (RPC method level policy, say). Checks based on the substance of a request message could be done by the individual RPC method implementations themselves.
This commit is contained in:
parent
8b46ad58c3
commit
a40c8cf5a4
|
|
@ -67,4 +67,25 @@ public abstract class AsyncSecurityPolicy extends SecurityPolicy {
|
|||
* authorized.
|
||||
*/
|
||||
public abstract ListenableFuture<Status> checkAuthorizationAsync(int uid);
|
||||
|
||||
/**
|
||||
* Decides whether the given Android UID is authorized, without providing its raw integer value.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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<Status> checkAuthorizationAsync(PeerUid uid) {
|
||||
return checkAuthorizationAsync(uid.getUid());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,4 +53,25 @@ public abstract class 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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue