forked from grpc/grpc-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow async/slow implementations of authorization checks for Binder g…
…RPCs. Introduce `AsyncSecurityPolicy`, exposing a method returns a `ListenableFuture<Status>` that callers can implement to perform slower auth checks (like network calls, disk I/O etc.) without necessarily blocking the gRPC calling thread. Partially addresses: grpc#10566
- Loading branch information
1 parent
bf9ccc6
commit 04d0085
Showing
10 changed files
with
251 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2023 The gRPC Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.grpc.binder; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.grpc.ExperimentalApi; | ||
import io.grpc.Status; | ||
import java.util.concurrent.ExecutionException; | ||
import javax.annotation.CheckReturnValue; | ||
|
||
/** | ||
* Decides whether a given Android UID is authorized to access some resource. | ||
* | ||
* <p>This class provides the asynchronous version of {@link SecurityPolicy}, allowing | ||
* implementations of authorization logic that involves slow or asynchronous calls without | ||
* necessarily blocking the calling thread. | ||
* | ||
* @see SecurityPolicy | ||
*/ | ||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10566") | ||
@CheckReturnValue | ||
public abstract class AsyncSecurityPolicy extends SecurityPolicy { | ||
|
||
/** | ||
* @deprecated Prefer {@link #checkAuthorizationAsync(int)} for async or slow calls or subclass | ||
* {@link SecurityPolicy} directly for quick, synchronous implementations. | ||
*/ | ||
@Override | ||
@Deprecated | ||
public final Status checkAuthorization(int uid) { | ||
try { | ||
return checkAuthorizationAsync(uid).get(); | ||
} catch (ExecutionException e) { | ||
return Status.fromThrowable(e); | ||
} catch (InterruptedException e) { | ||
return Status.CANCELLED.withCause(e); | ||
} | ||
} | ||
|
||
/** | ||
* Decides whether the given Android UID is authorized. (Validity is implementation dependent). | ||
* | ||
* <p>As long as any given UID has active processes, this method should return the same value for | ||
* that UID. In order words, policy changes which occur while a transport instance is active, will | ||
* have no effect on that transport instance. | ||
* | ||
* @param uid The Android UID to authenticate. | ||
* @return A {@link ListenableFuture} for a gRPC {@link Status} object, with OK indicating | ||
* authorized. | ||
*/ | ||
abstract ListenableFuture<Status> checkAuthorizationAsync(int uid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.