-
Notifications
You must be signed in to change notification settings - Fork 279
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
[ELY-2413] Re-authentication after reboot, even though HttpSession are persisted #1747
Conversation
0740042
to
e0ca0f5
Compare
private Set<String> rolesToSet(Roles roles) { | ||
Iterator<String> iterator = roles.iterator(); | ||
Set<String> resultSet = new HashSet<>(); | ||
while (iterator.hasNext()) { | ||
resultSet.add(iterator.next()); | ||
} | ||
return resultSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this set will be generated per user and will typically be small in size, I might suggest using a more lightweight data structure (e.g. TreeSet) and leverage empty and singleton implementations if possible.
e.g.
private Set<String> rolesToSet(Roles roles) {
Iterator<String> iterator = roles.iterator();
if (!iterator.hasNext()) return Set.of();
String role = iterator.next();
if (!iterator.hasNext()) return Set.of(role);
Set<String> result = new TreeSet<>();
result.add(role);
while (iterator.hasNext()) {
result.add(iterator.next());
}
return result;
}
Perhaps this logic could reside within a Roles.toSet() method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pferraro Good points! I have moved the method to the Roles class and I have used your TreeSet
approach. I just modified it slightly to not use Set.of
because we have to use Java 8 APIs. Thank you!
e0ca0f5
to
844df4b
Compare
static Set<String> rolesToSet(Roles roles) { | ||
Assert.checkNotNullParam("roles", roles); | ||
if (roles.isEmpty()) { | ||
return new TreeSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Collections.emptySet();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Iterator<String> iterator = roles.iterator(); | ||
String role = iterator.next(); | ||
if (!iterator.hasNext()) { | ||
return new TreeSet<>(Collections.singleton(role)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Collections.singleton(role);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
*/ | ||
static Set<String> rolesToSet(Roles roles) { | ||
Assert.checkNotNullParam("roles", roles); | ||
if (roles.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roles.isEmpty() internally creates an Iterator, so you can avoid creating the iterator twice by testing for empty via the Iterator (created in line 146).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pferraro thanks, updated
* @param roles collection (not {@code null}) | ||
* @return the set of role names (must not be {@code null}) | ||
*/ | ||
static Set<String> rolesToSet(Roles roles) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a normal public method instead of a static method?
e.g.
Set<String> toSet();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pferraro this is an interface. Also the above static Roles fromSet(Set<String> set)
method is static so it is congruent now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interfaces can contain default method implementations.
e.g.
default Set<String> toSet() {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway - this is just (my) stylistic preference, and does not need to block approval.
@@ -130,6 +132,30 @@ public boolean isEmpty() { | |||
}; | |||
} | |||
|
|||
/** | |||
* Construct a new roles collection from a set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest that this method return an immutable view of the roles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pferraro Thank you, fixed
while (iterator.hasNext()) { | ||
result.add(iterator.next()); | ||
} | ||
return result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Collections.unmodifiableSet(result);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
844df4b
to
512a1e8
Compare
https://issues.redhat.com/browse/ELY-2413