Skip to content

Commit 90dbaf6

Browse files
Sheikah45Brutus5000
authored andcommitted
Simplify scope check logic
1 parent e95613e commit 90dbaf6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/com/faforever/api/security/elide/permission/FafUserCheck.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ protected boolean checkOAuthScopes(OAuthScope... scope) {
2626

2727
private boolean checkOAuthScopes(String... scope) {
2828
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
29-
if (!(authentication instanceof OAuth2Authentication)) {
29+
if (!(authentication instanceof OAuth2Authentication oAuth2Authentication)) {
3030
log.trace("Authentication is no OAuth2Authentication: {}", authentication);
3131
return false;
3232
}
3333

34-
OAuth2Authentication oAuth2Authentication = ((OAuth2Authentication) authentication);
3534
OAuth2Request oAuth2Request = oAuth2Authentication.getOAuth2Request();
3635

3736
List<String> missedScopes = new ArrayList<>();
3837

38+
Set<String> scopes = oAuth2Request.getScope();
39+
3940
for (String currentScope : scope) {
40-
if (!oAuth2Request.getScope().contains(currentScope)) {
41+
if (!scopes.contains(currentScope)) {
4142
missedScopes.add(currentScope);
4243
}
4344
}
@@ -46,7 +47,7 @@ private boolean checkOAuthScopes(String... scope) {
4647
if (missedScopes.isEmpty()) {
4748
log.trace("All requested scopes are granted: {}", String.join(", ", scope));
4849
} else {
49-
log.trace("Scopes '{}' are not granted in requested scopes: {} for client with id {}", String.join(", ", missedScopes), String.join(", ", oAuth2Request.getScope()), oAuth2Request.getResourceIds());
50+
log.trace("Scopes '{}' are not granted in requested scopes: {} for client with id {}", String.join(", ", missedScopes), String.join(", ", scopes), oAuth2Request.getResourceIds());
5051
}
5152
}
5253

0 commit comments

Comments
 (0)