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
feat: Add roles-separator to split roles from attributes #796
feat: Add roles-separator to split roles from attributes #796
Conversation
…, and a separator is present
f9d8d41
to
c5a549a
Compare
@@ -52,6 +53,10 @@ public DefaultRolesFinder(TokenConfiguration tokenConfiguration) { | |||
List<String> roles = new ArrayList<>(); |
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.
what do you think if we rewrite this method as:
@NonNull
private List<String> rolesAtObject(@Nullable Object rolesObject) {
if (rolesObject == null) {
return Collections.emptyList();
}
if (rolesObject instanceof CharSequence && tokenConfiguration.getRolesSeparator() != null) {
return Arrays.asList(rolesObject.toString().split(tokenConfiguration.getRolesSeparator()));
}
if (rolesObject instanceof Iterable) {
List<String> roles = new ArrayList<>();
for (Object o : ((Iterable<?>) rolesObject)) {
roles.add(o.toString());
}
return roles;
}
return Collections.singletonList(rolesObject.toString());
}
Moreover we have to update the Javadoc to explain the change
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.
This is what I should've done.
I do prefer static imports from Colleactions, as it mostly helps with readability, but I'm not sure if that's allowed by the checkstyle
} | ||
|
||
/** | ||
* Used to change how the roles from the {@link io.micronaut.security.authentication.Authentication} attributes map are converted. Default value {@value io.micronaut.security.token.config.TokenConfiguration#DEFAULT_ROLES_SEPARATOR}. |
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 am not sure about the copy. This shows in our docs. I would like to convey it is used if the roles is a string.
What do you think if we change it to something like the following?
If the entry used for the roles in the {@link io.micronaut.security.authentication.Authentication} attributes map is a String, you can use the separator to split its value into multiple roles. Default value {@value io.micronaut.security.token.config.TokenConfiguration#DEFAULT_ROLES_SEPARATOR}.
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'm with you on that, it conveys the intention better
closes #787