OAK-11640 : removed usage of ImmutableSet.builder#2212
Conversation
Commit-Check ✔️ |
thomasmueller
left a comment
There was a problem hiding this comment.
It looks OK as far as I see, but I'm not sure about the security part.
Possibly memory usage could be much higher than with the current ImmutableSet.
| Set<Object> creds = ImmutableSet.builder() | ||
| .addAll(subject.getPublicCredentials(Credentials.class)) | ||
| .addAll(subject.getPublicCredentials(AuthInfo.class)).build(); | ||
| Set<Object> creds = Stream.concat(subject.getPublicCredentials(Credentials.class).stream(), subject.getPublicCredentials(AuthInfo.class).stream()) |
There was a problem hiding this comment.
Did you check that it's ok not to make this immutable?
There was a problem hiding this comment.
Yes, it is only iterated in the same class to destroy these credentials, but I would say that we should play safe here as well. let me update the ticket to use Collections.unmodifiableSet
...because? |
We have already done the micro benchmarks for it seems that using Java's |
...-azure/src/test/java/org/apache/jackrabbit/oak/segment/azure/v8/AzureSegmentStoreV8Test.java
Outdated
Show resolved
Hide resolved
AFAICT all the sets in question are pretty small (also I don't quite understand how the memory usage would increase). Could you elaborate on your security concerns? |
Because the hash table implementation is very different. Guava seems to use an open-addressing hash table (power of 2 sized) with linear probing, where entries are very small. Java internally (inside of LinkedHashSet) uses a HashMap that uses separate chaining.... Did someone test memory usage? |
thomasmueller
left a comment
There was a problem hiding this comment.
More investigation is needed:
- Verify memory usage
- Verify behavior of null entries
- Verify with someone that knows the security part
|
| addAll(getAutoMembership()).build(); | ||
| return Collections.unmodifiableSet((Set<String>) | ||
| Stream.concat(autoMembershipConfig.getAutoMembership(authorizable).stream(), getAutoMembership().stream()) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new))); |
There was a problem hiding this comment.
getAutoMembership has been annotated with @NotNull
| Set<Privilege> privs = new LinkedHashSet<>(); | ||
| for (AccessControlManager acMgr : acMgrs) { | ||
| privs.add(acMgr.getSupportedPrivileges(absPath)); | ||
| privs.addAll(Arrays.asList(acMgr.getSupportedPrivileges(absPath))); |
There was a problem hiding this comment.
Null not possible here as well since getSupportedPrivileges has been annotated as @NotNull
| private Role(@NotNull Role base, long permissions, String... privilegeNames) { | ||
| this.permissions = base.permissions|permissions; | ||
| this.privilegeNames = ImmutableSet.<String>builder().addAll(base.privilegeNames).add(privilegeNames).build(); | ||
| this.privilegeNames = Collections.unmodifiableSet( |
There was a problem hiding this comment.
private constructor called from within the class, privilegeNames can't be null here.
| Set<Object> creds = ImmutableSet.builder() | ||
| .addAll(subject.getPublicCredentials(Credentials.class)) | ||
| .addAll(subject.getPublicCredentials(AuthInfo.class)).build(); | ||
| Set<Object> builder = new LinkedHashSet<>(subject.getPublicCredentials(Credentials.class)); |
There was a problem hiding this comment.
same case as above, getPublicCredentials can't return null.
| builder.addAll(declaredAggregateNames); | ||
| } | ||
| this.declaredAggregateNames = builder.build(); | ||
| this.declaredAggregateNames = declaredAggregateNames != null ? Collections.unmodifiableSet(SetUtils.toLinkedSet(declaredAggregateNames)) : Set.of(); |
There was a problem hiding this comment.
Null case already handled.
| @NotNull | ||
| private Set<String> resolveBuiltInAggregation(@NotNull String privilegeName) { | ||
| ImmutableSet.Builder<String> builder = ImmutableSet.builder(); | ||
| Set<String> builder = new LinkedHashSet<>(); |
There was a problem hiding this comment.
Only called when AGGREGATE_PRIVILEGES already has privilegeName, so null value not possible here as well.
| ImmutableSet.Builder<MountedNodeStore> b = ImmutableSet.builder(); | ||
| Set<MountedNodeStore> b = new LinkedHashSet<>(); | ||
| b.add(this.globalStore); | ||
| b.addAll(this.nonDefaultStores); |
There was a problem hiding this comment.
Both values globalStore & nonDefaultStores can't be null else the code would have already failed in the higher tier.
| NodeStateCopier.builder() | ||
| .include(includes) | ||
| .exclude(excludes.build()) | ||
| .exclude(Collections.unmodifiableSet(excludes)) |
There was a problem hiding this comment.
excludes can't be null.
@thomasmueller please find reply as below:
|
Amoratinos
left a comment
There was a problem hiding this comment.
to me looks good, there are a couple of trivial things like removing imports but nothing blocker
.../org/apache/jackrabbit/oak/spi/security/authentication/external/basic/DefaultSyncConfig.java
Show resolved
Hide resolved
...rg/apache/jackrabbit/oak/security/authorization/composite/CompositeAccessControlManager.java
Show resolved
Hide resolved
...a/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java
Show resolved
Hide resolved
...src/main/java/org/apache/jackrabbit/oak/spi/security/authentication/AbstractLoginModule.java
Show resolved
Hide resolved
...a/org/apache/jackrabbit/oak/exercise/security/authorization/models/simplifiedroles/Role.java
Show resolved
Hide resolved
thomasmueller
left a comment
There was a problem hiding this comment.
It seems my concerns are addressed then! Thanks a lot!



No description provided.