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

Erronious user in spicedb #5371

Merged
merged 3 commits into from
Nov 4, 2024
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 @@ -51,6 +51,7 @@
import software.uncharted.terarium.hmiserver.models.dataservice.project.ProjectAsset;
import software.uncharted.terarium.hmiserver.models.dataservice.project.ProjectExport;
import software.uncharted.terarium.hmiserver.models.permissions.PermissionRelationships;
import software.uncharted.terarium.hmiserver.models.permissions.PermissionUser;
import software.uncharted.terarium.hmiserver.security.Roles;
import software.uncharted.terarium.hmiserver.service.ClientEventService;
import software.uncharted.terarium.hmiserver.service.CurrentUserService;
Expand Down Expand Up @@ -928,10 +929,10 @@ public ResponseEntity<PermissionRelationships> getProjectPermissions(@PathVariab
try {
for (final RebacPermissionRelationship permissionRelationship : rebacProject.getPermissionRelationships()) {
if (permissionRelationship.getSubjectType().equals(Schema.Type.USER)) {
permissions.addUser(
reBACService.getUser(permissionRelationship.getSubjectId()),
permissionRelationship.getRelationship()
);
PermissionUser user = reBACService.getUser(permissionRelationship.getSubjectId());
if (user != null) {
permissions.addUser(user, permissionRelationship.getRelationship());
}
} else if (permissionRelationship.getSubjectType().equals(Schema.Type.GROUP)) {
permissions.addGroup(
reBACService.getGroup(permissionRelationship.getSubjectId()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public ResponseEntity<PermissionGroup> getGroup(@PathVariable("groupId") final S
for (final RebacPermissionRelationship permissionRelationship : relationships) {
if (permissionRelationship.getSubjectType().equals(Schema.Type.USER)) {
final PermissionUser user = reBACService.getUser(permissionRelationship.getSubjectId());
permissions.addUser(user, permissionRelationship.getRelationship());
if (user != null) {
permissions.addUser(user, permissionRelationship.getRelationship());
}
} else if (permissionRelationship.getSubjectType().equals(Schema.Type.GROUP)) {
final PermissionGroup group = reBACService.getGroup(permissionRelationship.getSubjectId());
permissions.addGroup(group, permissionRelationship.getRelationship());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ private List<Contributor> getContributorsByRelationships(
if (relationships.length == 0 || List.of(relationships).contains(relationship)) {
if (permissionRelationship.getSubjectType().equals(Schema.Type.USER)) {
final PermissionUser user = reBACService.getUser(permissionRelationship.getSubjectId());
final String name = user.getFirstName() + " " + user.getLastName();
if (!contributorMap.containsKey(name)) {
contributorMap.put(name, new Contributor(name, user.getId(), relationship));
if (user != null) {
final String name = user.getFirstName() + " " + user.getLastName();
if (!contributorMap.containsKey(name)) {
contributorMap.put(name, new Contributor(name, user.getId(), relationship));
}
}
} else if (permissionRelationship.getSubjectType().equals(Schema.Type.GROUP)) {
final PermissionGroup group = reBACService.getGroup(permissionRelationship.getSubjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,32 @@ public PermissionUser getUser(final String id) {
final PermissionUser result = userCache.get(id, key_id -> {
final UsersResource usersResource = keycloak.realm(REALM_NAME).users();
final UserResource userResource = usersResource.get(key_id);
final UserRepresentation userRepresentation = userResource.toRepresentation();

final List<PermissionRole> roles = new ArrayList<>();
for (final RoleRepresentation roleRepresentation : userResource.roles().getAll().getRealmMappings()) {
if (roleRepresentation.getDescription().isBlank()) {
final PermissionRole role = new PermissionRole(
roleRepresentation.getId(),
roleRepresentation.getName()
// no users are acquired (to avoid circular references etc)
);
roles.add(role);
try {
final UserRepresentation userRepresentation = userResource.toRepresentation();

final List<PermissionRole> roles = new ArrayList<>();
for (final RoleRepresentation roleRepresentation : userResource.roles().getAll().getRealmMappings()) {
if (roleRepresentation.getDescription().isBlank()) {
final PermissionRole role = new PermissionRole(
roleRepresentation.getId(),
roleRepresentation.getName()
// no users are acquired (to avoid circular references etc)
);
roles.add(role);
}
}
}

return new PermissionUser(
userRepresentation.getId(),
userRepresentation.getFirstName(),
userRepresentation.getLastName(),
userRepresentation.getEmail(),
roles
);
return new PermissionUser(
userRepresentation.getId(),
userRepresentation.getFirstName(),
userRepresentation.getLastName(),
userRepresentation.getEmail(),
roles
);
} catch (Exception e) {
log.error("User identified by SpiceDB with id \"{}\" is not found in Keycloak.", id);
return null;
}
});
log.trace("User Cache hit: {}, miss: {}", userCache.stats().hitCount(), userCache.stats().missCount());
return result;
Expand Down
Loading