Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unnecessary scope check #294

Merged
merged 1 commit into from
Aug 30, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public CSPTokenService(CSPURLConnectionFactory cspUrlConnection) {
this.cspUrlConnectionFactory = cspUrlConnection;
}

public static boolean hasDirectIngestScope(final String scopeList) {
if (!Utils.isNullOrEmpty(scopeList)) {
return CSPTokenService.parseScopes(scopeList).stream()
.anyMatch(s -> s.contains("aoa:directDataIngestion") || s.contains("aoa/*") || s.contains("aoa:*") || s.contains("ALL_PERMISSIONS"));
}

return false;
}

@Override
public synchronized String getToken() {
// First access gets the token and is blocking, which schedules the next token fetch.
Expand Down Expand Up @@ -81,11 +72,6 @@ protected String getCSPToken() {
log.info("A CSP token was received. The token will be refreshed in " + threadDelay.getSeconds() + " seconds.");
executor.schedule(this, threadDelay.getSeconds(), TimeUnit.SECONDS);

if (!hasDirectIngestScope(parsedResponse.scope)) {
log.warning("The CSP response does not contain a required scope to send data to Wavefront. " +
"Must be one of 'aoa:directDataIngestion', 'aoa:*', 'aoa/*', or 'ALL_PERMISSIONS'. Received: '" + parsedResponse.scope + "'.");
}

return parsedResponse.accessToken;
} catch (JsonProcessingException e) {
log.severe("The request to CSP returned invalid json. Please restart your app.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ void teardown() {
assertTrue(allUnmatchedRequests.isEmpty());
}

@Test
public void testHasDirectIngestScope() {
final String scopeString = "external/<uuid>/*/aoa:directDataIngestion external/<uuid>/aoa:directDataIngestion csp:org_member";

assertTrue(CSPTokenService.hasDirectIngestScope(scopeString));
assertFalse(CSPTokenService.hasDirectIngestScope("no direct data ingestion scope"));
assertFalse(CSPTokenService.hasDirectIngestScope(""));
assertFalse(CSPTokenService.hasDirectIngestScope(null));
assertTrue(CSPTokenService.hasDirectIngestScope("aoa/*"));
assertTrue(CSPTokenService.hasDirectIngestScope("some aoa/*"));
assertTrue(CSPTokenService.hasDirectIngestScope("aoa:*"));
assertTrue(CSPTokenService.hasDirectIngestScope("some aoa:*"));
assertTrue(CSPTokenService.hasDirectIngestScope("ALL_PERMISSIONS"));
assertTrue(CSPTokenService.hasDirectIngestScope("aoa:metric ALL_PERMISSIONS aoa:log"));
assertFalse(CSPTokenService.hasDirectIngestScope("NO_PERMISSIONS"));
}

@Test
void testCSPServerTokenReturnsAccessToken() {
Expand Down
Loading