Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions alts/src/main/java/io/grpc/alts/AuthorizationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ private AuthorizationUtil() {}

/**
* Given a server call, performs client authorization check, i.e., checks if the client service
* account matches one of the expected service accounts. It returns OK if client is authorized and
* an error otherwise.
* account matches one of the expected service accounts, ignoring case. It returns OK if client
* is authorized and an error otherwise.
*/
public static Status clientAuthorizationCheck(
ServerCall<?, ?> call, Collection<String> expectedServiceAccounts) {
Expand All @@ -39,10 +39,13 @@ public static Status clientAuthorizationCheck(
if (altsContext == null) {
return Status.PERMISSION_DENIED.withDescription("Peer ALTS AuthContext not found");
}
if (expectedServiceAccounts.contains(altsContext.getPeerServiceAccount())) {
return Status.OK;
String peerServiceAccount = altsContext.getPeerServiceAccount();
for (String serviceAccount : expectedServiceAccounts) {
if (peerServiceAccount.equalsIgnoreCase(serviceAccount)) {
return Status.OK;
}
}
return Status.PERMISSION_DENIED.withDescription(
"Client " + altsContext.getPeerServiceAccount() + " is not authorized");
"Client " + peerServiceAccount + " is not authorized");
}
}
8 changes: 8 additions & 0 deletions alts/src/test/java/io/grpc/alts/AuthorizationUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public void altsAuthorizationCheck() throws Exception {
assertThat(status.getDescription()).endsWith("not authorized");
}

@Test
public void altsAuthorizationCheck_ignoresCase() throws Exception {
Status status =
AuthorizationUtil.clientAuthorizationCheck(
new FakeServerCall("alice"), Lists.newArrayList("ALICE", "Bob"));
assertThat(status.getCode()).isEqualTo(Status.Code.OK);
}

private static class FakeServerCall extends ServerCall<String, String> {
final Attributes attrs;

Expand Down
Loading