Skip to content

Commit 26d4899

Browse files
committed
fix(ResourcePermissionSetter): validate incoming scopes against known resource scopes
1 parent 97d6241 commit 26d4899

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/com/hawk/keycloak/resources/service/ResourcePermissionSetter.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.keycloak.authorization.store.PermissionTicketStore;
1010
import org.keycloak.authorization.store.ScopeStore;
1111
import org.keycloak.events.admin.OperationType;
12-
import org.keycloak.models.KeycloakSession;
1312
import org.keycloak.models.KeycloakUriInfo;
1413
import org.keycloak.models.UserModel;
1514
import org.keycloak.services.resources.admin.AdminEventBuilder;
@@ -38,6 +37,13 @@ public void setPermissions(
3837
}
3938

4039
List<String> knownScopesOfResource = resource.getScopes().stream().map(Scope::getName).toList();
40+
41+
for (String scope : scopes) {
42+
if(!knownScopesOfResource.contains(scope)){
43+
throw new BadRequestException("The scope \"" + scope + "\" is not allowed for the resource");
44+
}
45+
}
46+
4147
List<PermissionTicket> tickets = findTickets(resource, user);
4248

4349
boolean triggerEvent = false;
@@ -58,9 +64,6 @@ public void setPermissions(
5864
if(scope == null){
5965
throw new BadRequestException("The scope \"" + scopeName + "\" does not exist");
6066
}
61-
if(!knownScopesOfResource.contains(scope.getName())){
62-
throw new BadRequestException("The scope \"" + scopeName + "\" is not allowed for the resource");
63-
}
6467

6568
Iterator<PermissionTicket> ticketIterator = tickets.iterator();
6669

0 commit comments

Comments
 (0)