-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Refactor Privileges API/Store to use separate class #31191
Refactor Privileges API/Store to use separate class #31191
Conversation
The ApplicationPrivilege class had a dual purpose of defining application privileges as stored in the security index, and also being the means by which those privileges were tested against roles. This made the class difficult to work with - in particular validation was dependent on which purpose it was being used for. This commit splits the index storage part into a new ApplicationPrivilegeDescriptor class
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 like it. I left a few minor comments.
validationException = addValidationError(e.getMessage(), validationException); | ||
} | ||
try { | ||
ApplicationPrivilege.validatePrivilegeName(privilege.getName()); |
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.
hmm I think this should be something else or removed?
@@ -13,6 +13,7 @@ | |||
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; | |||
import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl; | |||
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilege; | |||
import org.elasticsearch.xpack.core.security.authz.privilege.ApplicationPrivilegeDescriptor; |
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.
not needed?
private static final Pattern VALID_NAME = Pattern.compile("^[a-z][a-zA-Z0-9_.-]*$"); | ||
private static final Pattern VALID_NAME_OR_ACTION = Pattern.compile("^\\p{Graph}*$"); |
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.
do you mind adding a comment about this? My regex isn't great so I had to go look up what this was
* @throws IllegalArgumentException if the name is not valid | ||
*/ | ||
public static void validatePrivilegeOrActionName(String name) { | ||
if(VALID_NAME_OR_ACTION.matcher(name).matches() == false) { |
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.
nit: space between if
and (
out.writeCollection(actions, StreamOutput::writeString); | ||
out.writeMap(metadata); | ||
} | ||
|
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.
nit: extra line
assertThat(exception, notNullValue()); | ||
assertThat(exception.validationErrors(), hasItem(containsString(message))); | ||
} | ||
|
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.
nit: extra line
I've addressed all feedback on this PR. |
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.
neat! LGTM Thanks!
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.
LGTM
|
||
/** | ||
* A name or action must be composed of printable, visible ASCII characters. | ||
* That is: letters, numbers & symbols, but no whitespace. |
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 think the &
needs to be &
# Conflicts: # x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ApplicationPrivilege.java # x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/privilege/TransportGetPrivilegesAction.java
The ApplicationPrivilege class had a dual purpose of defining
application privileges as stored in the security index, and also being
the means by which those privileges were tested against roles.
This made the class difficult to work with - in particular validation
was dependent on which purpose it was being used for.
This commit splits the index storage part into a new
ApplicationPrivilegeDescriptor class