private boolean grantScopeMatchesRequest( TokenGrantInfo tokenGrantInfo, OAuth2RSEndpoint requestEndpoint) throws OAuthProblemException { Set<String> grantScopes = tokenGrantInfo.getGrantScopeNames(); if (grantScopes.isEmpty()) { log.severe("No scopes associated with token grant"); throw OAuthProblemException.error(SERVER_ERROR); } for (String scopeName : grantScopes) { Set<OAuth2RSEndpoint> scopeEndpoints = authService.getEndpointsForScopeName(scopeName); if (scopeEndpoints == null) { log.severe("No endpoints associated with scope"); throw OAuthProblemException.error(SERVER_ERROR); } for (OAuth2RSEndpoint scopeEndpoint : scopeEndpoints) { if (requestEndpoint.equals(scopeEndpoint)) { log.info( "Endpoint " + requestEndpoint.getEndpointUrl() + " matches grant scope " + scopeName); return true; } } } return false; }