Remove invalid comment and add temp variable

It was not a problem after all to handle multiple scopes. Also added a temp variable to avoid making the same array conversion over and over.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164002903
This commit is contained in:
mountford 2017-08-02 10:31:03 -07:00 committed by Ben McIlwain
parent 5fefa8906d
commit f623d53e73

View file

@ -84,21 +84,20 @@ public class OAuthAuthenticationMechanism implements AuthenticationMechanism {
String rawAccessToken = header.substring(BEARER_PREFIX.length()); String rawAccessToken = header.substring(BEARER_PREFIX.length());
// Get the OAuth information. The various oauthService method calls use a single cached // Get the OAuth information. The various oauthService method calls use a single cached
// authentication result, we can call them one by one. Unfortunately, the calls have a // authentication result, so we can call them one by one.
// single-scope form, and a varargs scope list form, but no way to call them with a collection
// of scopes, so it will not be easy to configure multiple scopes.
User currentUser; User currentUser;
boolean isUserAdmin; boolean isUserAdmin;
String clientId; String clientId;
ImmutableSet<String> authorizedScopes; ImmutableSet<String> authorizedScopes;
try { try {
currentUser = oauthService.getCurrentUser(availableOauthScopes.toArray(new String[0])); String[] availableOauthScopeArray = availableOauthScopes.toArray(new String[0]);
isUserAdmin = oauthService.isUserAdmin(availableOauthScopes.toArray(new String[0])); currentUser = oauthService.getCurrentUser(availableOauthScopeArray);
isUserAdmin = oauthService.isUserAdmin(availableOauthScopeArray);
logger.infofmt("current user: %s (%s)", currentUser, isUserAdmin ? "admin" : "not admin"); logger.infofmt("current user: %s (%s)", currentUser, isUserAdmin ? "admin" : "not admin");
clientId = oauthService.getClientId(availableOauthScopes.toArray(new String[0])); clientId = oauthService.getClientId(availableOauthScopeArray);
logger.infofmt("client ID: %s", clientId); logger.infofmt("client ID: %s", clientId);
authorizedScopes = ImmutableSet authorizedScopes =
.copyOf(oauthService.getAuthorizedScopes(availableOauthScopes.toArray(new String[0]))); ImmutableSet.copyOf(oauthService.getAuthorizedScopes(availableOauthScopeArray));
logger.infofmt("authorized scope(s): %s", authorizedScopes); logger.infofmt("authorized scope(s): %s", authorizedScopes);
} catch (OAuthRequestException | OAuthServiceFailureException e) { } catch (OAuthRequestException | OAuthServiceFailureException e) {
logger.infofmt(e, "unable to get OAuth information"); logger.infofmt(e, "unable to get OAuth information");